docker-container: write github actions payload to container for provenance
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/docker/buildx/driver"
|
||||
"github.com/docker/buildx/driver/bkimage"
|
||||
"github.com/docker/buildx/util/confutil"
|
||||
"github.com/docker/buildx/util/ghutil"
|
||||
"github.com/docker/buildx/util/imagetools"
|
||||
"github.com/docker/buildx/util/progress"
|
||||
"github.com/docker/cli/cli/context/docker"
|
||||
@@ -43,20 +44,21 @@ type Driver struct {
|
||||
|
||||
// if you add fields, remember to update docs:
|
||||
// https://github.com/docker/docs/blob/main/content/build/drivers/docker-container.md
|
||||
netMode string
|
||||
image string
|
||||
memory opts.MemBytes
|
||||
memorySwap opts.MemSwapBytes
|
||||
cpuQuota int64
|
||||
cpuPeriod int64
|
||||
cpuShares int64
|
||||
cpusetCpus string
|
||||
cpusetMems string
|
||||
cgroupParent string
|
||||
restartPolicy container.RestartPolicy
|
||||
env []string
|
||||
defaultLoad bool
|
||||
gpus []container.DeviceRequest
|
||||
netMode string
|
||||
image string
|
||||
memory opts.MemBytes
|
||||
memorySwap opts.MemSwapBytes
|
||||
cpuQuota int64
|
||||
cpuPeriod int64
|
||||
cpuShares int64
|
||||
cpusetCpus string
|
||||
cpusetMems string
|
||||
cgroupParent string
|
||||
restartPolicy container.RestartPolicy
|
||||
env []string
|
||||
defaultLoad bool
|
||||
gpus []container.DeviceRequest
|
||||
writeProvenanceGHA bool
|
||||
}
|
||||
|
||||
func (d *Driver) IsMobyDriver() bool {
|
||||
@@ -137,6 +139,17 @@ func (d *Driver) create(ctx context.Context, l progress.SubLogger) error {
|
||||
},
|
||||
}
|
||||
|
||||
if d.writeProvenanceGHA {
|
||||
if ghactx, err := ghutil.GithubActionsContext(); err != nil {
|
||||
return err
|
||||
} else if ghactx != nil {
|
||||
if d.Files == nil {
|
||||
d.Files = make(map[string][]byte)
|
||||
}
|
||||
d.Files["provenance.d/github_actions_context.json"] = ghactx
|
||||
}
|
||||
}
|
||||
|
||||
// Mount WSL libaries if running in WSL environment and Docker context
|
||||
// is a local socket as requesting GPU on container builder creation
|
||||
// is not enough when generating the CDI specification for GPU devices.
|
||||
|
||||
@@ -47,9 +47,10 @@ func (f *factory) New(ctx context.Context, cfg driver.InitConfig) (driver.Driver
|
||||
return nil, err
|
||||
}
|
||||
d := &Driver{
|
||||
factory: f,
|
||||
InitConfig: cfg,
|
||||
restartPolicy: rp,
|
||||
factory: f,
|
||||
InitConfig: cfg,
|
||||
restartPolicy: rp,
|
||||
writeProvenanceGHA: true,
|
||||
}
|
||||
var gpus dockeropts.GpuOpts
|
||||
if err := gpus.Set("all"); err == nil {
|
||||
@@ -111,6 +112,11 @@ func (f *factory) New(ctx context.Context, cfg driver.InitConfig) (driver.Driver
|
||||
return nil, errors.Errorf("invalid env option %q, expecting env.FOO=bar", k)
|
||||
}
|
||||
d.env = append(d.env, fmt.Sprintf("%s=%s", envName, v))
|
||||
case k == "provenance-add-gha":
|
||||
d.writeProvenanceGHA, err = strconv.ParseBool(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
return nil, errors.Errorf("invalid driver option %s for docker-container driver", k)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user