forked from nginx/nginx-gateway-fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
101 lines (78 loc) · 3.52 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
VERSION = edge
TAG = $(VERSION)
PREFIX ?= nginx-kubernetes-gateway
GIT_COMMIT = $(shell git rev-parse HEAD)
DATE = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
TARGET ?= local
KIND_KUBE_CONFIG_FOLDER = $${HOME}/.kube/kind
OUT_DIR=$(shell pwd)/build/.out
.DEFAULT_GOAL := help
.PHONY: help
help: Makefile ## Display this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "; printf "Usage:\n\n make \033[36m<target>\033[0m\n\nTargets:\n\n"}; {printf " \033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: container
container: build ## Build the container
@docker -v || (code=$$?; printf "\033[0;31mError\033[0m: there was a problem with Docker\n"; exit $$code)
docker build --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) --build-arg DATE=$(DATE) --target $(TARGET) -f build/Dockerfile -t $(PREFIX):$(TAG) .
.PHONY: build
build: ## Build the binary
ifeq (${TARGET},local)
@go version || (code=$$?; printf "\033[0;31mError\033[0m: unable to build locally\n"; exit $$code)
CGO_ENABLED=0 GOOS=linux 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
endif
.PHONY: generate
generate: ## Run go generate
go generate ./...
.PHONY: clean
clean: ## Clean the build
-rm -r $(OUT_DIR)
.PHONY: clean--go-cache
clean-go-cache: ## Clean go cache
@go clean -modcache
.PHONY: deps
deps: ## Add missing and remove unused modules, verify deps and download them to local cache
@go mod tidy && go mod verify && go mod download
.PHONY: update-codegen
update-codegen: ## Update codegen
# requires the root folder of the repo to be inside the GOPATH
./hack/update-codegen.sh
.PHONY: verify-codegen
verify-codegen: ## Verify code generation
# requires the root folder of the repo to be inside the GOPATH
./hack/verify-codegen.sh
.PHONY: update-crds
update-crds: ## Update CRDs
go run sigs.k8s.io/controller-tools/cmd/controller-gen crd:crdVersions=v1 schemapatch:manifests=./deploy/manifests/crds/ paths=./pkg/apis/... output:dir=./deploy/manifests/crds/
.PHONY: create-kind-cluster
create-kind-cluster: ## Create a kind cluster
kind create cluster --image kindest/node:v1.25.0
kind export kubeconfig --kubeconfig $(KIND_KUBE_CONFIG_FOLDER)/config
.PHONY: delete-kind-cluster
delete-kind-cluster: ## Delete kind cluster
kind delete cluster
.PHONY: fmt
fmt: ## Run go fmt against code
go fmt ./...
.PHONY: njs-fmt
njs-fmt: ## Run prettier against the njs httpmatches module
docker run --rm -w /modules \
-v $(PWD)/internal/nginx/modules/:/modules/ \
node:18 \
/bin/bash -c "npm install && npm run format"
.PHONY: vet
vet: ## Run go vet against code
go vet ./...
.PHONY: lint
lint: ## Run golangci-lint against code
docker run --pull always --rm -v $(shell pwd):/nginx-kubernetes-gateway -w /nginx-kubernetes-gateway -v $(shell go env GOCACHE):/cache/go -e GOCACHE=/cache/go -e GOLANGCI_LINT_CACHE=/cache/go -v $(shell go env GOPATH)/pkg:/go/pkg golangci/golangci-lint:latest golangci-lint --color always run
.PHONY: unit-test
unit-test: ## Run unit tests for the go code
go test ./... -race -coverprofile cover.out
go tool cover -html=cover.out -o cover.html
njs-unit-test: ## Run unit tests for the njs httpmatches module
docker run --rm -w /modules \
-v $(PWD)/internal/nginx/modules:/modules/ \
node:18 \
/bin/bash -c "npm install && npm test && npm run clean"
.PHONY: dev-all
dev-all: deps fmt njs-fmt vet lint unit-test njs-unit-test ## Run all the development checks