nx-tools icon indicating copy to clipboard operation
nx-tools copied to clipboard

Github Actions caches do not work.

Open brandoncollins7 opened this issue 2 years ago • 2 comments

I have put the correct cache info, I see it correct in the flags the plugin calls to build to the container, but it does not download or upload any cache.

When I do this in my CI cache works (even though I see pretty much the exact same docker buildx command in the output) - But there are reasons I would like to build my containers using the nx plugin and it's frustrating that the cache doesn't work as it really slows down my builds:(

  - name: Set up Docker Buildx
    uses: docker/setup-buildx-action@v2

  - name: Build with dev deps
    uses: docker/build-push-action@v3
    env:
      ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
    with:
      context: .
      build-args: |
        npm_auth_token=${{ secrets.NPM_AUTH_TOKEN }}
      push: false
      tags: ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ github.sha }}
      cache-from: type=gha,scope=${{ env.ECR_REPOSITORY }}-$${{ github.ref }}-build
      cache-to: type=gha,mode=max,scope=${{ env.ECR_REPOSITORY }}-$${{ github.ref }}-build
      target: build
      load: true
      
      And here is the nx script I'm using:
      
      INPUT_BUILD_ARGS="$(echo -e "APP=${{ matrix.packages.name }}\nNPM_AUTH_TOKEN=${{ secrets.NPM_AUTH_TOKEN }}")" INPUT_CACHE_FROM=type=gha,scope=${{ matrix.packages.name }} INPUT_CACHE_TO=type=gha,mode=max,scope=${{ matrix.packages.name }} INPUT_TAGS="${{ matrix.packages.name }}-$(echo -e "${{ matrix.packages.imageTag }}\n${{ matrix.packages.name }}-$(echo "${{ matrix.packages.imageTag }}" | cut -d'-' -f1)\n${{ matrix.packages.name }}-latest")" INPUT_PUSH=${{ inputs.push }} INPUT_GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} npx nx container ${{ matrix.packages.name }}

brandoncollins7 avatar May 04 '23 13:05 brandoncollins7

Here is the build output, as you can see the cache statements are there and correct...

/usr/bin/docker buildx build --build-arg APP=quote-ticker-api --build-arg NPM_AUTH_TOKEN=*** --cache-from type=gha,scope=quote-ticker-api --cache-to type=gha,mode=max,scope=quote-ticker-api --file /home/runner/work/quote-ticker-api/Dockerfile --iidfile /tmp/docker-build-push-eSLdJr/iidfile --label org.opencontainers.image.title=my-project --label org.opencontainers.image.description=My Project --label org.opencontainers.image.url=redacted --label org.opencontainers.image.source=redacted --label org.opencontainers.image.version=quote-ticker-api-0.0.33-staging.2 --label org.opencontainers.image.created=2023-05-04T13:58:20.561Z --label org.opencontainers.image.revision=38ec3cb3bf63541ccf5cb2f9d9bcf105dae0d2e9 --label org.opencontainers.image.licenses= --secret id=GIT_AUTH_TOKEN,src=/tmp/docker-build-push-eSLdJr/tmp-2449-yyV07ZiNnX2v --tag ***/my-project:quote-ticker-api-0.0.33-staging.2 --tag ***/my-project:quote-ticker-api-0.0.33 --tag ***/my-project:quote-ticker-api-latest --metadata-file /tmp/docker-build-push-eSLdJr/metadata-file --push .

brandoncollins7 avatar May 04 '23 14:05 brandoncollins7

Hey @brandoncollins7! We're encountering the same issue too. Wondering if you've discovered any workarounds for it. Thanks! 🙌🏼

sibest19 avatar Feb 13 '24 17:02 sibest19