我有一个Dockerfile
看起来像这样:
# creating a node base
FROM node:16-slim as node-base
ENV CI=true
# builder-base is used to build dependencies
FROM node-base as builder-base
COPY ./package-lock.json ./package.json ./
RUN npm ci --production
# 'development' stage installs all dev deps and can be used to develop code.
FROM builder-base as development
WORKDIR /app
COPY . .
RUN npm ci
EXPOSE 4001
CMD ["npm", "start"]
# 'unit-tests' stage
FROM development AS unit-tests
RUN npm test -- --coverage --testNamePattern=UT:
# 'integration-tests' stage
FROM development AS integration-tests
RUN npm test -- --coverage --testNamePattern=IT:
在我的Azure DevOps CI管道中,我想"缓存";将development
阶段发送到我的Azure容器注册表(ACR)。这样,当我运行unit-tests
和integration-tests
阶段时,我可以从ACR中拉出,并希望通过不构建development
两次来节省一些时间。
我可以修改我的Dockerfile
从ACR,这将为CI工作,但我很确定这将搞砸本地运行这些阶段。在本地,我不想从ACR中拉出来,因为它是在本地构建的,因为它有开发人员正在处理的最新代码。
有没有办法做到这一点与devspace
没有多个Dockerfile
,修改它们,等?
编辑:实际上,我可能能够在build
命令中使用--cache-from
完成我在Azure DevOps方面所追求的目标,而不必在本地修改Dockerfile
或DevSpace.yaml
。
灵感来自这里:如何在Azure DevOps中启用Docker层缓存
还得测试一下。
您可以将appendDockerfileInstructions
选项与多阶段构建结合使用(即通过devspace在Dockerfile中添加多个FROM
语句):https://devspace.sh/cli/docs/configuration/images/append-dockerfile-instructions