mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-19 09:57:45 +08:00

Removes gogo/protobuf from buildx and updates to a version of moby/buildkit where gogo is removed. This also changes how the proto files are generated. This is because newer versions of protobuf are more strict about name conflicts. If two files have the same name (even if they are relative paths) and are used in different protoc commands, they'll conflict in the registry. Since protobuf file generation doesn't work very well with `paths=source_relative`, this removes the `go:generate` expression and just relies on the dockerfile to perform the generation. Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
controlapi "github.com/moby/buildkit/api/services/control"
|
|
apitypes "github.com/moby/buildkit/api/types"
|
|
"github.com/moby/buildkit/solver/pb"
|
|
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// WorkerInfo contains information about a worker
|
|
type WorkerInfo struct {
|
|
ID string `json:"id"`
|
|
Labels map[string]string `json:"labels"`
|
|
Platforms []ocispecs.Platform `json:"platforms"`
|
|
GCPolicy []PruneInfo `json:"gcPolicy"`
|
|
BuildkitVersion BuildkitVersion `json:"buildkitVersion"`
|
|
}
|
|
|
|
// ListWorkers lists all active workers
|
|
func (c *Client) ListWorkers(ctx context.Context, opts ...ListWorkersOption) ([]*WorkerInfo, error) {
|
|
info := &ListWorkersInfo{}
|
|
for _, o := range opts {
|
|
o.SetListWorkersOption(info)
|
|
}
|
|
|
|
req := &controlapi.ListWorkersRequest{Filter: info.Filter}
|
|
resp, err := c.ControlClient().ListWorkers(ctx, req)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "failed to list workers")
|
|
}
|
|
|
|
var wi []*WorkerInfo
|
|
|
|
for _, w := range resp.Record {
|
|
wi = append(wi, &WorkerInfo{
|
|
ID: w.ID,
|
|
Labels: w.Labels,
|
|
Platforms: pb.ToSpecPlatforms(w.Platforms),
|
|
GCPolicy: fromAPIGCPolicy(w.GCPolicy),
|
|
BuildkitVersion: fromAPIBuildkitVersion(w.BuildkitVersion),
|
|
})
|
|
}
|
|
|
|
return wi, nil
|
|
}
|
|
|
|
// ListWorkersOption is an option for a worker list query
|
|
type ListWorkersOption interface {
|
|
SetListWorkersOption(*ListWorkersInfo)
|
|
}
|
|
|
|
// ListWorkersInfo is a payload for worker list query
|
|
type ListWorkersInfo struct {
|
|
Filter []string
|
|
}
|
|
|
|
func fromAPIGCPolicy(in []*apitypes.GCPolicy) []PruneInfo {
|
|
out := make([]PruneInfo, 0, len(in))
|
|
for _, p := range in {
|
|
out = append(out, PruneInfo{
|
|
All: p.All,
|
|
Filter: p.Filters,
|
|
KeepDuration: time.Duration(p.KeepDuration),
|
|
MinStorage: p.MinStorage,
|
|
MaxStorage: p.MaxStorage,
|
|
Free: p.Free,
|
|
})
|
|
}
|
|
return out
|
|
}
|