Skip to content

fix(docker): use scope instead of ref for GHA cache backend#1213

Merged
int128 merged 2 commits intoint128:mainfrom
NikitaCOEUR:fix-gha-backend-scope
Jan 11, 2026
Merged

fix(docker): use scope instead of ref for GHA cache backend#1213
int128 merged 2 commits intoint128:mainfrom
NikitaCOEUR:fix-gha-backend-scope

Conversation

@NikitaCOEUR
Copy link
Copy Markdown
Contributor

This pull request updates the generateDockerFlags function and its associated tests to dynamically determine the correct key (scope or ref) for Docker cache flags based on the cacheType input. This improves flexibility and ensures compatibility with different cache types.

Updates to generateDockerFlags function:

  • Modified the generateDockerFlags function in src/docker.ts to use a dynamic key (refKey) for cache flags, which is set to scope if cacheType is gha, and ref otherwise. This change affects both cacheFrom and cacheTo flag generation. [1] [2]

Updates to tests:

  • Updated the unit test in tests/docker.test.ts to reflect the new behavior of the generateDockerFlags function, verifying that the correct key (scope or ref) is used in the generated cache flags.

Context

When using the GitHub Actions (GHA) cache backend, the use of useless tags ref= leads to cache collisions between different builds, branches, and stages due to the shared default namespace (buildkit).

This change replaces ref= with scope= when the cache type is gha, as recommended by the official Docker documentation: https://docs.docker.com/build/cache/backends/gha/#scope

Using scope= ensures proper cache isolation and prevents unintended invalidation, significantly improving cache reliability.

When using the GitHub Actions (GHA) cache backend, the use of useless tags `ref=` leads to cache collisions between different builds, branches, and stages due to the shared default namespace (buildkit).

This change replaces `ref=` with `scope=` when the cache type is `gha`, as recommended by the official Docker documentation: https://docs.docker.com/build/cache/backends/gha/#scope

Using `scope=` ensures proper cache isolation and prevents unintended
invalidation, significantly improving cache reliability.
NikitaCOEUR added a commit to Groupe-Hevea/ci-github-container that referenced this pull request Jul 31, 2025
This commit introduces a workaround for the GitHub Actions cache backend
when using the docker `cache-from` and `cache-to` flags with BuildKit.

The current version of `int128/docker-build-cache-config-action` incorrectly uses
`ref=` instead of `scope=` for the `gha` cache backend, which leads to shared
caches across branches and builds, resulting in frequent invalidations and
inefficient caching.

Until the upstream PR is merged and released:
int128/docker-build-cache-config-action#1213

...this commit replace `ref=` by `scope=` to ensure proper cache
isolation and reliable cache behavior in CI.

This workaround will be removed once the upstream fix is available in a stable release.
Copy link
Copy Markdown
Contributor

@neilime neilime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@neilime
Copy link
Copy Markdown
Contributor

neilime commented Aug 16, 2025

@int128 can you check this PR please?

It's a good one IMO!

@neilime
Copy link
Copy Markdown
Contributor

neilime commented Sep 3, 2025

Hi @int128, kindly reminder, can you have a look at this PR please?

@neilime
Copy link
Copy Markdown
Contributor

neilime commented Sep 29, 2025

Hi @int128, here is my monthly kindly reminder, I you can have a look to this PR please.

neilime pushed a commit to hoverkraft-tech/ci-github-container that referenced this pull request Sep 30, 2025
This commit introduces a workaround for the GitHub Actions cache backend
when using the docker `cache-from` and `cache-to` flags with BuildKit.

The current version of `int128/docker-build-cache-config-action` incorrectly uses
`ref=` instead of `scope=` for the `gha` cache backend, which leads to shared
caches across branches and builds, resulting in frequent invalidations and
inefficient caching.

Until the upstream PR is merged and released:
int128/docker-build-cache-config-action#1213

...this commit replace `ref=` by `scope=` to ensure proper cache
isolation and reliable cache behavior in CI.

This workaround will be removed once the upstream fix is available in a stable release.
@neilime
Copy link
Copy Markdown
Contributor

neilime commented Nov 30, 2025

Hi @int128, any change to get this PR review / merged?

Thanks

@neilime
Copy link
Copy Markdown
Contributor

neilime commented Jan 2, 2026

Hi @int128,
Is there a chance to get this PR review / merged?

Thanks

Copy link
Copy Markdown
Owner

@int128 int128 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Sorry for the late reply.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@int128 int128 merged commit 62504f8 into int128:main Jan 11, 2026
3 checks passed
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

Successfully merging this pull request may close these issues.

4 participants