Here is the complete flow of problem
1) Azure Build pipeline creates an artefact (docker image) using following DockerFile
FROM hub.docker.prod.private.com/library/node:10.16-alpine as buildImage
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ENV PATH /app/node_modules/.bin:$PATH
ENV REACT_APP_SERVER_URL=${REACT_APP_SERVER_URL}
ENV REACT_APP_AD_APP_ID=${REACT_APP_AD_APP_ID}
ENV REACT_APP_REDIRECT_URL=${REACT_APP_REDIRECT_URL}
ENV REACT_APP_AUTHORITY=${REACT_APP_AUTHORITY}
COPY package.json /usr/src/app/
RUN npm install
RUN npm install react-scripts@3.0.1 -g
COPY . /usr/src/app
RUN npm run build
FROM hub.docker.prod.private.com/library/nginx:1.15.12-alpine
COPY --from=buildImage /usr/src/app/build /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/nginx.conf /etc/nginx/conf.d
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
2) And pushes docker image into Azure container registry ( ACR
).
3) Multistage Release pipeline pulls image from ACR
and deploy on azure app service(s) ( QA -> Stage -> Prod
).
4) Release pipeline is using variable values from variable group defined in release pipeline and I am expecting these variable should available in docker environment so that it replaces ENV
variable placeholders in DockerFile
.
But after deployment all environment variables that being used inside application remains undefined, can you please correct me if it is possible to use docker environment the way I mentioned above.
But after deployment all environment variables that being used inside application remains undefined, can you please correct me if it is possible to use docker environment the way I mentioned above.
The way mentioned above wasn't possible to work. During the deployment process, Release Variables won't automatically replace the original values with stage-scope
release variables in DockerFile.
As a workaround, you can try Replace Tokens task
from Replace Tokens , add this task in your three stages before deploy task. So the task order in your three stages should be similar to: Replace Tokens task
to set release variables in DockerFile=>docker build and push=>deploy task.
To use this task, your Dockerfile should be:
ENV REACT_APP_SERVER_URL=#{REACT_APP_SERVER_URL}#
ENV REACT_APP_AD_APP_ID=#{REACT_APP_AD_APP_ID}#
ENV REACT_APP_REDIRECT_URL=#{REACT_APP_REDIRECT_URL}#
ENV REACT_APP_AUTHORITY=#{REACT_APP_AUTHORITY}#
Details about how this task works check my another issue .
If you don't want to make any change to the Dockerfile itself, another way is to pass the value in command-line arguments. You can check this similar post for more details.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.