diff options
author | Adin Scannell <ascannell@google.com> | 2019-04-01 16:17:40 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-04-01 16:18:43 -0700 |
commit | 7543e9ec2043af7d071373aeec04b92a98051087 (patch) | |
tree | f43044f892c853d5cf97fe5d12f6d6702a2a02f1 /runsc | |
parent | 7cff746ef2bbe5351e5985bebc88efc9e0881c78 (diff) |
Add release hook and version flag
PiperOrigin-RevId: 241421671
Change-Id: Ic0cebfe3efd458dc42c49f7f812c13318705199a
Diffstat (limited to 'runsc')
-rw-r--r-- | runsc/BUILD | 6 | ||||
-rw-r--r-- | runsc/main.go | 15 | ||||
-rw-r--r-- | runsc/specutils/specutils.go | 3 | ||||
-rw-r--r-- | runsc/version.go | 18 |
4 files changed, 36 insertions, 6 deletions
diff --git a/runsc/BUILD b/runsc/BUILD index e390b7bae..eb7503502 100644 --- a/runsc/BUILD +++ b/runsc/BUILD @@ -6,12 +6,13 @@ go_binary( name = "runsc", srcs = [ "main.go", + "version.go", ], pure = "on", visibility = [ "//visibility:public", ], - x_defs = {"main.gitRevision": "{GIT_REVISION}"}, + x_defs = {"main.version": "{VERSION}"}, deps = [ "//pkg/log", "//runsc/boot", @@ -36,12 +37,13 @@ go_binary( name = "runsc-race", srcs = [ "main.go", + "version.go", ], static = "on", visibility = [ "//visibility:public", ], - x_defs = {"main.gitRevision": "{GIT_REVISION}"}, + x_defs = {"main.version": "{VERSION}"}, deps = [ "//pkg/log", "//runsc/boot", diff --git a/runsc/main.go b/runsc/main.go index 4b3f55ad1..bbf08228c 100644 --- a/runsc/main.go +++ b/runsc/main.go @@ -18,6 +18,7 @@ package main import ( "context" + "fmt" "io" "os" "path/filepath" @@ -40,6 +41,7 @@ var ( logFilename = flag.String("log", "", "file path where internal debug information is written, default is stdout") logFormat = flag.String("log-format", "text", "log format: text (default), json, or json-k8s") debug = flag.Bool("debug", false, "enable debug logging") + showVersion = flag.Bool("version", false, "show version and exit") // These flags are unique to runsc, and are used to configure parts of the // system that are not covered by the runtime spec. @@ -69,9 +71,6 @@ var ( testOnlyAllowRunAsCurrentUserWithoutChroot = flag.Bool("TESTONLY-unsafe-nonroot", false, "TEST ONLY; do not ever use! This skips many security measures that isolate the host from the sandbox.") ) -// gitRevision is set during linking. -var gitRevision = "" - func main() { // Help and flags commands are generated automatically. subcommands.Register(subcommands.HelpCommand(), "") @@ -107,6 +106,14 @@ func main() { // All subcommands must be registered before flag parsing. flag.Parse() + // Are we showing the version? + if *showVersion { + // The format here is the same as runc. + fmt.Fprintf(os.Stdout, "runsc version %s\n", version) + fmt.Fprintf(os.Stdout, "spec: %s\n", specutils.Version) + os.Exit(0) + } + platformType, err := boot.MakePlatformType(*platform) if err != nil { cmd.Fatalf("%v", err) @@ -215,7 +222,7 @@ func main() { log.Infof("***************************") log.Infof("Args: %s", os.Args) - log.Infof("Git Revision: %s", gitRevision) + log.Infof("Version %s", version) log.Infof("PID: %d", os.Getpid()) log.Infof("UID: %d, GID: %d", os.Getuid(), os.Getgid()) log.Infof("Configuration:") diff --git a/runsc/specutils/specutils.go b/runsc/specutils/specutils.go index cbf099c64..af8d34535 100644 --- a/runsc/specutils/specutils.go +++ b/runsc/specutils/specutils.go @@ -38,6 +38,9 @@ import ( // changed in tests that aren't linked in the same binary. var ExePath = "/proc/self/exe" +// Version is the supported spec version. +var Version = specs.Version + // LogSpec logs the spec in a human-friendly way. func LogSpec(spec *specs.Spec) { log.Debugf("Spec: %+v", spec) diff --git a/runsc/version.go b/runsc/version.go new file mode 100644 index 000000000..4894f2de6 --- /dev/null +++ b/runsc/version.go @@ -0,0 +1,18 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +// version is set during linking. +var version = "" |