Skip to content

Commit

Permalink
Merge pull request #209 from Kuadrant/version-commit-hash
Browse files Browse the repository at this point in the history
version commit hash
  • Loading branch information
eguzki authored Sep 17, 2024
2 parents 012ee63 + a3ab60a commit 66c85ed
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ jobs:
platforms: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le
build-args: |
VERSION=${{ env.VERSION }}
GIT_SHA=${{ github.sha }}
DIRTY=false
DEFAULT_AUTHORINO_IMAGE=${{ env.DEFAULT_AUTHORINO_IMAGE }}
containerfiles: |
./Dockerfile
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*.dylib
bin
testbin/*
/authorino-operator

# Test binary, build with `go test -c`
*.test
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ COPY pkg/ pkg/

ARG VERSION=latest
ARG DEFAULT_AUTHORINO_IMAGE=quay.io/kuadrant/authorino:latest
RUN CGO_ENABLED=0 GO111MODULE=on go build -a -ldflags "-X main.version=${VERSION} -X github.com/kuadrant/authorino-operator/controllers.DefaultAuthorinoImage=${DEFAULT_AUTHORINO_IMAGE}" -o manager main.go
ARG GIT_SHA=unknown
ARG 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} -X github.com/kuadrant/authorino-operator/controllers.DefaultAuthorinoImage=${DEFAULT_AUTHORINO_IMAGE}" -o manager main.go

# Use Red Hat minimal base image to package the binary
# https://catalog.redhat.com/software/containers/ubi9-minimal
Expand Down
18 changes: 12 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,20 @@ test: manifests generate fmt vet setup-envtest ## Run the tests.

##@ Build

build: GIT_SHA=$(shell git rev-parse HEAD || echo "unknown")
build: DIRTY=$(shell $(PROJECT_DIR)/utils/check-git-dirty.sh || echo "unknown")
build: generate fmt vet ## Build manager binary.
go build -ldflags "-X main.version=$(VERSION) -X github.com/kuadrant/authorino-operator/controllers.DefaultAuthorinoImage=$(ACTUAL_DEFAULT_AUTHORINO_IMAGE)" -o bin/manager main.go
go build -ldflags "-X main.version=$(VERSION) -X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY} -X github.com/kuadrant/authorino-operator/controllers.DefaultAuthorinoImage=$(ACTUAL_DEFAULT_AUTHORINO_IMAGE)" -o bin/manager main.go

run: GIT_SHA=$(shell git rev-parse HEAD || echo "unknown")
run: DIRTY=$(shell $(PROJECT_DIR)/utils/check-git-dirty.sh || echo "unknown")
run: manifests generate fmt vet ## Run a controller from your host.
go run -ldflags "-X main.version=$(VERSION) -X github.com/kuadrant/authorino-operator/controllers.DefaultAuthorinoImage=$(ACTUAL_DEFAULT_AUTHORINO_IMAGE)" ./main.go
go run -ldflags "-X main.version=$(VERSION) -X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY} -X github.com/kuadrant/authorino-operator/controllers.DefaultAuthorinoImage=$(ACTUAL_DEFAULT_AUTHORINO_IMAGE)" ./main.go

docker-build: GIT_SHA=$(shell git rev-parse HEAD || echo "unknown")
docker-build: DIRTY=$(shell $(PROJECT_DIR)/utils/check-git-dirty.sh || echo "unknown")
docker-build: ## Build docker image with the manager.
docker build --build-arg VERSION=$(VERSION) --build-arg ACTUAL_DEFAULT_AUTHORINO_IMAGE=$(ACTUAL_DEFAULT_AUTHORINO_IMAGE) -t $(OPERATOR_IMAGE) .
docker build --build-arg VERSION=$(VERSION) --build-arg GIT_SHA=$(GIT_SHA) --build-arg DIRTY=$(DIRTY) --build-arg ACTUAL_DEFAULT_AUTHORINO_IMAGE=$(ACTUAL_DEFAULT_AUTHORINO_IMAGE) -t $(OPERATOR_IMAGE) .

docker-push: ## Push docker image with the manager.
docker push ${OPERATOR_IMAGE}
Expand All @@ -245,10 +251,10 @@ install-operator: manifests kustomize ## Install CRDs into the K8s cluster speci
uninstall-operator: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
kubectl delete -f $(OPERATOR_MANIFESTS) --ignore-not-found

install-authorino: create-namespace install-cert-manager ## install RBAC and CRD for authorino
install-authorino: $(KUSTOMIZE) create-namespace install-cert-manager ## install RBAC and CRD for authorino
$(KUSTOMIZE) build config/authorino | kubectl apply -f -

uninstall-authorino: ## uninstall RBAC and CRD for authorino
uninstall-authorino: $(KUSTOMIZE) ## uninstall RBAC and CRD for authorino
$(KUSTOMIZE) build config/authorino | kubectl delete -f - --ignore-not-found

install-cert-manager: ## install the cert manager need for the web hooks
Expand All @@ -267,7 +273,7 @@ delete-namespace:
DEPLOYMENT_DIR = $(PROJECT_DIR)/config/deploy
DEPLOYMENT_FILE = $(DEPLOYMENT_DIR)/manifests.yaml
.PHONY: deploy-manifest
deploy-manifest:
deploy-manifest: $(KUSTOMIZE)
mkdir -p $(DEPLOYMENT_DIR)
cd $(PROJECT_DIR)/config/manager && $(KUSTOMIZE) edit set image controller=$(OPERATOR_IMAGE) ;\
cd $(PROJECT_DIR) && $(KUSTOMIZE) build config/deploy > $(DEPLOYMENT_FILE)
Expand Down
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ var (
setupLog = ctrl.Log.WithName("setup")
logger log.Logger
version string // value injected in compilation-time
gitSHA string // value injected in compilation-time
dirty string // value injected in compilation-time
)

func init() {
Expand Down Expand Up @@ -89,7 +91,11 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

setupLog.Info("booting up authorino operator", "version", version, "default authorino image", controllers.DefaultAuthorinoImage)
setupLog.Info("booting up authorino operator",
"version", version,
"commit", gitSHA,
"dirty", dirty,
"default authorino image", controllers.DefaultAuthorinoImage)

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Expand Down
15 changes: 15 additions & 0 deletions utils/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

0 comments on commit 66c85ed

Please sign in to comment.