Skip to content

Commit

Permalink
buildx: force ListWorker response for any environment
Browse files Browse the repository at this point in the history
  • Loading branch information
gmichelo committed Oct 12, 2023
1 parent 2bbecf9 commit 3569e0a
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 8 deletions.
22 changes: 14 additions & 8 deletions internal/cli/cmd/cluster/buildkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,23 @@ func newBuildkitProxy() *cobra.Command {
}

func parseInjectWorkerInfo(workerInfoFile string, requiredPlatform api.BuildPlatform) (*controlapi.ListWorkersResponse, error) {
if workerInfoFile == "" {
return nil, nil
}

workerInfo, err := os.ReadFile(workerInfoFile)
if err != nil {
return nil, err
var workerDefData []byte
if workerInfoFile != "" {
workerInfo, err := os.ReadFile(workerInfoFile)
if err != nil {
return nil, err
}
workerDefData = workerInfo
} else {
// Settlemint uses the buildx also for local dev, but tenant token expires after 24h.
// API returns an authz error, but buildx does not show the error unless we unstuck it from its
// known bug where it block on ListWorkers buildkit API call for ever.
// So, embed the shortcut list worker payload:
workerDefData = []byte(staticWorkerDef)
}

f := &controlapi.ListWorkersResponse{}
if err := json.Unmarshal(workerInfo, f); err != nil {
if err := json.Unmarshal(workerDefData, f); err != nil {
return nil, err
}

Expand Down
62 changes: 62 additions & 0 deletions internal/cli/cmd/cluster/buildx_workers_def.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package cluster

const staticWorkerDef = `
{
"record": [
{
"ID": "namespace-amd64-builder",
"Labels": {
"org.mobyproject.buildkit.worker.executor": "oci",
"org.mobyproject.buildkit.worker.hostname": "namespace-amd64-builder",
"org.mobyproject.buildkit.worker.network": "cni",
"org.mobyproject.buildkit.worker.oci.process-mode": "sandbox",
"org.mobyproject.buildkit.worker.selinux.enabled": "false",
"org.mobyproject.buildkit.worker.snapshotter": "overlayfs"
},
"platforms": [
{ "Architecture": "amd64", "OS": "linux" },
{ "Architecture": "amd64", "OS": "linux", "Variant": "v2" },
{ "Architecture": "amd64", "OS": "linux", "Variant": "v3" },
{ "Architecture": "amd64", "OS": "linux", "Variant": "v4" },
{ "Architecture": "386", "OS": "linux" }
],
"GCPolicy": [
{ "keepDuration": 604800000000000, "keepBytes": 32000000000 },
{ "keepBytes": 47000000000 },
{ "all": true, "keepBytes": 50000000000 }
],
"BuildkitVersion": {
"package": "github.com/moby/buildkit",
"version": "v0.12.0-namespace",
"revision": "latest"
}
},
{
"ID": "namespace-arm64-builder",
"Labels": {
"org.mobyproject.buildkit.worker.executor": "oci",
"org.mobyproject.buildkit.worker.hostname": "namespace-arm64-builder",
"org.mobyproject.buildkit.worker.network": "cni",
"org.mobyproject.buildkit.worker.oci.process-mode": "sandbox",
"org.mobyproject.buildkit.worker.selinux.enabled": "false",
"org.mobyproject.buildkit.worker.snapshotter": "overlayfs"
},
"platforms": [
{ "Architecture": "arm64", "OS": "linux" },
{ "Architecture": "arm64", "OS": "linux", "Variant": "v6" },
{ "Architecture": "arm64", "OS": "linux", "Variant": "v7" }
],
"GCPolicy": [
{ "keepDuration": 604800000000000, "keepBytes": 32000000000 },
{ "keepBytes": 47000000000 },
{ "all": true, "keepBytes": 50000000000 }
],
"BuildkitVersion": {
"package": "github.com/moby/buildkit",
"version": "v0.12.0-namespace",
"revision": "latest"
}
}
]
}
`

0 comments on commit 3569e0a

Please sign in to comment.