From d79b2fd4a8b17eb4fdaa9df92cd8e6d42084c453 Mon Sep 17 00:00:00 2001 From: ehearneredhat Date: Tue, 2 Jul 2024 12:59:02 +0100 Subject: [PATCH 01/11] added display version, hash and dirty in logs --- Dockerfile | 9 ++++++++- Makefile | 30 +++++++++++++++++++++++------- main.go | 4 ++++ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 541c670a..98f215eb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,14 @@ COPY controllers/ controllers/ COPY pkg/ pkg/ # Build -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go +ARG VERSION +ARG COMMIT +ARG DIRTY + +ENV VERSION=${VERSION:-unknown} +ENV COMMIT=${COMMIT:-unknown} +ENV DIRTY=${DIRTY:-unknown} +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.dirty=${DIRTY}" -o manager main.go # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details diff --git a/Makefile b/Makefile index f40030c7..9f396341 100644 --- a/Makefile +++ b/Makefile @@ -6,13 +6,29 @@ SHELL = /usr/bin/env bash -o pipefail MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) PROJECT_PATH := $(patsubst %/,%,$(dir $(MKFILE_PATH))) -# VERSION defines the project version for the bundle. -# Update this value when you upgrade the version of your project. -# To re-generate a bundle for another specific version without changing the standard setup, you can: -# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2) -# - use environment variables to overwrite this value (e.g export VERSION=0.0.2) +# Check for dirty. +define check_dirty + GIT_SHA=$$(git rev-parse HEAD) || { \ + GIT_HASH=$${GIT_SHA:-NO_SHA}; \ + }; \ + if [ -z "$$GIT_HASH" ]; then \ + GIT_DIRTY=$$(git diff --stat); \ + if [ -n "$$GIT_DIRTY" ]; then \ + DIRTY="true"; \ + else \ + DIRTY="false"; \ + fi; \ + fi; \ + echo $$DIRTY +endef + VERSION ?= 0.0.0 +# ldflag variables +VERSION_LIMITADOR_OPERATOR=0.10.0-dev # change this when version increases +COMMIT=$(shell git rev-parse HEAD) +DIRTY=$(shell $(check_dirty)) + # CHANNELS define the bundle channels used in the bundle. # Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable") # To re-generate a bundle for other specific channels without changing the standard setup, you can: @@ -269,7 +285,7 @@ test-unit: clean-cov generate fmt vet ## Run Unit tests. ##@ Build build: generate fmt vet ## Build manager binary. - go build -o bin/manager main.go + go build -ldflags "-X main.version=${VERSION_LIMITADOR_OPERATOR} -X main.commit=${COMMIT} -X main.dirty=${DIRTY}" -o bin/manager main.go run: export LOG_LEVEL = debug run: export LOG_MODE = development @@ -277,7 +293,7 @@ run: manifests generate fmt vet ## Run a controller from your host. go run ./main.go docker-build: ## Build docker image with the manager. - docker build -t $(IMG) . + docker build --build-arg VERSION=$(VERSION_LIMITADOR_OPERATOR) --build-arg COMMIT=$(COMMIT) --build-arg DIRTY=$(DIRTY) -t $(IMG) . docker-push: ## Push docker image with the manager. docker push $(IMG) diff --git a/main.go b/main.go index 7c8a9c66..6dc1d0ea 100644 --- a/main.go +++ b/main.go @@ -45,6 +45,9 @@ var ( scheme = k8sruntime.NewScheme() logLevel = env.GetString("LOG_LEVEL", "info") logMode = env.GetString("LOG_MODE", "production") + version string + commit string + dirty string ) func init() { @@ -67,6 +70,7 @@ func printControllerMetaInfo() { setupLog.Info(fmt.Sprintf("go version: %s", runtime.Version())) setupLog.Info(fmt.Sprintf("go os/arch: %s/%s", runtime.GOOS, runtime.GOARCH)) setupLog.Info("base logger", "log level", logLevel, "log mode", logMode) + setupLog.Info("booting up limitador-operator", "version", version, "commit", commit, "dirty", dirty) } func main() { From bab591c7f7450ad8332565057122e4fde9eeb2bf Mon Sep 17 00:00:00 2001 From: ehearneredhat Date: Thu, 4 Jul 2024 10:42:51 +0100 Subject: [PATCH 02/11] moved version to version/version.go --- Dockerfile | 5 ++--- Makefile | 5 ++--- main.go | 6 ++++-- version/version.go | 21 +++++++++++++++++++++ 4 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 version/version.go diff --git a/Dockerfile b/Dockerfile index 98f215eb..222dbc9a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,16 +14,15 @@ COPY main.go main.go COPY api/ api/ COPY controllers/ controllers/ COPY pkg/ pkg/ +COPY version/ version/ # Build -ARG VERSION ARG COMMIT ARG DIRTY -ENV VERSION=${VERSION:-unknown} ENV COMMIT=${COMMIT:-unknown} ENV DIRTY=${DIRTY:-unknown} -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.dirty=${DIRTY}" -o manager main.go +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "-X main.commit=${COMMIT} -X main.dirty=${DIRTY}" -o manager main.go # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details diff --git a/Makefile b/Makefile index 9f396341..f95b692d 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,6 @@ endef VERSION ?= 0.0.0 # ldflag variables -VERSION_LIMITADOR_OPERATOR=0.10.0-dev # change this when version increases COMMIT=$(shell git rev-parse HEAD) DIRTY=$(shell $(check_dirty)) @@ -285,7 +284,7 @@ test-unit: clean-cov generate fmt vet ## Run Unit tests. ##@ Build build: generate fmt vet ## Build manager binary. - go build -ldflags "-X main.version=${VERSION_LIMITADOR_OPERATOR} -X main.commit=${COMMIT} -X main.dirty=${DIRTY}" -o bin/manager main.go + go build -ldflags "-X main.commit=${COMMIT} -X main.dirty=${DIRTY}" -o bin/manager main.go run: export LOG_LEVEL = debug run: export LOG_MODE = development @@ -293,7 +292,7 @@ run: manifests generate fmt vet ## Run a controller from your host. go run ./main.go docker-build: ## Build docker image with the manager. - docker build --build-arg VERSION=$(VERSION_LIMITADOR_OPERATOR) --build-arg COMMIT=$(COMMIT) --build-arg DIRTY=$(DIRTY) -t $(IMG) . + docker build --build-arg COMMIT=$(COMMIT) --build-arg DIRTY=$(DIRTY) -t $(IMG) . docker-push: ## Push docker image with the manager. docker push $(IMG) diff --git a/main.go b/main.go index 6dc1d0ea..1ad71b8a 100644 --- a/main.go +++ b/main.go @@ -38,14 +38,16 @@ import ( "github.com/kuadrant/limitador-operator/controllers" "github.com/kuadrant/limitador-operator/pkg/log" "github.com/kuadrant/limitador-operator/pkg/reconcilers" + //+kubebuilder:scaffold:imports + // import version + "github.com/kuadrant/limitador-operator/version" ) var ( scheme = k8sruntime.NewScheme() logLevel = env.GetString("LOG_LEVEL", "info") logMode = env.GetString("LOG_MODE", "production") - version string commit string dirty string ) @@ -70,7 +72,7 @@ func printControllerMetaInfo() { setupLog.Info(fmt.Sprintf("go version: %s", runtime.Version())) setupLog.Info(fmt.Sprintf("go os/arch: %s/%s", runtime.GOOS, runtime.GOARCH)) setupLog.Info("base logger", "log level", logLevel, "log mode", logMode) - setupLog.Info("booting up limitador-operator", "version", version, "commit", commit, "dirty", dirty) + setupLog.Info("booting up limitador-operator", "version", version.Version, "commit", commit, "dirty", dirty) } func main() { diff --git a/version/version.go b/version/version.go new file mode 100644 index 00000000..9c9d4f0b --- /dev/null +++ b/version/version.go @@ -0,0 +1,21 @@ +/* +Copyright 2021 Red Hat, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package version + +var ( + // This variable is dependent on what the current release is e.g. if it is v0.10.0 then this variable, outside of releases, will be v0.10.1-dev . + Version = "0.10.0-dev" +) From 8011be6cd4ea573814c0d4c2d0e36cc4c3882789 Mon Sep 17 00:00:00 2001 From: ehearneredhat Date: Thu, 4 Jul 2024 11:02:04 +0100 Subject: [PATCH 03/11] removed info message --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 1ad71b8a..efd0e454 100644 --- a/main.go +++ b/main.go @@ -72,7 +72,7 @@ func printControllerMetaInfo() { setupLog.Info(fmt.Sprintf("go version: %s", runtime.Version())) setupLog.Info(fmt.Sprintf("go os/arch: %s/%s", runtime.GOOS, runtime.GOARCH)) setupLog.Info("base logger", "log level", logLevel, "log mode", logMode) - setupLog.Info("booting up limitador-operator", "version", version.Version, "commit", commit, "dirty", dirty) + setupLog.Info("", "version", version.Version, "commit", commit, "dirty", dirty) } func main() { From 616d8320b7da38c1822d42319cd96471eb5c4cdd Mon Sep 17 00:00:00 2001 From: ehearneredhat Date: Thu, 4 Jul 2024 11:21:05 +0100 Subject: [PATCH 04/11] brought commit and dirty variables to target level --- Makefile | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index f95b692d..5b9c2aa4 100644 --- a/Makefile +++ b/Makefile @@ -24,10 +24,6 @@ endef VERSION ?= 0.0.0 -# ldflag variables -COMMIT=$(shell git rev-parse HEAD) -DIRTY=$(shell $(check_dirty)) - # CHANNELS define the bundle channels used in the bundle. # Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable") # To re-generate a bundle for other specific channels without changing the standard setup, you can: @@ -282,15 +278,20 @@ test-unit: clean-cov generate fmt vet ## Run Unit tests. go test $(UNIT_DIRS) -coverprofile $(PROJECT_PATH)/coverage/unit/cover.out -v -timeout 0 $(TEST_PATTERN) ##@ Build - +build: COMMIT=$(shell git rev-parse HEAD) +build: DIRTY=$(shell $(check_dirty)) build: generate fmt vet ## Build manager binary. - go build -ldflags "-X main.commit=${COMMIT} -X main.dirty=${DIRTY}" -o bin/manager main.go + go build -ldflags "-X main.commit=${COMMIT} -X main.dirty=${DIRTY}" -o bin/manager main.go run: export LOG_LEVEL = debug run: export LOG_MODE = development -run: manifests generate fmt vet ## Run a controller from your host. - go run ./main.go +run: COMMIT=$(shell git rev-parse HEAD) +run: DIRTY=$(shell $(check_dirty)) +run: manifests generate fmt vet ## Run a controller from your host.) + go run -ldflags "-X main.commit=${COMMIT} -X main.dirty=${DIRTY}" ./main.go +docker-build: COMMIT=$(shell git rev-parse HEAD) +docker-build: DIRTY=$(shell $(check_dirty)) docker-build: ## Build docker image with the manager. docker build --build-arg COMMIT=$(COMMIT) --build-arg DIRTY=$(DIRTY) -t $(IMG) . From 6fce58cf2dd81187caf245f506ecea6710354b5d Mon Sep 17 00:00:00 2001 From: ehearneredhat Date: Thu, 4 Jul 2024 11:41:56 +0100 Subject: [PATCH 05/11] changed commit to gitSHA --- Dockerfile | 6 +++--- Makefile | 12 ++++++------ main.go | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 222dbc9a..e03b52fe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,12 +17,12 @@ COPY pkg/ pkg/ COPY version/ version/ # Build -ARG COMMIT +ARG GIT_SHA ARG DIRTY -ENV COMMIT=${COMMIT:-unknown} +ENV GIT_SHA=${GIT_SHA:-unknown} ENV DIRTY=${DIRTY:-unknown} -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "-X main.commit=${COMMIT} -X main.dirty=${DIRTY}" -o manager main.go +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "-X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" -o manager main.go # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details diff --git a/Makefile b/Makefile index 5b9c2aa4..7d6a0724 100644 --- a/Makefile +++ b/Makefile @@ -278,22 +278,22 @@ test-unit: clean-cov generate fmt vet ## Run Unit tests. go test $(UNIT_DIRS) -coverprofile $(PROJECT_PATH)/coverage/unit/cover.out -v -timeout 0 $(TEST_PATTERN) ##@ Build -build: COMMIT=$(shell git rev-parse HEAD) +build: GIT_SHA=$(shell git rev-parse HEAD) build: DIRTY=$(shell $(check_dirty)) build: generate fmt vet ## Build manager binary. - go build -ldflags "-X main.commit=${COMMIT} -X main.dirty=${DIRTY}" -o bin/manager main.go + go build -ldflags "-X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" -o bin/manager main.go run: export LOG_LEVEL = debug run: export LOG_MODE = development -run: COMMIT=$(shell git rev-parse HEAD) +run: GIT_SHA=$(shell git rev-parse HEAD) run: DIRTY=$(shell $(check_dirty)) run: manifests generate fmt vet ## Run a controller from your host.) - go run -ldflags "-X main.commit=${COMMIT} -X main.dirty=${DIRTY}" ./main.go + go run -ldflags "-X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" ./main.go -docker-build: COMMIT=$(shell git rev-parse HEAD) +docker-build: GIT_SHA=$(shell git rev-parse HEAD) docker-build: DIRTY=$(shell $(check_dirty)) docker-build: ## Build docker image with the manager. - docker build --build-arg COMMIT=$(COMMIT) --build-arg DIRTY=$(DIRTY) -t $(IMG) . + docker build --build-arg GIT_SHA=$(GIT_SHA) --build-arg DIRTY=$(DIRTY) -t $(IMG) . docker-push: ## Push docker image with the manager. docker push $(IMG) diff --git a/main.go b/main.go index efd0e454..fabb1f94 100644 --- a/main.go +++ b/main.go @@ -48,7 +48,7 @@ var ( scheme = k8sruntime.NewScheme() logLevel = env.GetString("LOG_LEVEL", "info") logMode = env.GetString("LOG_MODE", "production") - commit string + gitSHA string dirty string ) @@ -72,7 +72,7 @@ func printControllerMetaInfo() { setupLog.Info(fmt.Sprintf("go version: %s", runtime.Version())) setupLog.Info(fmt.Sprintf("go os/arch: %s/%s", runtime.GOOS, runtime.GOARCH)) setupLog.Info("base logger", "log level", logLevel, "log mode", logMode) - setupLog.Info("", "version", version.Version, "commit", commit, "dirty", dirty) + setupLog.Info("", "version", version.Version, "commit", gitSHA, "dirty", dirty) } func main() { From 7272f9f1d00c813ed4379b8b47d0086044f1a63c Mon Sep 17 00:00:00 2001 From: ehearneredhat Date: Thu, 4 Jul 2024 12:26:51 +0100 Subject: [PATCH 06/11] added unknown feature to gitsha and dirty --- Makefile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 7d6a0724..3610a401 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,8 @@ define check_dirty else \ DIRTY="false"; \ fi; \ + else \ + DIRTY="unknown"; \ fi; \ echo $$DIRTY endef @@ -278,20 +280,20 @@ test-unit: clean-cov generate fmt vet ## Run Unit tests. go test $(UNIT_DIRS) -coverprofile $(PROJECT_PATH)/coverage/unit/cover.out -v -timeout 0 $(TEST_PATTERN) ##@ Build -build: GIT_SHA=$(shell git rev-parse HEAD) -build: DIRTY=$(shell $(check_dirty)) +build: GIT_SHA=$(shell git rev-parse HEAD || echo "unknown") +build: DIRTY=$(shell $(check_dirty) || echo "unknown") build: generate fmt vet ## Build manager binary. go build -ldflags "-X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" -o bin/manager main.go run: export LOG_LEVEL = debug run: export LOG_MODE = development -run: GIT_SHA=$(shell git rev-parse HEAD) -run: DIRTY=$(shell $(check_dirty)) +run: GIT_SHA=$(shell git rev-parse HEAD || echo "unknown") +run: DIRTY=$(shell $(check_dirty) || echo "unknown") run: manifests generate fmt vet ## Run a controller from your host.) go run -ldflags "-X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" ./main.go -docker-build: GIT_SHA=$(shell git rev-parse HEAD) -docker-build: DIRTY=$(shell $(check_dirty)) +docker-build: GIT_SHA=$(shell git rev-parse HEAD || echo "unknown") +docker-build: DIRTY=$(shell $(check_dirty) || echo "unknown") docker-build: ## Build docker image with the manager. docker build --build-arg GIT_SHA=$(GIT_SHA) --build-arg DIRTY=$(DIRTY) -t $(IMG) . From 649c32394ff609ea66561b2ca065c2c380bd8bad Mon Sep 17 00:00:00 2001 From: ehearneredhat Date: Mon, 8 Jul 2024 09:01:16 +0100 Subject: [PATCH 07/11] added docker args --- .github/workflows/build-images-base.yaml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.github/workflows/build-images-base.yaml b/.github/workflows/build-images-base.yaml index 8e2d9909..21db61bb 100644 --- a/.github/workflows/build-images-base.yaml +++ b/.github/workflows/build-images-base.yaml @@ -65,6 +65,25 @@ jobs: run: | sudo apt-get update sudo apt-get install -y qemu-user-static + - name: Set build arguments + run: | + GIT_SHA=$(git rev-parse HEAD) + GIT_SHA=$$(git rev-parse HEAD) || { \ + GIT_HASH=$${GIT_SHA:-NO_SHA}; \ + }; \ + if [ -z "$$GIT_HASH" ]; then \ + GIT_DIRTY=$$(git diff --stat); \ + if [ -n "$$GIT_DIRTY" ]; then \ + DIRTY="true"; \ + else \ + DIRTY="false"; \ + fi; \ + else \ + DIRTY="unknown"; \ + fi; \ + + echo "GIT_SHA=${GIT_SHA}" >> $GITHUB_ENV + echo "DIRTY=${DIRTY}" >> $GITHUB_ENV - name: Build Image id: build-image uses: redhat-actions/buildah-build@v2 @@ -74,6 +93,9 @@ jobs: platforms: linux/amd64,linux/arm64 dockerfiles: | ./Dockerfile + build-args: | + GIT_SHA=${{ env.GIT_SHA }} + DIRTY=${{ env.DIRTY }} - name: Push Image if: ${{ !env.ACT }} id: push-to-quay From 4ef06f6ccfb3541c0dceef1568fbf69bb84182ac Mon Sep 17 00:00:00 2001 From: ehearneredhat Date: Mon, 8 Jul 2024 13:27:30 +0100 Subject: [PATCH 08/11] implement eguzki script --- Makefile | 24 +++--------------------- utils/check-git-dirty.sh | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 21 deletions(-) create mode 100755 utils/check-git-dirty.sh diff --git a/Makefile b/Makefile index 3610a401..c9d4efd7 100644 --- a/Makefile +++ b/Makefile @@ -6,24 +6,6 @@ SHELL = /usr/bin/env bash -o pipefail MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) PROJECT_PATH := $(patsubst %/,%,$(dir $(MKFILE_PATH))) -# Check for dirty. -define check_dirty - GIT_SHA=$$(git rev-parse HEAD) || { \ - GIT_HASH=$${GIT_SHA:-NO_SHA}; \ - }; \ - if [ -z "$$GIT_HASH" ]; then \ - GIT_DIRTY=$$(git diff --stat); \ - if [ -n "$$GIT_DIRTY" ]; then \ - DIRTY="true"; \ - else \ - DIRTY="false"; \ - fi; \ - else \ - DIRTY="unknown"; \ - fi; \ - echo $$DIRTY -endef - VERSION ?= 0.0.0 # CHANNELS define the bundle channels used in the bundle. @@ -281,19 +263,19 @@ test-unit: clean-cov generate fmt vet ## Run Unit tests. ##@ Build build: GIT_SHA=$(shell git rev-parse HEAD || echo "unknown") -build: DIRTY=$(shell $(check_dirty) || echo "unknown") +build: DIRTY=$(shell $(PROJECT_PATH)/utils/check-git-dirty.sh || echo "unknown") build: generate fmt vet ## Build manager binary. go build -ldflags "-X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" -o bin/manager main.go run: export LOG_LEVEL = debug run: export LOG_MODE = development run: GIT_SHA=$(shell git rev-parse HEAD || echo "unknown") -run: DIRTY=$(shell $(check_dirty) || echo "unknown") +run: DIRTY=$(shell $(PROJECT_PATH)/utils/check-git-dirty.sh || echo "unknown") run: manifests generate fmt vet ## Run a controller from your host.) go run -ldflags "-X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" ./main.go docker-build: GIT_SHA=$(shell git rev-parse HEAD || echo "unknown") -docker-build: DIRTY=$(shell $(check_dirty) || echo "unknown") +docker-build: DIRTY=$(shell $(PROJECT_PATH)/utils/check-git-dirty.sh || echo "unknown") docker-build: ## Build docker image with the manager. docker build --build-arg GIT_SHA=$(GIT_SHA) --build-arg DIRTY=$(DIRTY) -t $(IMG) . diff --git a/utils/check-git-dirty.sh b/utils/check-git-dirty.sh new file mode 100755 index 00000000..8f0687f1 --- /dev/null +++ b/utils/check-git-dirty.sh @@ -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 \ No newline at end of file From 637079b52701012b5bf1ea70fe22226f31f4ea83 Mon Sep 17 00:00:00 2001 From: Evan Hearne <156197717+ehearneRedHat@users.noreply.github.com> Date: Mon, 8 Jul 2024 14:13:54 +0100 Subject: [PATCH 09/11] change git sha env to github sha Co-authored-by: Eguzki Astiz Lezaun --- .github/workflows/build-images-base.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-images-base.yaml b/.github/workflows/build-images-base.yaml index 21db61bb..1921138d 100644 --- a/.github/workflows/build-images-base.yaml +++ b/.github/workflows/build-images-base.yaml @@ -94,7 +94,7 @@ jobs: dockerfiles: | ./Dockerfile build-args: | - GIT_SHA=${{ env.GIT_SHA }} + GIT_SHA=${{ github.sha }} DIRTY=${{ env.DIRTY }} - name: Push Image if: ${{ !env.ACT }} From 4a2ec6a342f45139d5324fc7322f941c728d66fc Mon Sep 17 00:00:00 2001 From: ehearneredhat Date: Mon, 8 Jul 2024 14:15:59 +0100 Subject: [PATCH 10/11] remove set build args and set dirty to static false --- .github/workflows/build-images-base.yaml | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/.github/workflows/build-images-base.yaml b/.github/workflows/build-images-base.yaml index 1921138d..cf1f2208 100644 --- a/.github/workflows/build-images-base.yaml +++ b/.github/workflows/build-images-base.yaml @@ -65,25 +65,6 @@ jobs: run: | sudo apt-get update sudo apt-get install -y qemu-user-static - - name: Set build arguments - run: | - GIT_SHA=$(git rev-parse HEAD) - GIT_SHA=$$(git rev-parse HEAD) || { \ - GIT_HASH=$${GIT_SHA:-NO_SHA}; \ - }; \ - if [ -z "$$GIT_HASH" ]; then \ - GIT_DIRTY=$$(git diff --stat); \ - if [ -n "$$GIT_DIRTY" ]; then \ - DIRTY="true"; \ - else \ - DIRTY="false"; \ - fi; \ - else \ - DIRTY="unknown"; \ - fi; \ - - echo "GIT_SHA=${GIT_SHA}" >> $GITHUB_ENV - echo "DIRTY=${DIRTY}" >> $GITHUB_ENV - name: Build Image id: build-image uses: redhat-actions/buildah-build@v2 @@ -95,7 +76,7 @@ jobs: ./Dockerfile build-args: | GIT_SHA=${{ github.sha }} - DIRTY=${{ env.DIRTY }} + DIRTY="false" - name: Push Image if: ${{ !env.ACT }} id: push-to-quay From 3eb7709228b5b5c1227a576664d234be17ad7a67 Mon Sep 17 00:00:00 2001 From: ehearneredhat Date: Mon, 8 Jul 2024 14:30:25 +0100 Subject: [PATCH 11/11] test --- .github/workflows/build-images-base.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-images-base.yaml b/.github/workflows/build-images-base.yaml index cf1f2208..75eab485 100644 --- a/.github/workflows/build-images-base.yaml +++ b/.github/workflows/build-images-base.yaml @@ -76,7 +76,7 @@ jobs: ./Dockerfile build-args: | GIT_SHA=${{ github.sha }} - DIRTY="false" + DIRTY=false - name: Push Image if: ${{ !env.ACT }} id: push-to-quay