Skip to content

Commit

Permalink
Fix build information in logs (#842)
Browse files Browse the repository at this point in the history
* Fix build information in logs
* Add helper Make targets for cleaning docker images and go caches
  • Loading branch information
shreyas-s-rao authored Jul 25, 2024
1 parent c73cbf9 commit 8446c6d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .ci/build
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ GIT_SHA="${GIT_SHA:-$(git rev-parse --short HEAD || echo "GitNotFound")}"
CGO_ENABLED=0 GO111MODULE=on go build \
-v \
-o "${BINARY_PATH}"/etcd-druid \
-ldflags "-w -X ${REPOSITORY}/pkg/version.Version=${VERSION} -X ${REPOSITORY}/pkg/version.GitSHA=${GIT_SHA}" \
-ldflags "-w -X ${REPOSITORY}/internal/version.Version=${VERSION} -X ${REPOSITORY}/internal/version.GitSHA=${GIT_SHA}" \
main.go
32 changes: 25 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
#
# SPDX-License-Identifier: Apache-2.0

VERSION := $(shell cat VERSION)
REPO_ROOT := $(shell dirname "$(realpath $(lastword $(MAKEFILE_LIST)))")
HACK_DIR := $(REPO_ROOT)/hack
REGISTRY := europe-docker.pkg.dev/gardener-project/snapshots
IMAGE_REPOSITORY := $(REGISTRY)/gardener/etcd-druid
VERSION := $(shell $(HACK_DIR)/get-version.sh)
GIT_SHA := $(shell git rev-parse --short HEAD || echo "GitNotFound")
REGISTRY_ROOT := europe-docker.pkg.dev/gardener-project
REGISTRY := $(REGISTRY)/snapshots
IMAGE_NAME := gardener/etcd-druid
IMAGE_REPOSITORY := $(REGISTRY)/$(IMAGE_NAME)
IMAGE_BUILD_TAG := $(VERSION)
BUILD_DIR := build
PROVIDERS := ""
Expand Down Expand Up @@ -34,6 +37,11 @@ tidy:
clean:
@$(HACK_DIR)/clean.sh ./api/... ./internal/...

# Clean go mod cache
.PHONY: clean-mod-cache
clean-mod-cache:
@go clean -modcache

.PHONY: update-dependencies
update-dependencies:
@env GO111MODULE=on go get -u
Expand Down Expand Up @@ -112,6 +120,11 @@ test-cov-clean:
druid: fmt check
@env GO111MODULE=on go build -o bin/druid main.go

# Clean go build cache
.PHONY: clean-build-cache
clean-build-cache:
@go clean -cache

# Build the docker image
.PHONY: docker-build
docker-build:
Expand All @@ -124,6 +137,11 @@ docker-build:
docker-push:
docker push ${IMG}

# Clean up all docker images for etcd-druid
.PHONY: docker-clean
docker-clean:
docker images | grep -e "$(REGISTRY_ROOT)/.*/$(IMAGE_NAME)" | awk '{print $$3}' | xargs docker rmi -f

#####################################################################
# Rules for local environment #
#####################################################################
Expand Down Expand Up @@ -159,15 +177,15 @@ deploy-via-kustomize: manifests $(KUSTOMIZE)
# Modify the Helm template located at charts/druid/templates if any changes are required
.PHONY: deploy
deploy: $(SKAFFOLD) $(HELM)
$(SKAFFOLD) run -m etcd-druid
@VERSION=$(VERSION) GIT_SHA=$(GIT_SHA) $(SKAFFOLD) run -m etcd-druid

.PHONY: deploy-dev
deploy-dev: $(SKAFFOLD) $(HELM)
$(SKAFFOLD) dev --cleanup=false -m etcd-druid --trigger='manual'
@VERSION=$(VERSION) GIT_SHA=$(GIT_SHA) $(SKAFFOLD) dev --cleanup=false -m etcd-druid --trigger='manual'

.PHONY: deploy-debug
deploy-debug: $(SKAFFOLD) $(HELM)
$(SKAFFOLD) debug --cleanup=false -m etcd-druid
@VERSION=$(VERSION) GIT_SHA=$(GIT_SHA) $(SKAFFOLD) debug --cleanup=false -m etcd-druid

.PHONY: undeploy
undeploy: $(SKAFFOLD) $(HELM)
Expand All @@ -183,7 +201,7 @@ deploy-azurite: $(KUBECTL)

.PHONY: test-e2e
test-e2e: $(KUBECTL) $(HELM) $(SKAFFOLD) $(KUSTOMIZE)
@$(HACK_DIR)/e2e-test/run-e2e-test.sh $(PROVIDERS)
@VERSION=$(VERSION) GIT_SHA=$(GIT_SHA) $(HACK_DIR)/e2e-test/run-e2e-test.sh $(PROVIDERS)

.PHONY: ci-e2e-kind
ci-e2e-kind:
Expand Down
4 changes: 4 additions & 0 deletions skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ build:
- VERSION
flags:
- -v
ldflags:
- -w
- -X github.com/gardener/etcd-druid/internal/version.Version={{.VERSION}}
- -X github.com/gardener/etcd-druid/internal/version.GitSHA={{.GIT_SHA}}
deploy:
helm:
releases:
Expand Down

0 comments on commit 8446c6d

Please sign in to comment.