Skip to content

Commit b6760f1

Browse files
authored
Add help for Makefile (#228)
1 parent bda13ef commit b6760f1

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

Makefile

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,47 @@ TARGET ?= local
1010
KIND_KUBE_CONFIG_FOLDER = $${HOME}/.kube/kind
1111
OUT_DIR=$(shell pwd)/build/.out
1212

13-
export DOCKER_BUILDKIT = 1
13+
.DEFAULT_GOAL := help
14+
15+
.PHONY: help
16+
help: Makefile ## Display this help
17+
@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}'
1418

1519
.PHONY: container
16-
container: build
20+
container: build ## Build the container
21+
@docker -v || (code=$$?; printf "\033[0;31mError\033[0m: there was a problem with Docker\n"; exit $$code)
1722
docker build --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) --build-arg DATE=$(DATE) --target $(TARGET) -f build/Dockerfile -t $(PREFIX):$(TAG) .
1823

1924
.PHONY: build
20-
build:
25+
build: ## Build the binary
2126
ifeq (${TARGET},local)
27+
@go version || (code=$$?; printf "\033[0;31mError\033[0m: unable to build locally\n"; exit $$code)
2228
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
2329
endif
2430

2531
.PHONY: generate
26-
generate:
32+
generate: ## Run go generate
2733
go generate ./...
2834

29-
.PHONY: out_dir
30-
out_dir:
31-
mkdir -p $(OUT_DIR)
32-
3335
.PHONY: clean
34-
clean: out_dir
35-
rm -rf $(OUT_DIR)
36+
clean: ## Clean the build
37+
-rm -r $(OUT_DIR)
38+
39+
.PHONY: clean--go-cache
40+
clean-go-cache: ## Clean go cache
41+
@go clean -modcache
3642

3743
.PHONY: deps
38-
deps:
44+
deps: ## Add missing and remove unused modules, verify deps and download them to local cache
3945
@go mod tidy && go mod verify && go mod download
4046

4147
.PHONY: update-codegen
42-
update-codegen:
48+
update-codegen: ## Update codegen
4349
# requires the root folder of the repo to be inside the GOPATH
4450
./hack/update-codegen.sh
4551

4652
.PHONY: verify-codegen
47-
verify-codegen:
53+
verify-codegen: ## Verify code generation
4854
# requires the root folder of the repo to be inside the GOPATH
4955
./hack/verify-codegen.sh
5056

@@ -53,43 +59,43 @@ update-crds: ## Update CRDs
5359
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/
5460

5561
.PHONY: create-kind-cluster
56-
create-kind-cluster:
62+
create-kind-cluster: ## Create a kind cluster
5763
kind create cluster --image kindest/node:v1.25.0
5864
kind export kubeconfig --kubeconfig $(KIND_KUBE_CONFIG_FOLDER)/config
5965

6066
.PHONY: delete-kind-cluster
61-
delete-kind-cluster:
67+
delete-kind-cluster: ## Delete kind cluster
6268
kind delete cluster
6369

6470
.PHONY: fmt
65-
fmt: ## Run go fmt against code.
71+
fmt: ## Run go fmt against code
6672
go fmt ./...
6773

6874
.PHONY: njs-fmt
69-
njs-fmt: ## Run prettier against the njs httpmatches module.
75+
njs-fmt: ## Run prettier against the njs httpmatches module
7076
docker run --rm -w /modules \
7177
-v $(PWD)/internal/nginx/modules/:/modules/ \
7278
node:18 \
7379
/bin/bash -c "npm install && npm run format"
7480

7581
.PHONY: vet
76-
vet: ## Run go vet against code.
82+
vet: ## Run go vet against code
7783
go vet ./...
7884

7985
.PHONY: lint
80-
lint: ## Run golangci-lint against code.
86+
lint: ## Run golangci-lint against code
8187
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
8288

8389
.PHONY: unit-test
8490
unit-test: ## Run unit tests for the go code
8591
go test ./... -race -coverprofile cover.out
8692
go tool cover -html=cover.out -o cover.html
8793

88-
njs-unit-test: ## Run unit tests for the njs httpmatches module.
94+
njs-unit-test: ## Run unit tests for the njs httpmatches module
8995
docker run --rm -w /modules \
9096
-v $(PWD)/internal/nginx/modules:/modules/ \
9197
node:18 \
9298
/bin/bash -c "npm install && npm test && npm run clean"
9399

94100
.PHONY: dev-all
95-
dev-all: deps fmt njs-fmt vet lint unit-test njs-unit-test
101+
dev-all: deps fmt njs-fmt vet lint unit-test njs-unit-test ## Run all the development checks

0 commit comments

Comments
 (0)