new service: version
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/version"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@@ -15,14 +15,14 @@ var (
|
||||
|
||||
func init() {
|
||||
cli.VersionPrinter = func(c *cli.Context) {
|
||||
fmt.Println(c.App.Name, containerd.Package, c.App.Version)
|
||||
fmt.Println(c.App.Name, version.Package, c.App.Version)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "ctr"
|
||||
app.Version = containerd.Version
|
||||
app.Version = version.Version
|
||||
app.Usage = `
|
||||
__
|
||||
_____/ /______
|
||||
@@ -61,6 +61,7 @@ containerd client
|
||||
execCommand,
|
||||
pauseCommand,
|
||||
resumeCommand,
|
||||
versionCommand,
|
||||
}
|
||||
app.Commands = append(app.Commands, extraCmds...)
|
||||
app.Before = func(context *cli.Context) error {
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/containerd/containerd/api/services/execution"
|
||||
imagesapi "github.com/containerd/containerd/api/services/images"
|
||||
rootfsapi "github.com/containerd/containerd/api/services/rootfs"
|
||||
versionservice "github.com/containerd/containerd/api/services/version"
|
||||
"github.com/containerd/containerd/api/types/container"
|
||||
"github.com/containerd/containerd/content"
|
||||
"github.com/containerd/containerd/images"
|
||||
@@ -59,6 +60,14 @@ func getImageStore(clicontext *cli.Context) (images.Store, error) {
|
||||
return imagesservice.NewStoreFromClient(imagesapi.NewImagesClient(conn)), nil
|
||||
}
|
||||
|
||||
func getVersionService(context *cli.Context) (versionservice.VersionClient, error) {
|
||||
conn, err := getGRPCConnection(context)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return versionservice.NewVersionClient(conn), nil
|
||||
}
|
||||
|
||||
func getTempDir(id string) (string, error) {
|
||||
err := os.MkdirAll(filepath.Join(os.TempDir(), "ctr"), 0700)
|
||||
if err != nil {
|
||||
|
||||
43
cmd/ctr/version.go
Normal file
43
cmd/ctr/version.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
gocontext "context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/containerd/containerd/version"
|
||||
empty "github.com/golang/protobuf/ptypes/empty"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var versionCommand = cli.Command{
|
||||
Name: "version",
|
||||
Usage: "print the version",
|
||||
Action: func(context *cli.Context) error {
|
||||
if context.NArg() > 0 {
|
||||
return fmt.Errorf("no argument expected")
|
||||
}
|
||||
fmt.Println("Client:")
|
||||
fmt.Printf(" Version: %s\n", version.Version)
|
||||
fmt.Printf(" Revision: %s\n", version.Revision)
|
||||
fmt.Println("")
|
||||
vs, err := getVersionService(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v, err := vs.Version(gocontext.Background(), &empty.Empty{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("Server:")
|
||||
fmt.Printf(" Version: %s\n", v.Version)
|
||||
fmt.Printf(" Revision: %s\n", v.Revision)
|
||||
if v.Version != version.Version {
|
||||
fmt.Fprintf(os.Stderr, "WARNING: version mismatch\n")
|
||||
}
|
||||
if v.Revision != version.Revision {
|
||||
fmt.Fprintf(os.Stderr, "WARNING: revision mismatch\n")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user