Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having separate inject steps causes caches to be overwritten #39

Open
Redmega opened this issue Jul 25, 2024 · 1 comment
Open

Having separate inject steps causes caches to be overwritten #39

Redmega opened this issue Jul 25, 2024 · 1 comment

Comments

@Redmega
Copy link

Redmega commented Jul 25, 2024

I have two separate caches (one for dependencies, and one for next build caches within a monorepo) that I want to use in my docker build.

The problem is the cache-dance action seems to use the same source folder when extracting the caches. When I added my next build cache to the workflow, it seems that now it overwrites the mounted directed from the first inject step and now the yarn dependencies do not get detected by the docker build.

If I combine all my caches together I'll lose the ability to skip extraction on the dependencies which change much less frequently. I will waste time extracting my yarn cache despite it not changing.

      - name: Set up Yarn build cache
        id: yarn-cache
        uses: actions/cache@v4
        with:
          path: yarn-build-cache
          key: ${{ matrix.platform }}-yarn-${{ hashFiles('yarn.lock') }}
          restore-keys: |
            ${{ matrix.platform }}-yarn-
      - name: Set up Next build cache
        id: next-cache
        uses: actions/cache@v4
        with:
          path: |
            next-build-cache
            nx-build-cache
          key: ${{ matrix.platform }}-next-${{ matrix.app.name }}-${{ hashFiles('yarn.lock') }}-${{ hashFiles(format('apps/{0}/**', matrix.app.name)) }}
          restore-keys: |
            ${{ matrix.platform }}-next-${{ matrix.app.name }}-${{ hashFiles('yarn.lock') }}-
      - name: Inject caches into Docker
        uses: reproducible-containers/buildkit-cache-dance@v3
        with:
          cache-map: |
            {
              "yarn-build-cache": "/fe/.yarn/cache"
            }
          skip-extraction: ${{ steps.yarn-cache.outputs.cache-hit }}
      - name: Inject next cache into Docker
        uses: reproducible-containers/buildkit-cache-dance@v3
        with:
          cache-map: |
            {
              "next-build-cache": "/fe/apps/${{ matrix.app.name }}/.next/cache",
              "nx-build-cache": "/fe/.nx"
            }
          skip-extraction: ${{ steps.next-cache.outputs.cache-hit }}
@insanitybit
Copy link

I think I'm seeing the same behavior, but unsure. Regardless, it seems that just changing the cache-dance directory such that it's configurable would let this be fixed, or having it be something like /var/hash(paths).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants