-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build info (version and image tag) from the git ref name instead of u…
…sing a local build-info file This makes the injection of build-info, particularly the version, in the binary consistent across local dev env and remote builds (ci). Signed-off-by: Guilherme Cassolato <[email protected]>
- Loading branch information
1 parent
b35735e
commit 9e0d5ab
Showing
4 changed files
with
27 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
# Use bash as shell | ||
SHELL = /bin/bash | ||
|
||
VERSION ?= 0.0.0 | ||
|
||
# Use vi as default editor | ||
EDITOR ?= vi | ||
|
||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) | ||
ifeq (,$(shell go env GOBIN)) | ||
GOBIN=$(shell go env GOPATH)/bin | ||
# Set version and image tag | ||
ifeq ($(VERSION),) | ||
VERSION = $(shell git rev-parse --abbrev-ref HEAD) | ||
endif | ||
ifeq ($(VERSION),main) | ||
override VERSION = latest | ||
endif | ||
using_semantic_version := $(shell [[ $(VERSION) =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.+)?$$ ]] && echo "true") | ||
ifdef using_semantic_version | ||
IMAGE_TAG=v$(VERSION) | ||
else | ||
GOBIN=$(shell go env GOBIN) | ||
IMAGE_TAG=local | ||
endif | ||
IMAGE_REPO ?= authorino | ||
AUTHORINO_IMAGE ?= $(IMAGE_REPO):$(IMAGE_TAG) | ||
|
||
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) | ||
export PATH := $(PROJECT_DIR)/bin:$(PATH) | ||
|
@@ -41,10 +48,6 @@ help: | |
|
||
##@ Dependencies | ||
|
||
YQ = $(PROJECT_DIR)/bin/yq | ||
yq: ## Download yq locally if necessary. | ||
$(call go-get-tool,$(YQ),github.com/mikefarah/yq/[email protected]) | ||
|
||
CONTROLLER_GEN = $(PROJECT_DIR)/bin/controller-gen | ||
controller-gen: ## Installs controller-gen in $PROJECT_DIR/bin | ||
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected]) | ||
|
@@ -80,6 +83,13 @@ ifeq ($(SED),) | |
exit 1 | ||
endif | ||
|
||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) | ||
ifeq (,$(shell go env GOBIN)) | ||
GOBIN=$(shell go env GOPATH)/bin | ||
else | ||
GOBIN=$(shell go env GOBIN) | ||
endif | ||
|
||
# go-get-tool will 'go install' any package $2 and install it to $1. | ||
define go-get-tool | ||
@[ -f $(1) ] || { \ | ||
|
@@ -115,38 +125,20 @@ manifests: controller-gen kustomize ## Generates the manifests in $PROJECT_DIR/i | |
controller-gen crd:crdVersions=v1 rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=install/crd output:rbac:artifacts:config=install/rbac && $(KUSTOMIZE) build install > $(AUTHORINO_MANIFESTS) | ||
$(MAKE) patch-webhook | ||
|
||
run: yq | ||
run:$(shell $(PROJECT_DIR)/hack/write-version.sh) | ||
run:version=$(shell $(YQ) '.build.version' build-recent.yaml) | ||
run:git_sha=$(shell git rev-parse HEAD) | ||
run:dirty=$(shell $(PROJECT_DIR)/hack/check-git-dirty.sh || echo "unknown") | ||
run: generate manifests ## Runs the application against the Kubernetes cluster configured in ~/.kube/config | ||
go run -ldflags "-X main.version=$(version) -X main.gitSHA=${git_sha} -X main.dirty=${dirty}" ./main.go server | ||
go run -ldflags "-X main.version=$(VERSION) -X main.gitSHA=${git_sha} -X main.dirty=${dirty}" ./main.go server | ||
|
||
build: yq | ||
build:$(shell $(PROJECT_DIR)/hack/write-version.sh) | ||
build:version=$(shell $(YQ) '.build.version' build-recent.yaml) | ||
build:git_sha=$(shell git rev-parse HEAD) | ||
build:dirty=$(shell $(PROJECT_DIR)/hack/check-git-dirty.sh || echo "unknown") | ||
build: generate ## Builds the manager binary | ||
CGO_ENABLED=0 GO111MODULE=on go build -a -ldflags "-X main.version=$(version) -X main.gitSHA=${git_sha} -X main.dirty=${dirty}" -o bin/authorino main.go | ||
|
||
IMAGE_REPO ?= authorino | ||
using_semantic_version := $(shell [[ $(VERSION) =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.+)?$$ ]] && echo "true") | ||
ifdef using_semantic_version | ||
IMAGE_TAG=v$(VERSION) | ||
else | ||
IMAGE_TAG=local | ||
endif | ||
AUTHORINO_IMAGE ?= $(IMAGE_REPO):$(IMAGE_TAG) | ||
CGO_ENABLED=0 GO111MODULE=on go build -a -ldflags "-X main.version=$(VERSION) -X main.gitSHA=${git_sha} -X main.dirty=${dirty}" -o bin/authorino main.go | ||
|
||
docker-build: yq | ||
docker-build:$(shell $(PROJECT_DIR)/hack/write-version.sh) | ||
docker-build:version=$(shell $(YQ) '.build.version' build-recent.yaml) | ||
docker-build:git_sha=$(shell git rev-parse HEAD) | ||
docker-build:dirty=$(shell $(PROJECT_DIR)/hack/check-git-dirty.sh || echo "unknown") | ||
docker-build: ## Builds an image based on the current branch | ||
docker build --build-arg version=$(version) --build-arg git_sha=$(git_sha) --build-arg dirty=$(dirty) -t $(AUTHORINO_IMAGE) . | ||
docker build --build-arg version=$(VERSION) --build-arg git_sha=$(git_sha) --build-arg dirty=$(dirty) -t $(AUTHORINO_IMAGE) . | ||
|
||
test: generate manifests envtest ## Runs the tests | ||
KUBEBUILDER_ASSETS='$(strip $(shell $(ENVTEST) use -p path 1.21.2 --os linux))' go test ./... -coverprofile cover.out | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.