Open zfalen-deloitte opened 11 months ago
I am facing same issue that the npm ci
step in Dockerfile has not being cached.
I'm think also seeing (something like?) this, but surprisingly only for 1 app out of 6. Can't figure out what's different about it.
...
#8 [stage-1 1/3] FROM docker.io/library/nginx:1.19-alpine@sha256:07ab71a2c8e4ecb19a5a5abcfb3a4f175946c001c8af288b1aa766d67b0d05d2
#8 resolve docker.io/library/nginx:1.19-alpine@sha256:07ab71a2c8e4ecb19a5a5abcfb3a4f175946c001c8af288b1aa766d67b0d05d2 done
#8 DONE 0.0s
#9 [auth] ***/testers-portal:pull token for registry-1.docker.io
#9 DONE 0.0s
#10 importing cache manifest from ***/testers-portal:buildcache
#10 inferred cache manifest type: application/vnd.oci.image.index.v1+json done
#10 DONE 0.6s
#6 [internal] load build context
#6 transferring context: 2.17MB 0.1s done
#6 DONE 0.1s
#11 [client-app 2/7] WORKDIR /app
#11 CACHED
#12 [client-app 3/7] COPY [./package*.json, /app/]
#12 CACHED
#13 [client-app 4/7] RUN npm install --silent
#13 sha256:27bbc6afb145de99accc53bcb39c9c8f18fa87d6299209502377b68761bda221 0B / 104.79MB 0.2s
#13 sha256:3c461cc005eb2f5800f3de8399ddf0ceb9af4eb901febfc663213273f8c89a9f 164.68kB / 164.68kB 0.2s done
#13 sha256:cb1607bbeb42eb40ec9066fc85f1b7f8ef0d0d175ffcff70cfeb0fd4744828b6 99B / 99B 0.2s done
#13 sha256:98b00e0a6a079def65676f976e860e2067ac07536ceaecc04b5d19c64958a3c5 292B / 292B 0.2s done
#13 sha256:63ee7d0b743d2664350409e8297032641e454e77286e03edf996706abfd4553c 4.16kB / 4.16kB 0.1s done
...
Confirmed, same problem on my CI.
Same problem for me. Strangely when bypassing the build-push-action
and simply running the cli command ( docker buildx build....) it's cacheing everything besides the node-modules, and when using the prebuilt action, it's happening from time to time.
The same problem happens to me. Is there any solution?
FROM node:18.15-alpine AS base
RUN apk add tzdata && ln -snf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
FROM base AS builder
WORKDIR /app
COPY package-lock.json package.json tsconfig.build.json tsconfig.json ./
RUN npm install
COPY src ./src
RUN npm run build
FROM base AS runner
WORKDIR /app
COPY --from=builder /app/package*.json /app/tsconfig*.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
EXPOSE 3000
CMD [ "npm", "run", "start" ]
name: Docker Cache Test
on:
push:
branches: main
jobs:
docker-cache-test:
runs-on: ubuntu-22.04
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Set Up Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64
- name: Build & Push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: '${{ steps.login-ecr.outputs.registry }}/actions_test:latest'
cache-from: type=gha
cache-to: type=gha, mode=max
provenance: false
...
#10 [builder 2/5] COPY package-lock.json package.json tsconfig.build.json tsconfig.json ./
#10 DONE 1.2s
#11 [builder 3/5] RUN npm install
#11 10.91
#11 10.91 added 714 packages, and audited 715 packages in 10s
#11 10.91
#11 10.91 116 packages are looking for funding
#11 10.91 run `npm fund` for details
#11 10.92
#11 10.92 found 0 vulnerabilities
#11 10.92 npm notice
#11 10.92 npm notice New major version of npm available! 9.5.0 -> 10.5.2
#11 10.92 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v10.5.2>
#11 10.92 npm notice Run `npm install -g npm@10.5.2` to update!
#11 10.92 npm notice
#11 DONE 11.0s
#12 [builder 4/5] COPY src ./src
#12 DONE 1.1s
#13 [builder 5/5] RUN npm run build
#13 0.536
#13 0.536 > docker_cache@0.0.1 build
#13 0.536 > nest build
#13 0.536
#13 DONE 4.8s
#14 [runner 2/4] COPY --from=builder /app/package*.json /app/tsconfig*.json ./
#14 CACHED
#15 [runner 3/4] COPY --from=builder /app/node_modules ./node_modules
#15 CACHED
#15 [runner 3/4] COPY --from=builder /app/node_modules ./node_modules
#15 sha256:47368dd19a5d423d64f17607c08d29e7fc545064a8e1322a88937fbc7aeb74f4 0B / 31.17MB 0.2s
#15 sha256:546c24b708c7d128e445c9a0461c7072e0d3d0c0abbaea7abc4e9d8f760303f1 81.60kB / 81.60kB 0.2s done
#15 extracting sha256:546c24b708c7d128e445c9a0461c7072e0d3d0c0abbaea7abc4e9d8f760303f1 done
#15 sha256:47368dd19a5d423d64f17607c08d29e7fc545064a8e1322a88937fbc7aeb74f4 4.19MB / 31.17MB 0.5s
#15 sha256:47368dd19a5d423d64f17607c08d29e7fc545064a8e1322a88937fbc7aeb74f4 6.29MB / 31.17MB 0.6s
#15 sha256:47368dd19a5d423d64f17607c08d29e7fc545064a8e1322a88937fbc7aeb74f4 9.44MB / 31.17MB 0.8s
#15 sha256:47368dd19a5d423d64f17607c08d29e7fc545064a8e1322a88937fbc7aeb74f4 13.63MB / 31.17MB 0.9s
#15 sha256:47368dd19a5d423d64f17607c08d29e7fc545064a8e1322a88937fbc7aeb74f4 17.83MB / 31.17MB 1.1s
#15 sha256:47368dd19a5d423d64f17607c08d29e7fc545064a8e1322a88937fbc7aeb74f4 22.02MB / 31.17MB 1.2s
#15 sha256:47368dd19a5d423d64f17607c08d29e7fc545064a8e1322a88937fbc7aeb74f4 26.21MB / 31.17MB 1.4s
#15 sha256:47368dd19a5d423d64f17607c08d29e7fc545064a8e1322a88937fbc7aeb74f4 30.41MB / 31.17MB 1.5s
#15 sha256:47368dd19a5d423d64f17607c08d29e7fc545064a8e1322a88937fbc7aeb74f4 31.17MB / 31.17MB 1.6s done
#15 extracting sha256:47368dd19a5d423d64f17607c08d29e7fc545064a8e1322a88937fbc7aeb74f4
#15 extracting sha256:47368dd19a5d423d64f17607c08d29e7fc545064a8e1322a88937fbc7aeb74f4 3.3s done
#15 DONE 5.0s
...
I am having the same issue, it also happens with docker compose build
using the gha
cache in a Github action. The layers are saved but then not used consistently even without changes to the repo. (I also tried having .git
in .dockerignore
but that didn't help)
Maybe cache is being evicted because you exceed storage limit: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy
GitHub will remove any cache entries that have not been accessed in over 7 days. There is no limit on the number of caches you can store, but the total size of all caches in a repository is limited to 10 GB.
You can check that at https://github.com/<repo>/actions/caches
Have the same behavior with the registry cache (using AWS ECR)
Contributing guidelines
I've found a bug, and:
Description
SO Link here: https://stackoverflow.com/questions/77623949/docker-caching-on-github-actions-npm-install-is-not-cached
I am using the documented examples for caching Docker build layers via the GitHub Actions cache described here.
It appears to be working mostly as intended. It does successfully create a cache - and seems to pull many layers from it - but it does not cache arguably the most important layer:
npm-modules
No changes to the dependency files are occurring during/prior to the builds below. Theoretically, these layers should be 100% reusable unless we make changes to the
package.json
- and it would save my build time ~1.5minMy setup in the workflow:
Relevant stage of the Dockerfile:
Some steps are caching, from logs e.g.:
However, the next steps seemingly fail to cache - especially the
npm ci
step:Weirdly, later in the Dockerfile I reference these modules:
...which pulls from the cache, apparently.
Expected behaviour
GHA Cache should cache all layers which are unchanged between builds.
Actual behaviour
GHA Cache is caching only some layers, and not the
node_modules
- which is arguably the most important layer to cache.IMPORTANT NOTE: Layer caching with this Dockerfile works as expected locally. That is to say, the
npm ci
step is cached/reused on my local machine usingdocker build
when no changes to the dependencies are present.YAML workflow