Skip to content

Commit

Permalink
Build info (version and image tag) from the git ref name instead of u…
Browse files Browse the repository at this point in the history
…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
guicassolato committed Sep 3, 2024
1 parent b35735e commit 9e0d5ab
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 64 deletions.
54 changes: 23 additions & 31 deletions Makefile
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)
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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) ] || { \
Expand Down Expand Up @@ -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
Expand Down
16 changes: 4 additions & 12 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@

To release a version “vX.Y.Z” of Authorino in GitHub and Quay.io, follow these steps:

1. Create a release branch as source.
1. Pick a `<git-ref>` (SHA-1) as source.

```shell
git checkout release-vX.Y.Z
git checkout <git-ref>
```

2. Change the `version` field in `build.yaml` to `vX.Y.Z` and save.

```yaml
# This is where the build configuration is stored.
build:
version: vX.Y.Z
```
3. Create a new tag and named release `vX.Y.Z`. Push the tag to GitHub.
2. Create a new tag and named release `vX.Y.Z`. Push the tag to GitHub.

```shell
git tag -a vX.Y.Z -m "vX.Y.Z"
Expand All @@ -29,7 +21,7 @@ Then at the GitHub repository, create a new release from the tag you just pushed
release notes and then write the change notes highlighting all the new features, bug fixes, enhancements, etc.
([example](https://github.com/Kuadrant/authorino/releases/tag/v0.9.0)).

4. Run the GHA ‘Build and push images’ for the `vX.Y.Z` tag. This will cause a new image to be built and pushed to quay.io/kuadrant/authorino.
3. Run the GHA ‘Build and push images’ for the `vX.Y.Z` tag. This will cause a new image to be built and pushed to quay.io/kuadrant/authorino.

## Notes on Authorino’s automated builds

Expand Down
3 changes: 0 additions & 3 deletions build.yaml

This file was deleted.

18 changes: 0 additions & 18 deletions hack/write-version.sh

This file was deleted.

0 comments on commit 9e0d5ab

Please sign in to comment.