question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cache not found when pulling from container

See original GitHub issue

I have a simple workflow such as:

Where the “Prepare repository” and “Lint” jobs are jobs running in normal machine (not containerized) whereas the “Test suite” is containerized (because I need supporting service containers).

Here’s a simplified version of the workflow, so you can get the gist.

jobs:
  prepare_repository:
    name: Prepare repository for testing
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Setup node
        uses: actions/setup-node@v3
        with:
          node-version: 14.19.3

      - name: Prepare yarn cache
        id: yarn_cache
        shell: bash
        run: |
          yarn cache clean
          echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

      - name: Setting up cache
        uses: actions/cache@v3
        id: cache
        with:
          key: cache-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/src') }}
          path: |
            ${{ steps.yarn_cache.outputs.dir }}
            ./node_modules
            ./dist

      - if: ${{ steps.cache.outputs.cache-hit != 'true' }}
        name: Build for test
        run: |
          yarn install --frozen-lockfile
          yarn build:test

  run_lint:
    needs: prepare_repository

    name: Running linter
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Setup node
        uses: actions/setup-node@v3
        with:
          node-version: 14.19.3

      - name: Prepare yarn cache
        id: yarn_cache
        shell: bash
        run: |
          yarn cache clean
          echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

      - name: Setting up cache
        uses: actions/cache@v3
        id: cache
        with:
          key: cache-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/src') }}
          path: |
            ${{ steps.yarn_cache.outputs.dir }}
            ./node_modules
            ./dist

      - name: run lint
        run: |
          yarn lint
          yarn lint:file-and-dir-naming
          yarn lint:migrations

  run_tests:
    needs: prepare_repository

    name: tests suites
    runs-on: ubuntu-latest
    container: node:14.19.3

    services:
      mongo:
        image: mongo:4.4.3

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Prepare yarn cache
        id: yarn_cache
        shell: bash
        run: |
          yarn cache clean
          echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

      - name: Setting up cache
        uses: actions/cache@v3
        id: cache
        with:
          key: cache-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/src') }}
          path: |
            ${{ steps.yarn_cache.outputs.dir }}
            ./node_modules
            ./dist

      - name: Run test suite
        run: yarn test

The problem I have is in the log of those 3 jobs:

1st job (the builder)

Cache Size: ~552 MB (578855117 B)
Cache saved successfully
Cache saved with key: cache-57a6636dfb01a6d99def1d54cdd3bacc9690e0d1b96e972bddcec55f0ece5***-feca3d7ade3ad8b930***

2nd job (the linter)

Run actions/cache@v3
Received 0 of 578855117 (0.0%), 0.0 MBs/sec
Received 92274688 of 578855117 (15.9%), 43.9 MBs/sec
Received 226492416 of 578855117 (39.1%), 71.8 MBs/sec
Received 3774873[60](***) of 578855117 (65.2%), 89.8 MBs/sec
Received 511705088 of 578855117 (88.4%), 97.4 MBs/sec
Received 578855117 of 578855117 (100.0%), 93.1 MBs/sec
Cache Size: ~552 MB (578855117 B)
/usr/bin/tar --use-compress-program unzstd -xf /home/runner/work/_temp/84d2563f-635d-44f2-9d49-e5e66974b005/cache.tzst -P -C ***
Cache restored successfully
Cache restored from key: cache-57a6636dfb01a6d99def1d54cdd3bacc9690e0d1b96e972bddcec55f0ece5***-feca3d7ade3ad8b930***[61](***)23c7104c607583a79e9d5f982c5c5da80a1151***

3rd job (the tester)

Run actions/cache@v3
/usr/bin/docker exec  bf150bc133b4be09140814bc0b8c02143d052dc57855b9ffbdc4e649ba074cf7 sh -c "cat /etc/*release | grep ^ID"
Cache not found for input keys: cache-57a6636dfb01a6d99def1d54cdd3bacc9690e0d1b96e972bddcec55f0ece5***-feca3d7ade3ad8b930***[60](***)7583a79e9d5f982c5c5da80a1151***

As you can see:

  1. The cache key matches
  2. The cache is successfully uploaded in 1st job
  3. The cache is successfully retrieved in 2nd job
  4. The cache failed to be retrieved in the 3rd job
  5. The difference between 2nd and 3rd job is the container: directive in yaml
  6. Yes, if we comment the container and use actions/setup-node, it solves the issue.

I’m clueless at what to do here, please let me know if you have a workaround.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
vsvipulcommented, Nov 9, 2022

Yes, I understand that. Please leave a comment on the already open issue - https://github.com/actions/cache/issues/330 as well so that we can work on improving this in the future. Unfortunately, for now I can’t suggest you any workaround for this.

0reactions
vsvipulcommented, Nov 10, 2022

@y-nk I’m not sure about that. You’ll need to open a separate support ticket with GitHub for that.

Also, I was thinking about this and what if we change the path of the yarn cache itself in the container. Can you try running a solution like this inside the container? https://stackoverflow.com/questions/40381112/how-do-i-set-a-custom-cache-path-for-yarn

so that all the 3 paths match.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[HELP/QUESTION] Docker registry cache not working ... - GitHub
I have tried to setup a docker container for caching registry image pulls but without any success, the local registry only cache docker.io ......
Read more >
Docker - failed to compute cache key: not found - runs fine in ...
Check your .dockerignore file. Possible it ignores needed files for copy command and you get failed to compute cache key error.
Read more >
Docker Caching - do I restore my cache when I pull an image?
As long as nothing changes in the folder for the COPY command, the cache will be used. If the contents do change, this...
Read more >
Pulling cached Docker Hub images - Google Cloud
Pulling cached images · The Docker daemon checks the Container Registry cache and fetches the images if it exists. · If the image...
Read more >
Caching docker images is not working - CircleCI Discuss
The next step I would try is to manually cache the Docker image. As I understand it, you presently have no control over...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found