reactjs - Azure DevOps docker build 与本地构建产生不同的结果
问题描述
我有一个使用 create-react-app 启动器构建的 React 应用程序。我正在尝试将此应用程序部署到 Azure App 服务。在本地测试时,一切都按预期工作。当我使用通过管道推送到 ACR 的图像来部署它时,应用程序的行为有所不同,并且出现了本地未见的错误。当我在本地构建映像并将其推送到 ACR 存储库时,问题就消失了。因此,构建管道会导致不同的行为。任何想法如何解决这样的问题?
这是我正在使用的 Dockerfile:
# build environment
FROM node:13.12.0-alpine as build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json ./
COPY package-lock.json ./
RUN npm ci --silent
RUN npm install react-scripts@3.4.1 -g --silent
COPY . ./
RUN npm run build
# production environment
FROM nginx:stable-alpine
COPY --from=build /app/build /usr/share/nginx/html
# new
COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
这是 ADO 中的构建定义:
# Docker
# Build and push an image to Azure Container Registry
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- master
resources:
- repo: self
variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: '3919c5b1-8ce6-4f6c-aa87-73632208d6a2'
imageRepository: 'videoeffectsreact'
containerRegistry: 'videoeffects.azurecr.io'
dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
tag: '$(Build.BuildId)'
# Agent VM image name
vmImageName: 'ubuntu-18.04'
stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
latest
解决方案
推荐阅读
- itext - 块和颜色类需要哪个包
- javascript - Angular 6:setTimeout 函数在我的自定义验证器中不起作用
- java - Spring ResponseErrorHandler 不解析对象
- android - MyApps 崩溃但找不到解决方案,
- java - Android Studio 构建 NDK {NDK_PROJECT_PATH=null} 错误 87 => 错误 1
- microsoft-graph-api - 托管设备 - 操作系统制造商
- automation - 安装茉莉花时收到以下错误
- java - 只获取协议缓冲区中的一个字段而不反序列化java中的整个对象
- javascript - 设置正确的自动填充用户名和密码
- r - 打破 R 文档中的长方程