Skip to content

Commit bdbc2cf

Browse files
author
Kate Osborn
committed
Resuse existing build and container targets
1 parent 779c3a3 commit bdbc2cf

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

Makefile

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ MANIFEST_DIR = $(shell pwd)/deploy/manifests
66
NJS_DIR = $(shell pwd)/internal/mode/static/nginx/modules/src
77
CHART_DIR = $(shell pwd)/deploy/helm-chart
88

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+
914
# variables that can be overridden by the user
1015
PREFIX ?= nginx-kubernetes-gateway## The name of the image. For example, nginx-kubernetes-gateway
1116
TAG ?= $(VERSION:v%=%)## The tag of the image. For example, 0.3.0
@@ -31,7 +36,7 @@ container: build ## Build the container
3136
build: ## Build the binary
3237
ifeq (${TARGET},local)
3338
@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
3540
endif
3641

3742
.PHONY: build-goreleaser
@@ -89,6 +94,7 @@ unit-test: ## Run unit tests for the go code
8994
go test ./... -race -coverprofile cover.out
9095
go tool cover -html=cover.out -o cover.html
9196

97+
.PHONY: njs-unit-test
9298
njs-unit-test: ## Run unit tests for the njs httpmatches module
9399
docker run --rm -w /modules \
94100
-v $(PWD)/internal/mode/static/nginx/modules:/modules/ \
@@ -103,15 +109,13 @@ generate-njs-yaml: ## Generate the njs-modules ConfigMap
103109
lint-helm: ## Run the helm chart linter
104110
helm lint $(CHART_DIR)
105111

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
111116

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
115119

116120
.PHONY: dev-all
117121
dev-all: deps fmt njs-fmt vet lint unit-test njs-unit-test ## Run all the development checks

0 commit comments

Comments
 (0)