Skip to content

Commit

Permalink
added cleaner dirty implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ehearneRedHat committed Jul 2, 2024
1 parent 5bbd1ec commit d002940
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ WORKDIR /usr/src/authorino
COPY ./ ./
ARG GIT_SHA
ENV GIT_SHA=${GIT_SHA:-unknown}
RUN CGO_ENABLED=0 GO111MODULE=on go build -a -ldflags "-X main.version=${GIT_SHA}" -o /usr/bin/authorino main.go
ARG DIRTY
ENV DIRTY=${DIRTY:-unknown}
RUN CGO_ENABLED=0 GO111MODULE=on go build -a -ldflags "-X main.version=${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
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ define check_dirty
if [ -z "$$GIT_HASH" ]; then \
GIT_DIRTY=$$(git diff --stat); \
if [ -n "$$GIT_DIRTY" ]; then \
GIT_HASH=$${GIT_SHA}-dirty; \
DIRTY="true"; \
else \
GIT_HASH=$${GIT_SHA}; \
DIRTY="false"; \
fi; \
fi; \
echo $$GIT_HASH
echo $$DIRTY
endef

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

# Authorino dirty
DIRTY = $(shell $(check_dirty))

# Use vi as default editor
EDITOR ?= vi
Expand Down Expand Up @@ -132,7 +135,7 @@ run: generate manifests ## Runs the application against the Kubernetes cluster c
go run -ldflags "-X main.version=$(VERSION)" ./main.go server

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.dirty=$(DIRTY)" -o bin/authorino main.go

IMAGE_REPO ?= authorino
using_semantic_version := $(shell [[ $(VERSION) =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.+)?$$ ]] && echo "true")
Expand All @@ -143,7 +146,7 @@ IMAGE_TAG=local
endif
AUTHORINO_IMAGE ?= $(IMAGE_REPO):$(IMAGE_TAG)
docker-build: ## Builds an image based on the current branch
docker build --build-arg GIT_SHA=$(VERSION) -t $(AUTHORINO_IMAGE) .
docker build --build-arg GIT_SHA=$(VERSION) --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
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const (
var (
// ldflags
version string
dirty string

scheme = runtime.NewScheme()
logger logr.Logger
Expand Down Expand Up @@ -373,7 +374,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("booting up authorino", "version", version, "cmd", cmd.Use, "dirty", dirty)

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

func printVersion(_ *cobra.Command, _ []string) {
fmt.Println("Authorino", version)
if dirty == "true" {
fmt.Println("Authorino", version, "(dirty)")
} else {
fmt.Println("Authorino", version)
}
}

0 comments on commit d002940

Please sign in to comment.