@@ -6,6 +6,11 @@ MANIFEST_DIR = $(shell pwd)/deploy/manifests
6
6
NJS_DIR = $(shell pwd) /internal/mode/static/nginx/modules/src
7
7
CHART_DIR = $(shell pwd) /deploy/helm-chart
8
8
9
+ # go build flags - should not be overridden by the user
10
+ GO_LINKER_FlAGS_VARS = -X main.version=${VERSION} -X main.commit=${GIT_COMMIT} -X main.date=${DATE}
11
+ GO_LINKER_FLAGS_OPTIMIZATIONS = -s -w
12
+ GO_LINKER_FLAGS = $(GO_LINKER_FLAGS_OPTIMIZATIONS ) $(GO_LINKER_FlAGS_VARS )
13
+
9
14
# variables that can be overridden by the user
10
15
PREFIX ?= nginx-kubernetes-gateway# # The name of the image. For example, nginx-kubernetes-gateway
11
16
TAG ?= $(VERSION:v%=% ) # # The tag of the image. For example, 0.3.0
@@ -31,7 +36,7 @@ container: build ## Build the container
31
36
build : # # Build the binary
32
37
ifeq (${TARGET},local)
33
38
@go version || (code=$$?; printf "\033[0;31mError\033[0m: unable to build locally\n"; exit $$code)
34
- CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) go build -trimpath -a -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${GIT_COMMIT} -X main.date=${DATE}" -o $(OUT_DIR)/gateway github.com/nginxinc/nginx-kubernetes-gateway/cmd/gateway
39
+ CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) go build -trimpath -a -ldflags "$(GO_LINKER_FLAGS)" $(ADDITIONAL_GO_BUILD_FLAGS) -o $(OUT_DIR)/gateway github.com/nginxinc/nginx-kubernetes-gateway/cmd/gateway
35
40
endif
36
41
37
42
.PHONY : build-goreleaser
@@ -89,6 +94,7 @@ unit-test: ## Run unit tests for the go code
89
94
go test ./... -race -coverprofile cover.out
90
95
go tool cover -html=cover.out -o cover.html
91
96
97
+ .PHONY : njs-unit-test
92
98
njs-unit-test : # # Run unit tests for the njs httpmatches module
93
99
docker run --rm -w /modules \
94
100
-v $(PWD ) /internal/mode/static/nginx/modules:/modules/ \
@@ -103,15 +109,13 @@ generate-njs-yaml: ## Generate the njs-modules ConfigMap
103
109
lint-helm : # # Run the helm chart linter
104
110
helm lint $(CHART_DIR )
105
111
106
- debug-build : # # Build binary with debug info, symbols, and no optimizations
107
- ifeq (${TARGET},local)
108
- @go version || (code=$$?; printf "\033[0;31mError\033[0m: unable to build locally\n"; exit $$code)
109
- CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) go build -trimpath -a -gcflags "all=-N -l" -ldflags "-X main.version=${VERSION} -X main.commit=${GIT_COMMIT} -X main.date=${DATE}" -o $(OUT_DIR)/gateway github.com/nginxinc/nginx-kubernetes-gateway/cmd/gateway
110
- endif
112
+ .PHONY : debug-build
113
+ debug-build : GO_LINKER_FLAGS=$(GO_LINKER_FlAGS_VARS )
114
+ debug-build : ADDITIONAL_GO_BUILD_FLAGS=-gcflags "all=-N -l"
115
+ debug-build : build # # Build binary with debug info, symbols, and no optimizations
111
116
112
- debug-container : debug-build # # Build container with debug binary
113
- @docker -v || (code=$$ ? ; printf " \033[0;31mError\033[0m: there was a problem with Docker\n" ; exit $$ code)
114
- docker build --platform linux/$(ARCH ) $(strip $(DOCKER_BUILD_OPTIONS ) ) --target $(strip $(TARGET ) ) -f build/Dockerfile -t $(strip $(PREFIX ) ) :$(strip $(TAG ) ) .
117
+ .PHONY : debug-container
118
+ debug-container : debug-build container # # Build container with debug binary
115
119
116
120
.PHONY : dev-all
117
121
dev-all : deps fmt njs-fmt vet lint unit-test njs-unit-test # # Run all the development checks
0 commit comments