diff --git a/Dockerfile b/Dockerfile index 755ff5a8..31b9f1ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,11 +11,9 @@ COPY go.sum . RUN go mod download # Copy the go source -COPY main.go . -COPY api/ api/ -COPY pkg/ pkg/ +COPY . . # Build -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -a -o applicationset-controller main.go +RUN make build FROM ubuntu:20.10 @@ -41,4 +39,4 @@ RUN mkdir -p /app/config/gpg/source && \ # chmod 0700 /app/config/gpg/keys WORKDIR / -COPY --from=builder /workspace/applicationset-controller /usr/local/bin/ +COPY --from=builder /workspace/dist/argocd-applicationset /usr/local/bin/applicationset-controller diff --git a/Makefile b/Makefile index ed47356f..19a330f2 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,12 @@ +VERSION_PACKAGE=github.com/argoproj-labs/applicationset/common VERSION?=$(shell cat VERSION) IMAGE_NAMESPACE?=argoproj IMAGE_NAME?=argocd-applicationset IMAGE_TAG?=latest CONTAINER_REGISTRY?=quay.io +GIT_COMMIT = $(shell git rev-parse HEAD) +LDFLAGS = -w -s -X ${VERSION_PACKAGE}.version=${VERSION} \ + -X ${VERSION_PACKAGE}.gitCommit=${GIT_COMMIT} MKDOCS_DOCKER_IMAGE?=squidfunk/mkdocs-material:4.1.1 MKDOCS_RUN_ARGS?= @@ -34,7 +38,7 @@ endif .PHONY: build build: manifests fmt vet - CGO_ENABLED=0 go build -ldflags="-w -s" -o ./dist/argocd-applicationset . + CGO_ENABLED=0 go build -ldflags="${LDFLAGS}" -o ./dist/argocd-applicationset . .PHONY: test test: generate fmt vet manifests diff --git a/common/version.go b/common/version.go new file mode 100644 index 00000000..d88cd3a5 --- /dev/null +++ b/common/version.go @@ -0,0 +1,21 @@ +package common + +// version information populated during build time +var ( + version = "" // value from VERSION file + gitCommit = "" // output of git rev-parse HEAD +) + +// Version of the applicationset controller +type Version struct { + Version string + GitCommit string +} + +// GetVersion returns the version of the applicationset controller +func GetVersion() Version { + return Version{ + Version: "v" + version, + GitCommit: gitCommit, + } +} diff --git a/main.go b/main.go index 13d66dba..d2cd6dd4 100644 --- a/main.go +++ b/main.go @@ -31,6 +31,7 @@ import ( "github.com/argoproj-labs/applicationset/pkg/services" "github.com/argoproj-labs/applicationset/pkg/utils" + "github.com/argoproj-labs/applicationset/common" argov1alpha1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1" "github.com/argoproj/argo-cd/util/db" argosettings "github.com/argoproj/argo-cd/util/settings" @@ -110,7 +111,8 @@ func main() { namespace = "argocd" } - setupLog.Info(fmt.Sprintf("ApplicationSet controller using namespace '%s'", namespace), "namespace", namespace) + version := common.GetVersion() + setupLog.Info(fmt.Sprintf("ApplicationSet controller %s using namespace '%s'", version.Version, namespace), "namespace", namespace, "COMMIT_ID", version.GitCommit) mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ Scheme: scheme,