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 = "" diff --git a/tools/tag_release.sh b/tools/tag_release.sh new file mode 100755 index 000000000..6906a952f --- /dev/null +++ b/tools/tag_release.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# 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. + +# This script will optionally map a PiperOrigin-RevId to a given commit, +# validate a provided release name, create a tag and push it. It must be +# run manually when a release is created. + +set -euxo pipefail + +# Check arguments. +if [ "$#" -ne 2 ]; then + echo "usage: $0 " + exit 1 +fi + +commit=$1 +release=$2 + +# Is the passed identifier a sha commit? +if ! git show "${commit}" &> /dev/null; then + # Extract the commit given a piper ID. + commit=$(git log|grep -E "(^commit |^ PiperOrigin-RevId:)" |grep -B1 "RevId: ${commit}"| head -n1|cut -d" " -f2) +fi +if ! git show "${commit}" &> /dev/null; then + echo "unknown commit: ${commit}" + exit 1 +fi + +# Is the release name sane? Must be a date with patch/rc. +if ! [[ "${release}" =~ ^20[0-9]{6}\.[0-9]+$ ]]; then + expected=$(date +%Y%m%d.0) # Use today's date. + echo "unexpected release format: ${release}" + echo " ... expected like ${expected}" + exit 1 +fi + +# Tag the given commit. +tag="release-${release}" +(git tag "${tag}" "${commit}" && git push origin tag "${tag}") || \ + (git tag -d "${tag}" && false) diff --git a/tools/workspace_status.sh b/tools/workspace_status.sh index 7d44dad37..a0e646e45 100755 --- a/tools/workspace_status.sh +++ b/tools/workspace_status.sh @@ -14,4 +14,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -echo GIT_REVISION $(git describe --always --abbrev=40 --dirty) +echo VERSION $(git describe --always --tags --abbrev=12 --dirty)