简体   繁体   English

dockerize create-react-app如何在docker环境下访问azure发布管道变量

[英]How dockerize create-react-app can access to azure release pipeline variables in docker environment

Here is the complete flow of problem这是问题的完整流程

1) Azure Build pipeline creates an artefact (docker image) using following DockerFile 1) Azure 构建管道使用以下DockerFile创建一个工件(docker 镜像)

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 ). 2) 并将 docker 镜像推送到 Azure 容器注册表 ( ACR )。

3) Multistage Release pipeline pulls image from ACR and deploy on azure app service(s) ( QA -> Stage -> Prod ). 3) 多阶段发布管道从ACR中提取图像并部署在 azure 应用服务上( 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 . 4) 发布管道正在使用发布管道中定义的变量组中的变量值,我期望这些变量应该在 docker 环境中可用,以便它替换DockerFile中的ENV变量占位符。

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.但是在部署之后,应用程序内部使用的所有环境变量仍然未定义,如果可以按照我上面提到的方式使用 docker 环境,请您纠正我。

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.但是在部署之后,应用程序内部使用的所有环境变量仍然未定义,如果可以按照我上面提到的方式使用 docker 环境,请您纠正我。

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.在部署过程中,Release Variables不会自动将原始值替换为 DockerFile 中的stage-scope发布变量。

As a workaround, you can try Replace Tokens task from Replace Tokens , add this task in your three stages before deploy task.作为解决方法,您可以尝试从Replace Tokens 中Replace Tokens task Replace Tokens 任务,在部署任务之前的三个阶段中添加此任务。 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.所以你的三个阶段的任务顺序应该类似于: Replace Tokens task以在 DockerFile 中设置发布变量=>docker build and push=>deploy 任务。

To use this task, your Dockerfile should be:要使用此任务,您的 Dockerfile 应该是:

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.如果您不想对 Dockerfile 本身进行任何更改,另一种方法是在命令行 arguments 中传递该值。您可以查看此类似帖子以获取更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在运行管道时将 create-react-app 发布到 Azure 得到 git 结帐错误我该如何解决这个问题? - Publishing create-react-app to Azure getting git checkout error when running pipeline how can I fix this? 如何访问 Azure 管道中的环境变量? - How to access environment variables in Azure pipeline? 如何从 azure 发布管道查询当前部署到应用程序服务的 docker 图像? - How can I query which docker image is currently deployed to an app service from an azure release pipeline? 如何使用 Azure DevOps 部署 create-react-app? - How to deploy a create-react-app using Azure DevOps? 使用 azure 管道部署 create-react-app - Deploy create-react-app with azure pipelines 使用create-react-app在azure上进行部署 - Deploying on azure with create-react-app Azure DevOps 发布管道 - 将环境变量传递给 docker 容器 - Azure DevOps Release Pipeline - Pass environment variable to docker container 如何在 azure 发布管道上创建自定义参数 - how to create custom parameters on azure release pipeline 如何在 Azure 上为 Angular 项目创建发布管道 - How to create a release pipeline on Azure for an Angular project 如何在 Azure 托管的 React 应用程序中使用环境变量 - How to use environment variables in React app hosted in Azure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM