I have a Dockerfile
that looks something like the following:
# 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:
In my Azure DevOps CI pipeline I'd like to "cache" the development
stage by sending it to my Azure Container Registry (ACR). That way when I run unit-tests
and integration-tests
stages, I can just pull from ACR and hopefully save some time by not building development
twice.
I can modify my Dockerfile
to pull from ACR which would work for CI, but I'm pretty sure this would screw up running those stages locally. Locally, I wouldn't want to pull from ACR, and for it to be built locally since that has the most recent code the developer is working on.
Is there a way to do this with devspace
without having multiple Dockerfile
, modifying them, etc?
EDIT:
Actually, I might be able to accomplish what I'm after on the Azure DevOps side with --cache-from
in the build
command, and not have to modify the Dockerfile
or DevSpace.yaml
locally.
Idea came from here: How to Enable Docker layer caching in Azure DevOps
Have to test it out yet.
You could use the appendDockerfileInstructions
option in combination with multi-stage builds (i.e. multiple FROM
statements in the Dockerfile added in-memory via devspace): https://devspace.sh/cli/docs/configuration/images/append-dockerfile-instructions