-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
224 lines (178 loc) · 7.85 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# SPDX-License-Identifier: MIT
# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
GARM_GITHUB_NAME ?= "github-pat"
GARM_GITHUB_BASE_URL ?= https://github.com
GARM_GITHUB_API_BASE_URL ?= https://api.github.com
GARM_GITHUB_UPLOAD_BASE_URL ?= https://uploads.github.com
# Set binary output folder
BIN_DIR := ./bin
BINARY_NAME := garm-provider-k8s
GO_BUILD_FLAGS :=
PKG_PATH := ./cmd/garm-provider-k8s/main.go
$(eval ARCH := $(shell go env GOARCH))
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
## Tool Binaries
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
GORELEASER ?= $(LOCALBIN)/goreleaser
MDTOC ?= $(LOCALBIN)/mdtoc
NANCY ?= $(LOCALBIN)/nancy
GOVULNCHECK ?= $(LOCALBIN)/govulncheck
KIND ?= $(LOCALBIN)/kind
## Tool Versions
GOLANGCI_LINT_VERSION ?= v1.59.1
GORELEASER_VERSION ?= v1.21.0
MDTOC_VERSION ?= v1.1.0
NANCY_VERSION ?= v1.0.46
KIND_VERSION ?= v0.22.0
##@ Build
.PHONY: all build copy run clean
all: clean build copy docker-build apply
build:
@go mod tidy
@if [ "$(OS)" = "mac" ]; then \
echo "Building $(BINARY_NAME) for mac..." && \
GOOS="darwin" CGO_ENABLED=0 go build $(GO_BUILD_FLAGS) -o $(BIN_DIR)/$(BINARY_NAME) $(PKG_PATH); \
else \
echo "Building $(BINARY_NAME) for linux..." && \
GOOS="linux" CGO_ENABLED=0 go build $(GO_BUILD_FLAGS) -o $(BIN_DIR)/$(BINARY_NAME) $(PKG_PATH); \
fi
test:
@echo "Testing App..."
@go mod tidy
@go test -v ./...
copy:
@echo "copying binaries..."
@mkdir -p ./hack/bin
@cp "$(BIN_DIR)/$(BINARY_NAME)" "./hack/bin/$(BINARY_NAME)"
clean:
@echo "Cleaning up $(BIN_DIR)..."
@rm -rf $(BIN_DIR)
DEBUG = 0
##@ Local Development
.PHONY: docker-build
docker-build: ## Build a garm image with the k8s provider
docker build -t localhost:5000/garm-with-k8s:latest ./hack
docker push localhost:5000/garm-with-k8s:latest
.PHONY: docker-build-summerwind-runner
docker-build-summerwind-runner: ## Build the used runner image
docker build -t $(RUNNER_IMAGE) ./runner/summerwind
docker push $(RUNNER_IMAGE)
.PHONY: docker-build-upstream-runner
docker-build-upstream-runner: ## Build the used runner image
docker build -t $(RUNNER_IMAGE) ./runner/upstream
docker push $(RUNNER_IMAGE)
.PHONY: template
template: ## Create the necessary configmap for the local development
ifeq ($(GARM_GITHUB_OAUTH_TOKEN),)
$(error GARM_GITHUB_OAUTH_TOKEN is undefined)
endif
GARM_GITHUB_NAME=$(GARM_GITHUB_NAME) \
GARM_GITHUB_OAUTH_TOKEN=$(GARM_GITHUB_OAUTH_TOKEN) \
GARM_GITHUB_BASE_URL=$(GARM_GITHUB_BASE_URL) \
GARM_GITHUB_API_BASE_URL=$(GARM_GITHUB_API_BASE_URL) \
GARM_GITHUB_UPLOAD_BASE_URL=$(GARM_GITHUB_UPLOAD_BASE_URL) \
envsubst < hack/local-development/kubernetes/configmap-envsubst.yaml > hack/local-development/kubernetes/configmap.yaml
.PHONY: prepare-operator
prepare-operator: ## Prepare garm-operator for local development
curl -L https://github.com/mercedes-benz/garm-operator/releases/download/v0.3.2/garm_operator_all.yaml | \
GARM_SERVER_URL=http://garm-server.garm-server.svc:9997 \
GARM_SERVER_USERNAME=admin \
GARM_SERVER_PASSWORD=LmrBG1KcBOsDfNKq4cQTGpc0hJ0kejkk \
OPERATOR_WATCH_NAMESPACE=garm-operator-system \
envsubst > hack/local-development/kubernetes/garm-operator-all.yaml
.PHONY: kind-cluster
kind-cluster: $(KIND) ## Create a new kind cluster designed for local development
hack/scripts/kind-with-registry.sh
.PHONY: delete-kind-cluster
delete-kind-cluster:
$(KIND) delete cluster --name garm
docker kill kind-registry && docker rm kind-registry
.PHONY: tilt-up
tilt-up: kind-cluster ## Start tilt and build kind cluster
tilt up
##@ Release
.PHONY: release
release: goreleaser ## Create a new release
$(GORELEASER) release --clean
##@ Lint / Verify
ALL_VERIFY_CHECKS = doctoc license security
.PHONY: verify
verify: $(addprefix verify-,$(ALL_VERIFY_CHECKS)) ## Run all verify-* targets
.PHONY: lint
lint: $(GOLANGCI_LINT) ## Run linting.
$(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS)
.PHONY: lint-fix
lint-fix: $(GOLANGCI_LINT) ## Lint the codebase and run auto-fixers if supported by the linte
GOLANGCI_LINT_EXTRA_ARGS=--fix $(MAKE) lint
.PHONY: verify-license
verify-license: ## Verify license headers
./hack/scripts/verify-license.sh
.PHONY: verify-doctoc
verify-doctoc: generate-doctoc
@if !(git diff --quiet HEAD); then \
git diff; \
echo "doctoc is out of date, run make generate-doctoc"; exit 1; \
fi
.PHONY: verify-security
verify-security: govulncheck-scan nancy-scan ## Verify security by running govulncheck and nancy
@echo "Security checks passed"
.PHONY: govulncheck-scan
govulncheck-scan: govulncheck ## Perform govulncheck scan
$(GOVULNCHECK) ./...
.PHONY: nancy-scan
nancy-scan: nancy ## Perform nancy scan
go list -json -deps ./... | $(NANCY) sleuth
##@ Build Dependencies
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. If wrong version is installed, it will be overwritten.
$(GOLANGCI_LINT): $(LOCALBIN)
test -s $(LOCALBIN)/golangci-lint && $(LOCALBIN)/golangci-lint --version | grep -q $(GOLANGCI_LINT_VERSION) || \
GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
.PHONY: goreleaser
goreleaser: $(GORELEASER) ## Download goreleaser locally if necessary. If wrong version is installed, it will be overwritten.
$(GORELEASER): $(LOCALBIN)
test -s $(LOCALBIN)/goreleaser && $(LOCALBIN)/goreleaser --version | grep -q $(GORELEASER_VERSION) || \
GOBIN=$(LOCALBIN) go install github.com/goreleaser/goreleaser@$(GORELEASER_VERSION)
.PHONY: mdtoc
mdtoc: $(MDTOC) ## Download mdtoc locally if necessary. If wrong version is installed, it will be overwritten.
$(MDTOC): $(LOCALBIN)
test -s $(LOCALBIN)/mdtoc || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/mdtoc@$(MDTOC_VERSION)
.PHONY: nancy
nancy: $(NANCY) ## Download nancy locally if necessary. If wrong version is installed, it will be overwritten.
$(NANCY): $(LOCALBIN)
test -s $(LOCALBIN)/nancy && $(LOCALBIN)/nancy --version | grep -q $(NANCY_VERSION) || \
GOBIN=$(LOCALBIN) go install github.com/sonatype-nexus-community/nancy@$(NANCY_VERSION)
.PHONY: govulncheck
govulncheck: $(GOVULNCHECK) ## Download govulncheck locally if necessary. If wrong version is installed, it will be overwritten.
$(GOVULNCHECK): $(LOCALBIN)
test -s $(LOCALBIN)/govulncheck || \
GOBIN=$(LOCALBIN) go install golang.org/x/vuln/cmd/govulncheck@latest
.PHONY: kind
kind: $(KIND) ## Download kind locally if necessary. If wrong version is installed, it will be overwritten.
$(KIND): $(LOCALBIN)
test -s $(LOCALBIN)/kind && $(LOCALBIN)/kind version | grep -q $(KIND_VERSION) || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/kind@$(KIND_VERSION)
##@ Documentation
.PHONY: generate-doctoc
generate-doctoc: mdtoc ## Generate documentation table of contents
grep --include='*.md' -rl -e '<!-- toc -->' $(git rev-parse --show-toplevel) | xargs $(MDTOC) -inplace -max-depth 3