Handle case of missing GH variables (#492)

Closes #482 

I traced the problem to where buildx parses the cli args
([here](fa4461b9a1/util/buildflags/cache.go (L14))),
and confirmed it applies defaults based on GHA environment variables and
ignores the cacheTo/cacheFrom directive altogether when the variables
aren't available.

The fix is to ignore the GHA cache directive when it the upstream parser
ignores it.
This commit is contained in:
Eron Wright
2025-03-20 09:27:59 -07:00
committed by GitHub
parent f41c8c927d
commit 20f5f536dc
4 changed files with 100 additions and 12 deletions

View File

@@ -576,7 +576,9 @@ func (ia *ImageArgs) validate(supportsMultipleExports, preview bool) (controller
multierr = errors.Join(multierr, newCheckFailure(err, "exports[%d]", idx))
continue
}
exports = append(exports, exp)
if exp != nil {
exports = append(exports, exp)
}
}
platforms := []string{}
@@ -586,7 +588,9 @@ func (ia *ImageArgs) validate(supportsMultipleExports, preview bool) (controller
multierr = errors.Join(multierr, newCheckFailure(err, "platforms[%d]", idx))
continue
}
platforms = append(platforms, platform)
if platform != "" {
platforms = append(platforms, platform)
}
}
cacheFrom := []*controllerapi.CacheOptionsEntry{}
@@ -599,7 +603,9 @@ func (ia *ImageArgs) validate(supportsMultipleExports, preview bool) (controller
multierr = errors.Join(multierr, newCheckFailure(err, "cacheFrom[%d]", idx))
continue
}
cacheFrom = append(cacheFrom, cache)
if cache != nil {
cacheFrom = append(cacheFrom, cache)
}
}
cacheTo := []*controllerapi.CacheOptionsEntry{}
@@ -612,7 +618,9 @@ func (ia *ImageArgs) validate(supportsMultipleExports, preview bool) (controller
multierr = errors.Join(multierr, newCheckFailure(err, "cacheTo[%d]", idx))
continue
}
cacheTo = append(cacheTo, cache)
if cache != nil {
cacheTo = append(cacheTo, cache)
}
}
ssh := []*controllerapi.SSH{}
@@ -622,7 +630,9 @@ func (ia *ImageArgs) validate(supportsMultipleExports, preview bool) (controller
multierr = errors.Join(multierr, newCheckFailure(err, "ssh[%d]", idx))
continue
}
ssh = append(ssh, ss)
if ss != nil {
ssh = append(ssh, ss)
}
}
for idx, t := range normalized.Tags {