From d2e319523d15bab57432969688b5f419ec76bc54 Mon Sep 17 00:00:00 2001 From: Peter Edge Date: Fri, 18 Dec 2015 13:06:04 +0000 Subject: [PATCH] Use protoversion for containerd version Signed-off-by: Peter Edge --- containerd/main.go | 13 ++++++++++++- ctr/container.go | 6 +++++- ctr/main.go | 3 ++- ctr/version.go | 22 ++++++++++++++++++++++ version.go | 8 +++++++- 5 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 ctr/version.go diff --git a/containerd/main.go b/containerd/main.go index eebeb9f..4c0e141 100644 --- a/containerd/main.go +++ b/containerd/main.go @@ -9,6 +9,8 @@ import ( "syscall" "time" + "go.pedge.io/proto/version" + "google.golang.org/grpc" "github.com/Sirupsen/logrus" @@ -77,7 +79,7 @@ var daemonFlags = []cli.Flag{ func main() { app := cli.NewApp() app.Name = "containerd" - app.Version = containerd.Version + app.Version = containerd.Version.VersionString() app.Usage = Usage app.Authors = authors app.Flags = daemonFlags @@ -201,6 +203,15 @@ func daemon(id, address, stateDir string, concurrency int, oom bool) error { } s := grpc.NewServer() types.RegisterAPIServer(s, server.NewServer(sv)) + protoversion.RegisterAPIServer( + s, + protoversion.NewAPIServer( + containerd.Version, + protoversion.APIServerOptions{ + DisableLogging: true, + }, + ), + ) logrus.Debugf("GRPC API listen on %s", address) return s.Serve(l) } diff --git a/ctr/container.go b/ctr/container.go index 8b0758f..ae164a3 100644 --- a/ctr/container.go +++ b/ctr/container.go @@ -23,6 +23,10 @@ import ( // TODO: parse flags and pass opts func getClient(ctx *cli.Context) types.APIClient { + return types.NewAPIClient(getClientConn(ctx)) +} + +func getClientConn(ctx *cli.Context) *grpc.ClientConn { dialOpts := []grpc.DialOption{grpc.WithInsecure()} dialOpts = append(dialOpts, grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) { @@ -33,7 +37,7 @@ func getClient(ctx *cli.Context) types.APIClient { if err != nil { fatal(err.Error(), 1) } - return types.NewAPIClient(conn) + return conn } var ContainersCommand = cli.Command{ diff --git a/ctr/main.go b/ctr/main.go index aa0a3e3..cf83789 100644 --- a/ctr/main.go +++ b/ctr/main.go @@ -14,7 +14,7 @@ const Usage = `High performance container daemon cli` func main() { app := cli.NewApp() app.Name = "ctr" - app.Version = containerd.Version + app.Version = containerd.Version.VersionString() app.Usage = Usage app.Authors = []cli.Author{ { @@ -37,6 +37,7 @@ func main() { CheckpointCommand, ContainersCommand, EventsCommand, + VersionCommand, } app.Before = func(context *cli.Context) error { if context.GlobalBool("debug") { diff --git a/ctr/version.go b/ctr/version.go new file mode 100644 index 0000000..f6f3c3b --- /dev/null +++ b/ctr/version.go @@ -0,0 +1,22 @@ +package main + +import ( + "fmt" + + "go.pedge.io/proto/version" + + "github.com/codegangsta/cli" + "github.com/docker/containerd" +) + +var VersionCommand = cli.Command{ + Name: "version", + Usage: "get the containerd version", + Action: func(context *cli.Context) { + serverVersion, err := protoversion.GetServerVersion(getClientConn(context)) + if err != nil { + fatal(err.Error(), 1) + } + fmt.Printf("Client: %s\nServer: %s\n", containerd.Version.VersionString(), serverVersion.VersionString()) + }, +} diff --git a/version.go b/version.go index b741b19..db894d6 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,9 @@ package containerd -const Version = "0.0.4" +import "go.pedge.io/proto/version" + +var Version = &protoversion.Version{ + Major: 0, + Minor: 0, + Micro: 4, +}