@@ -15,17 +15,6 @@ export GOOS=linux
1515# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
1616# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
1717VERSION ?= main
18- BUILD_DATE := $(shell date +% Y-% m-% d\ % H:% M)
19- TAG_COMMIT := $(shell git rev-list --abbrev-commit --tags --max-count=1)
20- TAG := $(shell git describe --abbrev=0 --tags ${TAG_COMMIT} 2>/dev/null || true)
21- BUILD_SHA := $(shell git rev-parse --short HEAD)
22- BUILD_VERSION := $(TAG:v%=% )
23- ifneq ($(COMMIT ) , $(TAG_COMMIT ) )
24- BUILD_VERSION := $(BUILD_VERSION)-$(BUILD_SHA)
25- endif
26- ifneq ($(shell git status --porcelain) ,)
27- BUILD_VERSION := $(BUILD_VERSION)-dirty
28- endif
2918
3019# Go architecture and targets images to build
3120GOARCH ?= amd64
@@ -39,13 +28,18 @@ IMAGE_TAG_BASE ?= quay.io/$(IMAGE_ORG)/flowlogs-pipeline
3928
4029# Image URL to use all building/pushing image targets
4130IMAGE ?= $(IMAGE_TAG_BASE ) :$(VERSION )
42- OCI_BUILD_OPTS ?=
4331
4432# Image building tool (docker / podman) - docker is preferred in CI
4533OCI_BIN_PATH = $(shell which docker 2>/dev/null || which podman)
4634OCI_BIN ?= $(shell basename ${OCI_BIN_PATH})
35+ OCI_BUILD_OPTS ?=
36+
37+ ifneq ($(CLEAN_BUILD ) ,)
38+ BUILD_DATE := $(shell date +%Y-%m-%d\ %H:%M)
39+ BUILD_SHA := $(shell git rev-parse --short HEAD)
40+ LDFLAGS ?= -X 'main.buildVersion=${VERSION}-${BUILD_SHA}' -X 'main.buildDate=${BUILD_DATE}'
41+ endif
4742
48- MIN_GO_VERSION := 1.20.0
4943FLP_BIN_FILE =flowlogs-pipeline
5044CG_BIN_FILE =confgenerator
5145NETFLOW_GENERATOR =nflow-generator
@@ -60,7 +54,7 @@ FORCE: ;
6054# build a single arch target provided as argument
6155define build_target
6256 echo 'building image for arch $(1 ) '; \
63- DOCKER_BUILDKIT=1 $(OCI_BIN ) buildx build --load --build-arg TARGETARCH=$(1 ) ${OCI_BUILD_OPTS} -t ${IMAGE}-$(1 ) -f contrib/docker/Dockerfile .;
57+ DOCKER_BUILDKIT=1 $(OCI_BIN ) buildx build --load --build-arg LDFLAGS="${LDFLAGS}" --build-arg TARGETARCH=$(1 ) ${OCI_BUILD_OPTS} -t ${IMAGE}-$(1 ) -f contrib/docker/Dockerfile .;
6458endef
6559
6660# push a single arch target image
@@ -97,25 +91,19 @@ vendors: ## Check go vendors
9791 @echo " ### Checking vendors"
9892 go mod tidy && go mod vendor
9993
100- .PHONY : validate_go
101- validate_go :
102- @current_ver=$$(go version | { read _ _ v _; echo $${v#go}; } ) ; \
103- required_ver=${MIN_GO_VERSION} ; min_ver=$$(echo -e "$$current_ver\n$$required_ver" | sort -V | head -n 1 ) ; \
104- if [[ $$ min_ver == $$ current_ver ]]; then echo -e " \n!!! golang version > $$ required_ver required !!!\n" ; exit 7; fi
105-
10694# #@ Develop
10795
108- .PHONY : validate_go lint
96+ .PHONY : lint
10997lint : $(GOLANGCI_LINT ) # # Lint the code
11098 $(GOLANGCI_LINT ) run ./... --timeout=3m
11199
112- .PHONY : build_code
113- build_code :
114- GOARCH=${GOARCH} go build -ldflags " -X 'main.BuildVersion= $( BUILD_VERSION ) ' -X 'main.BuildDate= $( BUILD_DATE ) ' " " ${CMD_DIR}${FLP_BIN_FILE} "
115- GOARCH=${GOARCH} go build -ldflags " -X 'main.BuildVersion= $( BUILD_VERSION ) ' -X 'main.BuildDate= $( BUILD_DATE ) ' " " ${CMD_DIR}${CG_BIN_FILE} "
100+ .PHONY : compile
101+ compile : # # Compile main flowlogs-pipeline and config generator
102+ GOARCH=${GOARCH} go build " ${CMD_DIR}${FLP_BIN_FILE} "
103+ GOARCH=${GOARCH} go build " ${CMD_DIR}${CG_BIN_FILE} "
116104
117105.PHONY : build
118- build : validate_go lint build_code docs # # Build flowlogs-pipeline executable and update the docs
106+ build : lint compile docs # # Build flowlogs-pipeline executable and update the docs
119107
120108.PHONY : docs
121109docs : FORCE # # Update flowlogs-pipeline documentation
@@ -131,7 +119,7 @@ clean: ## Clean
131119
132120TEST_OPTS := -race -coverpkg=./... -covermode=atomic -coverprofile cover.out
133121.PHONY : tests-unit
134- tests-unit : validate_go # # Unit tests
122+ tests-unit : # # Unit tests
135123 # tests may rely on non-thread safe libs such as go-ipfix => no -race flag
136124 go test $$(go list ./... | grep /testnorace )
137125 # enabling CGO is required for -race flag
@@ -152,15 +140,15 @@ tests-fast: TEST_OPTS=
152140tests-fast : tests-unit # # Fast unit tests (no race tests / coverage)
153141
154142.PHONY : tests-e2e
155- tests-e2e : validate_go $(KIND ) # # End-to-end tests
143+ tests-e2e : $(KIND ) # # End-to-end tests
156144 go test -p 1 -v -timeout 20m $$(go list ./... | grep /e2e )
157145
158146.PHONY : tests-all
159- tests-all : validate_go tests-unit tests-e2e # # All tests
147+ tests-all : tests-unit tests-e2e # # All tests
160148
161149# note: to review profile execute: go tool pprof -web /tmp/flowlogs-pipeline-cpu-profile.out (make sure graphviz is installed)
162150.PHONY : benchmarks
163- benchmarks : $(BENCHSTAT ) validate_go # # Benchmark
151+ benchmarks : $(BENCHSTAT ) # # Benchmark
164152 go test -bench=. ./cmd/flowlogs-pipeline -o=/tmp/flowlogs-pipeline.test \
165153 -cpuprofile /tmp/flowlogs-pipeline-cpu-profile.out \
166154 -run=^# -count=10 -parallel=1 -cpu=1 -benchtime=100x \
@@ -187,7 +175,7 @@ image-push: ## Push MULTIARCH_TARGETS images
187175.PHONY : manifest-build
188176manifest-build : # # Build MULTIARCH_TARGETS manifest
189177 @echo ' building manifest $(IMAGE)'
190- DOCKER_BUILDKIT=1 $(OCI_BIN ) rmi ${IMAGE} -f
178+ DOCKER_BUILDKIT=1 $(OCI_BIN ) rmi ${IMAGE} -f || true
191179 DOCKER_BUILDKIT=1 $(OCI_BIN ) manifest create ${IMAGE} $(foreach target,$(MULTIARCH_TARGETS ) , --amend ${IMAGE}-$(target ) ) ;
192180
193181.PHONY : manifest-push
0 commit comments