Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add version and git commit at compile time #244

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
RUNC_TEST_IMAGE=runc_test
PROJECT=github.com/opencontainers/runc
TEST_DOCKERFILE=script/test_Dockerfile
VERSION := $(shell cat VERSION)
export GOPATH:=$(CURDIR)/Godeps/_workspace:$(GOPATH)

GITCOMMIT := $(shell git rev-parse --short HEAD)
GITUNTRACKEDCHANGES := $(shell git status --porcelain --untracked-files=no)
ifneq ($(GITUNTRACKEDCHANGES),)
GITCOMMIT := $(GITCOMMIT)-dirty
endif
CTIMEVAR=-X $(PROJECT)/version.GitCommit '$(GITCOMMIT)' -X $(PROJECT)/version.Version '$(VERSION)'
GO_LDFLAGS=-ldflags "-w $(CTIMEVAR)"

all:
go build -o runc .
go build -o runc ${GO_LDFLAGS} .

vet:
go get golang.org/x/tools/cmd/vet
Expand All @@ -26,7 +35,7 @@ install:
cp runc /usr/local/bin/runc

clean:
rm runc
rm -f runc

validate: vet
script/validate-gofmt
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.2
12 changes: 7 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (

"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/opencontainers/runc/version"
)

const (
version = "0.2"
usage = `Open Container Initiative runtime
var (
usage = `Open Container Initiative runtime

runc is a command line client for running applications packaged according to
the Open Container Format (OCF) and is a compliant implementation of the
Expand All @@ -30,14 +30,16 @@ or
cd /mycontainer
runc start [ spec-file ]

If not specified, the default value for the 'spec-file' is 'config.json'. `
If not specified, the default value for the 'spec-file' is 'config.json'.

Built from git commit: ` + version.GitCommit
)

func main() {
app := cli.NewApp()
app.Name = "runc"
app.Usage = usage
app.Version = version
app.Version = version.Version
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "id",
Expand Down
7 changes: 7 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package version

// Version indicates which version of the binary is running.
var Version string

// GitCommit indicates which git hash the binary was built off of
var GitCommit string