uber-archive / makisu

Fast and flexible Docker image building tool, works in unprivileged containerized environments like Mesos and Kubernetes.
Apache License 2.0
2.41k stars 154 forks source link

Caching for multi-stage builds #234

Open fkorotkov opened 5 years ago

fkorotkov commented 5 years ago

I'm trying to configure a build for NodeJS application using Makisu and HTTP cache. Here is my Dockerfile:

FROM node:12 as builder

WORKDIR /tmp/cirrus-ci-web
ADD package.json package-lock.json /tmp/cirrus-ci-web/

RUN npm ci #!COMMIT

ENV GENERATE_SOURCEMAP true
ENV NODE_ENV production

RUN pwd && ls # for debugging caching
ADD . /tmp/cirrus-ci-web/
RUN pwd && ls && npm run relay && npm run build

FROM node:12-alpine

WORKDIR /svc/cirrus-ci-web
EXPOSE 8080

RUN npm install -g serve@11.0.1 #!COMMIT

COPY --from=builder /tmp/cirrus-ci-web/serve.json /svc/cirrus-ci-web/serve.json
COPY --from=builder /tmp/cirrus-ci-web/build/ /svc/cirrus-ci-web/

CMD serve --single \
          --listen 8080 \
          --config serve.json

When it build the first time everything succeeds and cache gets populated(here is a link to the this CI task).

When I re-run the task to check if caching is working I can see that a layer for npm ci hits the cache but it seems that the working directory is empty.

I'm not sure what is going on there. I don't see that I'm doing anything obviously wrong. I will appreciate any help with debugging it.

PS this build is using gcr.io/makisu-project/makisu:v0.1.11 docker image and the following command to build the image(you can check CI config too):

/makisu-internal/makisu build
      --http-cache-addr="http://$CIRRUS_HTTP_CACHE_HOST"
      --registry-config=/root/.docker/config
      --tag cirrusci/web-front-end:makisu
      --commit=explicit
      --modifyfs=true
      --push=index.docker.io
      /makisu-context