Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version commit hash #191

Merged
merged 29 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2dab094
added check dirty script
ehearneRedHat Jul 15, 2024
4e75e96
added target level vars .
ehearneRedHat Jul 15, 2024
523b2fc
added ldflag strings
ehearneRedHat Jul 15, 2024
9c3630c
added docker args
ehearneRedHat Jul 15, 2024
88c098d
added target level args + docker envs
ehearneRedHat Jul 18, 2024
5a3d19d
added build args to workflow
ehearneRedHat Jul 22, 2024
1a62830
remove unnecessary var
ehearneRedHat Jul 23, 2024
504aa0f
Merge branch 'main' into version-commit-hash
ehearneRedHat Jul 23, 2024
24e55c8
change commit to gitsha args + envs
ehearneRedHat Jul 29, 2024
650b73a
change commit target vars to gitsha target vars
ehearneRedHat Jul 29, 2024
613b189
change commit build args to gitsha build args
ehearneRedHat Jul 29, 2024
b335047
move version to separate file + commit change to gitsha
ehearneRedHat Jul 29, 2024
e5736c4
Merge branch 'version-commit-hash' of github.com:Kuadrant/dns-operato…
ehearneRedHat Jul 29, 2024
4b8832b
Merge branch 'main' into version-commit-hash
ehearneRedHat Jul 29, 2024
622abb9
added func printControllerMetaInfo()
ehearneRedHat Jul 29, 2024
4400824
new test tools for pkg/log/log_test.go
ehearneRedHat Jul 29, 2024
1f642d3
import new log go file + brought over dns-operator's log pkg
ehearneRedHat Jul 29, 2024
893de4f
add copy for new log pkg
ehearneRedHat Jul 29, 2024
22f2a57
added new changes to go.mod
ehearneRedHat Jul 29, 2024
35fc04b
add new line for import
ehearneRedHat Jul 29, 2024
704035e
move version to internal/version
ehearneRedHat Aug 9, 2024
fe5fa3a
version now copy in internal/
ehearneRedHat Aug 9, 2024
d348e42
revert logger config
ehearneRedHat Aug 9, 2024
075768f
move printcontrollermetainfo() to below setuplogger
ehearneRedHat Aug 9, 2024
65bd458
remove copy pkg
ehearneRedHat Aug 9, 2024
ef9ad74
fix from casing issue
ehearneRedHat Aug 9, 2024
9c4ef60
Merge branch 'main' into version-commit-hash
ehearneRedHat Aug 9, 2024
c0cb348
add build info string to controllermetainfo
ehearneRedHat Aug 26, 2024
03cc372
Merge branch 'main' of github.com:Kuadrant/dns-operator into version-…
ehearneRedHat Aug 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/build-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ jobs:
image: ${{ env.OPERATOR_NAME }}
tags: ${{ env.IMG_TAGS }}
platforms: linux/amd64,linux/arm64
build-args: |
COMMIT=${{ github.sha }}
ehearneRedHat marked this conversation as resolved.
Show resolved Hide resolved
DIRTY=false

dockerfiles: |
./Dockerfile

Expand Down Expand Up @@ -92,6 +96,9 @@ jobs:
image: ${{ env.OPERATOR_NAME }}-bundle
tags: ${{ needs.build.outputs.build-tags }}
platforms: linux/amd64,linux/arm64
build-args: |
COMMIT=${{ github.sha }}
ehearneRedHat marked this conversation as resolved.
Show resolved Hide resolved
DIRTY=false
dockerfiles: |
./bundle.Dockerfile

Expand Down
9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ FROM golang:1.21 as builder
ARG TARGETOS
ARG TARGETARCH

ARG COMMIT
ARG DIRTY

ENV COMMIT=${COMMIT:-unknown}
ENV DIRTY=${DIRTY:-unknown}


WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
Expand All @@ -21,7 +28,7 @@ COPY internal/ internal/
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -ldflags "-X main.commit=${COMMIT} -X main.dirty=${DIRTY}" -a -o manager cmd/main.go
ehearneRedHat marked this conversation as resolved.
Show resolved Hide resolved

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,25 @@ local-deploy-namespaced: docker-build kind-load-image ## Deploy the dns operator
##@ Build

.PHONY: build
build: COMMIT=$(shell git rev-parse HEAD || echo "unknown")
build: DIRTY=$(shell hack/check-git-dirty.sh || echo "unknown")
build: manifests generate fmt vet ## Build manager binary.
go build -o bin/manager cmd/main.go
go build -ldflags "-X main.commit=${COMMIT} -X main.dirty=${DIRTY}" -o bin/manager cmd/main.go

.PHONY: run
run: COMMIT=$(shell git rev-parse HEAD || echo "unknown")
run: DIRTY=$(shell hack/check-git-dirty.sh || echo "unknown")
mikenairn marked this conversation as resolved.
Show resolved Hide resolved
run: manifests generate fmt vet ## Run a controller from your host.
go run ./cmd/main.go --zap-devel --provider inmemory,aws,google,azure
go run -ldflags "-X main.commit=${COMMIT} -X main.dirty=${DIRTY}" ./cmd/main.go --zap-devel --provider inmemory,aws,google,azure

# If you wish built the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
.PHONY: docker-build
docker-build: COMMIT=$(shell git rev-parse HEAD || echo "unknown")
docker-build: DIRTY=$(shell hack/check-git-dirty.sh || echo "unknown")
docker-build: ## Build docker image with the manager.
$(CONTAINER_TOOL) build -t ${IMG} .
$(CONTAINER_TOOL) build -t ${IMG} . --build-arg COMMIT=$(COMMIT) --build-arg DIRTY=$(DIRTY)

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
Expand Down
13 changes: 13 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ import (
var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
version = "0.4.0-dev" // Change as versions are released
eguzki marked this conversation as resolved.
Show resolved Hide resolved
commit string // pass ldflag here to display commit hash
dirty string // must be string as passed in by ldflag to determine display .
)

const (
Expand Down Expand Up @@ -129,6 +132,16 @@ func main() {
providers = defaultProviders
}

// Display version here.

dnsInfoDisplay := fmt.Sprintf("dns-operator %s (%s-dirty)", version, commit)
ehearneRedHat marked this conversation as resolved.
Show resolved Hide resolved

if dirty == "false" {
dnsInfoDisplay = fmt.Sprintf("dns-operator %s (%s)", version, commit)
}

setupLog.Info(dnsInfoDisplay)

setupLog.Info("init provider factory", "providers", providers)
providerFactory, err := provider.NewFactory(mgr.GetClient(), providers)
if err != nil {
Expand Down
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
Loading