github.com/containerd/Containerd@v1.4.13/cmd/ctr/commands/version/version.go (about)

     1  /*
     2     Copyright The containerd Authors.
     3  
     4     Licensed under the Apache License, Version 2.0 (the "License");
     5     you may not use this file except in compliance with the License.
     6     You may obtain a copy of the License at
     7  
     8         http://www.apache.org/licenses/LICENSE-2.0
     9  
    10     Unless required by applicable law or agreed to in writing, software
    11     distributed under the License is distributed on an "AS IS" BASIS,
    12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13     See the License for the specific language governing permissions and
    14     limitations under the License.
    15  */
    16  
    17  package version
    18  
    19  import (
    20  	"fmt"
    21  	"os"
    22  
    23  	"github.com/containerd/containerd/cmd/ctr/commands"
    24  	"github.com/containerd/containerd/version"
    25  	"github.com/urfave/cli"
    26  )
    27  
    28  // Command is a cli command to output the client and containerd server version
    29  var Command = cli.Command{
    30  	Name:  "version",
    31  	Usage: "print the client and server versions",
    32  	Action: func(context *cli.Context) error {
    33  		fmt.Println("Client:")
    34  		fmt.Println("  Version: ", version.Version)
    35  		fmt.Println("  Revision:", version.Revision)
    36  		fmt.Println("  Go version:", version.GoVersion)
    37  		fmt.Println("")
    38  		client, ctx, cancel, err := commands.NewClient(context)
    39  		if err != nil {
    40  			return err
    41  		}
    42  		defer cancel()
    43  		v, err := client.Version(ctx)
    44  		if err != nil {
    45  			return err
    46  		}
    47  		fmt.Println("Server:")
    48  		fmt.Println("  Version: ", v.Version)
    49  		fmt.Println("  Revision:", v.Revision)
    50  		di, err := client.Server(ctx)
    51  		if err != nil {
    52  			return err
    53  		}
    54  		fmt.Println("  UUID:", di.UUID)
    55  		if v.Version != version.Version {
    56  			fmt.Fprintln(os.Stderr, "WARNING: version mismatch")
    57  		}
    58  		if v.Revision != version.Revision {
    59  			fmt.Fprintln(os.Stderr, "WARNING: revision mismatch")
    60  		}
    61  		return nil
    62  	},
    63  }