Skip to content

Commit 04855bd

Browse files
Filter out type=gha cache entries and print warning
GHA cache backend is redundant with Depot's built-in caching and can cause 'Our services aren't available right now' errors. This change filters out --cache-from and --cache-to entries with type=gha and prints a warning message to inform users that this cache type is being ignored. Fixes DEP-3118 Co-authored-by: jacob <jacob@depot.dev>
1 parent 6b86e64 commit 04855bd

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

pkg/buildx/bake/bake.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,10 +1269,10 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
12691269
}
12701270

12711271
if t.CacheFrom != nil {
1272-
bo.CacheFrom = buildflags.CreateCaches(t.CacheFrom)
1272+
bo.CacheFrom = buildflags.CreateCaches(buildflags.FilterGHACaches(t.CacheFrom, "cache-from"))
12731273
}
12741274
if t.CacheTo != nil {
1275-
bo.CacheTo = buildflags.CreateCaches(t.CacheTo)
1275+
bo.CacheTo = buildflags.CreateCaches(buildflags.FilterGHACaches(t.CacheTo, "cache-to"))
12761276
}
12771277

12781278
bo.Exports, _, err = buildflags.CreateExports(t.Outputs)

pkg/buildx/bake/buildflags/cache.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/csv"
66
"encoding/json"
7+
"fmt"
78
"maps"
89
"os"
910
"strconv"
@@ -265,3 +266,48 @@ func addAwsCredentials(ci *CacheOptionsEntry) {
265266
ci.Attrs["session_token"] = credentials.SessionToken
266267
}
267268
}
269+
270+
// FilterGHACaches filters out GitHub Actions cache entries (type=gha) and prints
271+
// a warning message when they are detected. The GHA cache backend is redundant
272+
// with Depot's built-in caching and can cause "Our services aren't available
273+
// right now" errors.
274+
func FilterGHACaches(entries CacheOptions, direction string) CacheOptions {
275+
var filtered CacheOptions
276+
var foundGHA bool
277+
278+
for _, entry := range entries {
279+
if entry.Type == "gha" {
280+
foundGHA = true
281+
continue
282+
}
283+
filtered = append(filtered, entry)
284+
}
285+
286+
if foundGHA {
287+
fmt.Fprintf(os.Stderr, "WARNING: Ignoring %s with type=gha: GitHub Actions cache is redundant with Depot's built-in caching\n", direction)
288+
}
289+
290+
return filtered
291+
}
292+
293+
// FilterGHACacheEntries filters out GitHub Actions cache entries (type=gha) from
294+
// client.CacheOptionsEntry slices and prints a warning message when they are detected.
295+
// This is used by the build command which uses docker/buildx types directly.
296+
func FilterGHACacheEntries(entries []client.CacheOptionsEntry, direction string) []client.CacheOptionsEntry {
297+
var filtered []client.CacheOptionsEntry
298+
var foundGHA bool
299+
300+
for _, entry := range entries {
301+
if entry.Type == "gha" {
302+
foundGHA = true
303+
continue
304+
}
305+
filtered = append(filtered, entry)
306+
}
307+
308+
if foundGHA {
309+
fmt.Fprintf(os.Stderr, "WARNING: Ignoring %s with type=gha: GitHub Actions cache is redundant with Depot's built-in caching\n", direction)
310+
}
311+
312+
return filtered
313+
}

pkg/buildx/commands/build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,13 +632,13 @@ func validateBuildOptions(in *buildOptions) (map[string]build.Options, error) {
632632
if err != nil {
633633
return nil, err
634634
}
635-
opts.CacheFrom = cacheImports
635+
opts.CacheFrom = depotbuildflags.FilterGHACacheEntries(cacheImports, "--cache-from")
636636

637637
cacheExports, err := buildflags.ParseCacheEntry(in.cacheTo)
638638
if err != nil {
639639
return nil, err
640640
}
641-
opts.CacheTo = cacheExports
641+
opts.CacheTo = depotbuildflags.FilterGHACacheEntries(cacheExports, "--cache-to")
642642

643643
allow, err := buildflags.ParseEntitlements(in.allow)
644644
if err != nil {

0 commit comments

Comments
 (0)