Skip to content

Commit

Permalink
control: add info service
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
(cherry picked from commit 859ad49)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
crazy-max authored and thaJeztah committed Oct 4, 2022
1 parent 067c577 commit 63d1215
Show file tree
Hide file tree
Showing 7 changed files with 840 additions and 101 deletions.
841 changes: 743 additions & 98 deletions api/services/control/control.pb.go

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion api/services/control/control.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ service Control {
rpc Status(StatusRequest) returns (stream StatusResponse);
rpc Session(stream BytesMessage) returns (stream BytesMessage);
rpc ListWorkers(ListWorkersRequest) returns (ListWorkersResponse);
// rpc Info(InfoRequest) returns (InfoResponse);
rpc Info(InfoRequest) returns (InfoResponse);
}

message PruneRequest {
Expand Down Expand Up @@ -157,3 +157,15 @@ message ListWorkersRequest {
message ListWorkersResponse {
repeated moby.buildkit.v1.types.WorkerRecord record = 1;
}

message Version {
string package = 1;
string version = 2;
string revision = 3;
}

message InfoRequest {}

message InfoResponse {
Version buildkitVersion = 1;
}
9 changes: 9 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func TestIntegration(t *testing.T) {
testUncompressedLocalCacheImportExport,
testUncompressedRegistryCacheImportExport,
testStargzLazyRegistryCacheImportExport,
testCallInfo,
)
tests = append(tests, diffOpTestCases()...)
integration.Run(t, tests, mirrors)
Expand Down Expand Up @@ -5727,6 +5728,14 @@ func testBuildInfoNoExport(t *testing.T, sb integration.Sandbox) {
require.Equal(t, exbi.Sources[0].Ref, "docker.io/library/busybox:latest")
}

func testCallInfo(t *testing.T, sb integration.Sandbox) {
c, err := New(sb.Context(), sb.Address())
require.NoError(t, err)
defer c.Close()
_, err = c.Info(sb.Context())
require.NoError(t, err)
}

func tmpdir(appliers ...fstest.Applier) (string, error) {
tmpdir, err := os.MkdirTemp("", "buildkit-client")
if err != nil {
Expand Down
32 changes: 32 additions & 0 deletions client/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package client

import (
"context"

controlapi "github.com/moby/buildkit/api/services/control"
"github.com/pkg/errors"
)

type InfoResponse struct {
BuildkitVersion Version
}

func (c *Client) Info(ctx context.Context) (*InfoResponse, error) {
res, err := c.controlClient().Info(ctx, &controlapi.InfoRequest{})
if err != nil {
return nil, errors.Wrap(err, "failed to call info")
}
return &InfoResponse{
BuildkitVersion: Version{
Package: res.BuildkitVersion.Package,
Version: res.BuildkitVersion.Version,
Revision: res.BuildkitVersion.Revision,
},
}, nil
}

type Version struct {
Package string
Version string
Revision string
}
1 change: 1 addition & 0 deletions cmd/buildctl/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ var debugCommand = cli.Command{
debug.DumpLLBCommand,
debug.DumpMetadataCommand,
debug.WorkersCommand,
debug.InfoCommand,
},
}
30 changes: 30 additions & 0 deletions cmd/buildctl/debug/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package debug

import (
"fmt"
"os"
"text/tabwriter"

bccommon "github.com/moby/buildkit/cmd/buildctl/common"
"github.com/urfave/cli"
)

var InfoCommand = cli.Command{
Name: "info",
Usage: "display internal information",
Action: info,
}

func info(clicontext *cli.Context) error {
c, err := bccommon.ResolveClient(clicontext)
if err != nil {
return err
}
res, err := c.Info(bccommon.CommandContext(clicontext))
if err != nil {
return err
}
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
_, _ = fmt.Fprintf(w, "BuildKit:\t%s %s %s\n", res.BuildkitVersion.Package, res.BuildkitVersion.Version, res.BuildkitVersion.Revision)
return w.Flush()
}
14 changes: 12 additions & 2 deletions control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"sync/atomic"
"time"

"github.com/moby/buildkit/util/bklog"

controlapi "github.com/moby/buildkit/api/services/control"
apitypes "github.com/moby/buildkit/api/types"
"github.com/moby/buildkit/cache/remotecache"
Expand All @@ -20,9 +18,11 @@ import (
"github.com/moby/buildkit/solver"
"github.com/moby/buildkit/solver/llbsolver"
"github.com/moby/buildkit/solver/pb"
"github.com/moby/buildkit/util/bklog"
"github.com/moby/buildkit/util/imageutil"
"github.com/moby/buildkit/util/throttle"
"github.com/moby/buildkit/util/tracing/transform"
"github.com/moby/buildkit/version"
"github.com/moby/buildkit/worker"
"github.com/pkg/errors"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
Expand Down Expand Up @@ -435,6 +435,16 @@ func (c *Controller) ListWorkers(ctx context.Context, r *controlapi.ListWorkersR
return resp, nil
}

func (c *Controller) Info(ctx context.Context, r *controlapi.InfoRequest) (*controlapi.InfoResponse, error) {
return &controlapi.InfoResponse{
BuildkitVersion: &controlapi.Version{
Package: version.Package,
Version: version.Version,
Revision: version.Revision,
},
}, nil
}

func (c *Controller) gc() {
c.gcmu.Lock()
defer c.gcmu.Unlock()
Expand Down

0 comments on commit 63d1215

Please sign in to comment.