main: Add a --version flag to show the build version
This embeds the version at build time and displays it when passed the --version flag.
This commit is contained in:
parent
63bb56e12d
commit
2cfe043f5e
3 changed files with 6 additions and 3 deletions
2
Makefile
2
Makefile
|
|
@ -98,7 +98,7 @@ $(BUILDDIR)/%/:
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build: $(BUILDDIR)/bin/ ## build the binary from source
|
build: $(BUILDDIR)/bin/ ## build the binary from source
|
||||||
go build -o $<image-builder ./cmd/image-builder/
|
go build -ldflags="-X main.BuildVersion=${VERSION}" -o $<image-builder ./cmd/image-builder/
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean: ## Remove all built binaries
|
clean: ## Remove all built binaries
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
osStdout io.Writer = os.Stdout
|
osStdout io.Writer = os.Stdout
|
||||||
osStderr io.Writer = os.Stderr
|
osStderr io.Writer = os.Stderr
|
||||||
|
BuildVersion = "DEVEL"
|
||||||
)
|
)
|
||||||
|
|
||||||
// basenameFor returns the basename for directory and filenames
|
// basenameFor returns the basename for directory and filenames
|
||||||
|
|
@ -378,6 +379,7 @@ image-type and blueprint.
|
||||||
Image-builder builds operating system images for a range of predefined
|
Image-builder builds operating system images for a range of predefined
|
||||||
operating systems like Fedora, CentOS and RHEL with easy customizations support.`,
|
operating systems like Fedora, CentOS and RHEL with easy customizations support.`,
|
||||||
SilenceErrors: true,
|
SilenceErrors: true,
|
||||||
|
Version: BuildVersion,
|
||||||
}
|
}
|
||||||
rootCmd.PersistentFlags().String("data-dir", "", `Override the default data directory for e.g. custom repositories/*.json data`)
|
rootCmd.PersistentFlags().String("data-dir", "", `Override the default data directory for e.g. custom repositories/*.json data`)
|
||||||
rootCmd.PersistentFlags().StringArray("extra-repo", nil, `Add an extra repository during build (will *not* be gpg checked and not be part of the final image)`)
|
rootCmd.PersistentFlags().StringArray("extra-repo", nil, `Add an extra repository during build (will *not* be gpg checked and not be part of the final image)`)
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,7 @@ export GOFLAGS+=" -mod=vendor"
|
||||||
GOTAGS="exclude_graphdriver_btrfs"
|
GOTAGS="exclude_graphdriver_btrfs"
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
|
export LDFLAGS="${LDFLAGS} -X 'main.BuildVersion=%{version}'"
|
||||||
%gobuild ${GOTAGS:+-tags=$GOTAGS} -o %{gobuilddir}/bin/image-builder %{goipath}/cmd/image-builder
|
%gobuild ${GOTAGS:+-tags=$GOTAGS} -o %{gobuilddir}/bin/image-builder %{goipath}/cmd/image-builder
|
||||||
|
|
||||||
%install
|
%install
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue