Skip to content

Embed the Authorino version info into the binary#345

Merged
didierofrivia merged 1 commit intomainfrom
embed-version
Aug 24, 2022
Merged

Embed the Authorino version info into the binary#345
didierofrivia merged 1 commit intomainfrom
embed-version

Conversation

@guicassolato
Copy link
Collaborator

@guicassolato guicassolato commented Aug 24, 2022

The Authorino version info can be specified as a build argument (VERSION) of the docker build command, which is then set as an ldflag in the go build command.

When using the Makefile:

  1. If VERSION is not specified, it defaults to the Git ref (SHA-1) of HEAD;
  2. The image tag (IMAGE_TAG) is inferred from the value of VERSION (user-defined or set to default):
  • When it matches ^[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ (e.g. '0.10.0-pre'), the tag is set to v$VERSION (e.g. 'v0.10.0-pre');
  • otherwise, the tag is set to fixed value 'local'.

Additionally, a new parameter IMAGE_REPO was introduced to the Makefile (default: 'authorino'), and the existing parameter AUTHORINO_IMAGE now defaults to $(IMAGE_REPO):$(IMAGE_TAG).

In CI, VERSION is inferred based on GITHUB_REF_NAME:

  • When the Git ref (branch/tag name) matches ^v[0-9]+\.[0-9]+\.[0-9]+(-.+)?$, VERSION is set to GITHUB_REF_NAME (with all slashes replaced with dashes);
  • otherwise, VERSION is set to the actual Git ref (i.e. github.sha)

Also in this chnage:

  • New make target docker-build
  • Rename the binary to 'authorino' (previously: 'manager')

Verification steps

In all the scenarios below, you should be able to spot in the Auhtorino logs a message 'booting up authorino', with a label version, set to the value of the version build argument.

Scenario: Build and run the binary locally

Setup a cluster to target the service to:

kind create cluster
kubectl create namespace authorino-operator && kubectl apply -f https://raw.githubusercontent.com/Kuadrant/authorino-operator/main/config/install/manifests.yaml && make install

Build and run the binary locally:

make build
KUBECONFIG=$HOME/.kube/config ./bin/authorino

Try with a version number:

make build VERSION=0.10.0-pre
KUBECONFIG=$HOME/.kube/config ./bin/authorino

Cleanup:

kind delete cluster

Scenario: Build and run container image in docker

Setup a cluster to target the service to:

kind create cluster
kubectl create namespace authorino-operator && kubectl apply -f https://raw.githubusercontent.com/Kuadrant/authorino-operator/main/config/install/manifests.yaml && make install

Build and run container image in docker:

make docker-build
docker run \
  -v $HOME/.kube/config:/home/.kube/config \
  --env KUBECONFIG=/home/.kube/config \
  --network=host \
  authorino:local

Try with a version number:

make docker-build VERSION=0.10.0-pre
docker run \
  -v $HOME/.kube/config:/home/.kube/config \
  --env KUBECONFIG=/home/.kube/config \
  --network=host \
  authorino:v0.10.0-pre

Cleanup:

kind delete cluster

Scenario: Build and run container image in kubernetes

make local-setup FF=1

Cleanup:

make local-cleanup

The Authorino version info can be specified as a build argument (`VERSION`) of the `docker build` command, which is then set as an ldflag in the `go build` command.

When using the Makefile:
1. If `VERSION` is not specified, it defaults to the Git ref (SHA-1) of HEAD;
2. The image tag (`IMAGE_TAG`) is inferred from the value of `VERSION` (user-defined or set to default):
  - When it matches `^[0-9]+\.[0-9]+\.[0-9]+(-.+)?$` (e.g. '0.10.0-pre'), the tag is set to `v$VERSION` (e.g. 'v0.10.0-pre');
  - otherwise, the tag is set to fixed value 'local'.

Additionally, a new parameter `IMAGE_REPO` was introduced to the Makefile (default: 'authorino'), and the existing parameter `AUTHORINO_IMAGE` now defaults to `$(IMAGE_REPO):$(IMAGE_TAG)`.

In CI, `VERSION` is inferred based on `GITHUB_REF_NAME`:
- When the Git ref (branch/tag name) matches `^v[0-9]+\.[0-9]+\.[0-9]+(-.+)?$`, `VERSION` is set to `GITHUB_REF_NAME` (with all slashes replaced with dashes);
- otherwise, `VERSION` is set to the actual Git ref (i.e. `github.sha`)

Also in this chnage:
- New make target `docker-build`
- Rename the binary to 'authorino' (previously: 'manager')
@guicassolato guicassolato self-assigned this Aug 24, 2022
@guicassolato guicassolato requested a review from a team August 24, 2022 10:27
@didierofrivia didierofrivia merged commit 1f3dd71 into main Aug 24, 2022
@didierofrivia didierofrivia deleted the embed-version branch August 24, 2022 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants