Add release hook and version flag

PiperOrigin-RevId: 241421671
Change-Id: Ic0cebfe3efd458dc42c49f7f812c13318705199a
This commit is contained in:
Adin Scannell 2019-04-01 16:17:40 -07:00 committed by Shentubot
parent 7cff746ef2
commit 7543e9ec20
6 changed files with 90 additions and 7 deletions

View File

@ -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",

View File

@ -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:")

View File

@ -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)

18
runsc/version.go Normal file
View File

@ -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 = ""

53
tools/tag_release.sh Executable file
View File

@ -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 <commit|revid> <release.rc>"
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)

View File

@ -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)