mirror of
https://github.com/opencontainers/runc.git
synced 2025-09-27 03:46:19 +08:00
runc: embed version from VERSION file
This ensures that if runc is built without the provided Makefile, the version is still properly set. No change in the output. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
8
Makefile
8
Makefile
@@ -17,8 +17,8 @@ BUILDTAGS += $(EXTRA_BUILDTAGS)
|
|||||||
|
|
||||||
COMMIT := $(shell git describe --dirty --long --always)
|
COMMIT := $(shell git describe --dirty --long --always)
|
||||||
EXTRA_VERSION :=
|
EXTRA_VERSION :=
|
||||||
VERSION := $(shell cat ./VERSION)$(EXTRA_VERSION)
|
LDFLAGS_COMMON := -X main.gitCommit=$(COMMIT) \
|
||||||
LDFLAGS_COMMON := -X main.gitCommit=$(COMMIT) -X main.version=$(VERSION)
|
$(if $(strip $(EXTRA_VERSION)),-X main.extraVersion=$(EXTRA_VERSION),)
|
||||||
|
|
||||||
GOARCH := $(shell $(GO) env GOARCH)
|
GOARCH := $(shell $(GO) env GOARCH)
|
||||||
|
|
||||||
@@ -118,11 +118,11 @@ release: runcimage
|
|||||||
--rm -v $(CURDIR):/go/src/$(PROJECT) \
|
--rm -v $(CURDIR):/go/src/$(PROJECT) \
|
||||||
-e RELEASE_ARGS=$(RELEASE_ARGS) \
|
-e RELEASE_ARGS=$(RELEASE_ARGS) \
|
||||||
$(RUNC_IMAGE) make localrelease
|
$(RUNC_IMAGE) make localrelease
|
||||||
script/release_sign.sh -S $(GPG_KEYID) -r release/$(VERSION) -v $(VERSION)
|
script/release_sign.sh -S $(GPG_KEYID)
|
||||||
|
|
||||||
.PHONY: localrelease
|
.PHONY: localrelease
|
||||||
localrelease: verify-changelog
|
localrelease: verify-changelog
|
||||||
script/release_build.sh -r release/$(VERSION) -v $(VERSION) $(RELEASE_ARGS)
|
script/release_build.sh $(RELEASE_ARGS)
|
||||||
|
|
||||||
.PHONY: dbuild
|
.PHONY: dbuild
|
||||||
dbuild: runcimage
|
dbuild: runcimage
|
||||||
|
17
main.go
17
main.go
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
_ "embed"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -19,12 +20,18 @@ import (
|
|||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
// version must be set from the contents of VERSION file by go build's
|
// version is set from the contents of VERSION file.
|
||||||
// -X main.version= option in the Makefile.
|
//
|
||||||
var version = "unknown"
|
//go:embed VERSION
|
||||||
|
var version string
|
||||||
|
|
||||||
|
// extraVersion is an optional suffix appended to runc version.
|
||||||
|
// It can be set via Makefile ("make EXTRA_VERSION=xxx") or by
|
||||||
|
// adding -X main.extraVersion=xxx option to the go build command.
|
||||||
|
var extraVersion = ""
|
||||||
|
|
||||||
// gitCommit will be the hash that the binary was built from
|
// gitCommit will be the hash that the binary was built from
|
||||||
// and will be populated by the Makefile
|
// and will be populated by the Makefile.
|
||||||
var gitCommit = ""
|
var gitCommit = ""
|
||||||
|
|
||||||
func printVersion(c *cli.Context) {
|
func printVersion(c *cli.Context) {
|
||||||
@@ -73,7 +80,7 @@ value for "bundle" is the current directory.`
|
|||||||
func main() {
|
func main() {
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Name = "runc"
|
app.Name = "runc"
|
||||||
app.Version = version
|
app.Version = strings.TrimSpace(version) + extraVersion
|
||||||
app.Usage = usage
|
app.Usage = usage
|
||||||
|
|
||||||
cli.VersionPrinter = printVersion
|
cli.VersionPrinter = printVersion
|
||||||
|
Reference in New Issue
Block a user