Skip to content

Commit

Permalink
Merge pull request #473 from Kuadrant/471-add-commit-hash-implementat…
Browse files Browse the repository at this point in the history
…ion-similar-to-kuadrantctl-to-authorino

add commit hash implementation similar to kuadrantctl to authorino
  • Loading branch information
guicassolato authored Sep 12, 2024
2 parents 14126e3 + 7a7d904 commit 7d07f22
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 36 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/build-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ jobs:
id: add-branch-tag
run: |
echo "IMG_TAGS=${GITHUB_REF_NAME/\//-} ${{ env.IMG_TAGS }}" >> $GITHUB_ENV
- name: Set Authorino version
id: authorino-version
- name: Set Authorino build info
id: authorino-build-info
run: |
if [[ ${GITHUB_REF_NAME/\//-} =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]]; then
echo "VERSION=${GITHUB_REF_NAME/\//-}" >> $GITHUB_ENV
tag=${GITHUB_REF_NAME/\//-}
echo "version=${tag#v}" >> $GITHUB_ENV
elif [[ ${GITHUB_REF_NAME/\//-} == "main" ]]; then
echo "version=latest" >> $GITHUB_ENV
else
echo "VERSION=${{ github.sha }}" >> $GITHUB_ENV
echo "version=${{ github.ref_name }}" >> $GITHUB_ENV
fi
echo "git_sha=${{ github.sha }}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Build Image
Expand All @@ -48,7 +52,9 @@ jobs:
tags: ${{ env.IMG_TAGS }}
platforms: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le
build-args: |
version=${{ env.VERSION }}
git_sha=${{ env.git_sha }}
version=${{ env.version }}
dirty=${{ env.dirty }}
containerfiles: |
./Dockerfile
- name: Push Image
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ vendor
tmp
target
.scannerwork
build-recent.yaml
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ FROM registry.access.redhat.com/ubi9/go-toolset:1.21 AS builder
USER root
WORKDIR /usr/src/authorino
COPY ./ ./
ARG version=latest
RUN CGO_ENABLED=0 GO111MODULE=on go build -a -ldflags "-X main.version=${version}" -o /usr/bin/authorino main.go
ARG version
ENV version=${version:-unknown}
ARG git_sha
ENV git_sha=${git_sha:-unknown}
ARG dirty
ENV dirty=${dirty:-unknown}
RUN CGO_ENABLED=0 GO111MODULE=on go build -a -ldflags "-X main.version=${version} -X main.gitSHA=${git_sha} -X main.dirty=${dirty}" -o /usr/bin/authorino main.go

# Use Red Hat minimal base image to package the binary
# https://catalog.redhat.com/software/containers/ubi9-minimal
Expand Down
47 changes: 29 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
# Use bash as shell
SHELL = /bin/bash

# Authorino version
VERSION = $(shell git rev-parse HEAD)

# 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 @@ -77,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 @@ -112,22 +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: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)" ./main.go server
go run -ldflags "-X main.version=$(VERSION) -X main.gitSHA=${git_sha} -X main.dirty=${dirty}" ./main.go server

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)" -o bin/authorino main.go
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)
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) -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
10 changes: 5 additions & 5 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

## Process

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

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

```shell
git checkout <git-ref>
```

2. Create a new tag and named release `v0.X.Y`. 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 v0.X.Y -m "v0.X.Y"
git push origin v0.X.Y
git tag -a vX.Y.Z -m "vX.Y.Z"
git push origin vX.Y.Z
```

Then at the GitHub repository, create a new release from the tag you just pushed. One could start autogenerating the
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)).

3. Run the GHA ‘Build and push images’ for the `v0.X.Y` 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
4 changes: 2 additions & 2 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions hack/check-git-dirty.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

if ! command -v git &>/dev/null
then
echo "git not found..." >&2
exit 1
fi

if output=$(git diff --stat 2>/dev/null)
then
[ -n "$output" ] && echo "true" || echo "false"
else
# Not a git repository
exit 1
fi
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const (
var (
// ldflags
version string
dirty string
gitSHA string

scheme = runtime.NewScheme()
logger logr.Logger
Expand Down Expand Up @@ -373,7 +375,7 @@ func runWebhookServer(cmd *cobra.Command, _ []string) {
func setup(cmd *cobra.Command, log logOptions, telemetry telemetryOptions) {
setupLogger(log)

logger.Info("booting up authorino", "version", version, "cmd", cmd.Use)
logger.Info("build information", "version", version, "commit", gitSHA, "dirty", dirty, "cmd", cmd.Use)

// log the command-line args
if logger.V(1).Enabled() {
Expand Down Expand Up @@ -562,5 +564,9 @@ func timeoutMs(timeout int) time.Duration {
}

func printVersion(_ *cobra.Command, _ []string) {
fmt.Println("Authorino", version)
if dirty == "true" {
fmt.Printf("Authorino %s (%s-dirty)\n", version, gitSHA)
} else {
fmt.Printf("Authorino %s (%s)\n", version, gitSHA)
}
}

0 comments on commit 7d07f22

Please sign in to comment.