Skip to content

Commit

Permalink
Use static VERSION file for version inject
Browse files Browse the repository at this point in the history
This allows us to modify only one place to set the container as well as
the internal version.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
  • Loading branch information
saschagrunert committed Aug 13, 2020
1 parent 8beff86 commit e95aaa3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Expand Up @@ -36,9 +36,10 @@ ADD . /work
RUN make

FROM scratch
ARG version

LABEL name="Seccomp Operator" \
version="0.0.0" \
version=$version \
description="The Seccomp Operator makes it easier for cluster admins to manage their seccomp profiles and apply them to Kubernetes' workloads."

COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Expand Up @@ -26,14 +26,16 @@ endif

GIT_COMMIT := $(shell git rev-parse HEAD 2> /dev/null || echo unknown)
GIT_TREE_STATE := $(if $(shell git status --porcelain --untracked-files=no),dirty,clean)
VERSION := $(shell cat VERSION)

BUILDTAGS := netgo
BUILD_FILES := $(shell find . -type f -name '*.go' -or -name '*.mod' -or -name '*.sum' -not -name '*_test.go')
GO_PROJECT := sigs.k8s.io/$(PROJECT)
LDVARS := \
-X $(GO_PROJECT)/internal/pkg/version.buildDate=$(BUILD_DATE) \
-X $(GO_PROJECT)/internal/pkg/version.gitCommit=$(GIT_COMMIT) \
-X $(GO_PROJECT)/internal/pkg/version.gitTreeState=$(GIT_TREE_STATE)
-X $(GO_PROJECT)/internal/pkg/version.gitTreeState=$(GIT_TREE_STATE) \
-X $(GO_PROJECT)/internal/pkg/version.version=$(VERSION)
LDFLAGS := -s -w -linkmode external -extldflags "-static" $(LDVARS)

CONTAINER_RUNTIME ?= docker
Expand Down Expand Up @@ -85,7 +87,7 @@ default-profiles: ## Generate the default profiles

.PHONY: image
image: ## Build the container image
$(CONTAINER_RUNTIME) build -t $(IMAGE) .
$(CONTAINER_RUNTIME) build --build-arg version=$(VERSION) -t $(IMAGE) .

# Verification targets

Expand Down
1 change: 1 addition & 0 deletions VERSION
@@ -0,0 +1 @@
0.0.0
4 changes: 1 addition & 3 deletions internal/pkg/version/version.go
Expand Up @@ -24,13 +24,11 @@ import (
"text/tabwriter"
)

// version is the current version of the operator.
const version = "0.0.0"

var (
buildDate string // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
gitCommit string // sha1 from git, output of $(git rev-parse HEAD)
gitTreeState string // state of git tree, either "clean" or "dirty"
version string // the current version of the operator
)

type Info struct {
Expand Down

0 comments on commit e95aaa3

Please sign in to comment.