forked from kinvolk/lokomotive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
212 lines (166 loc) · 7.74 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
TAG := `git describe --tags --always`
VERSION :=
# MOD can either be "readonly" or "vendor".
# The default is "vendor" which uses checked out modules for building.
# Use make MOD=readonly to build with sources from the Go module cache instead.
MOD ?= vendor
DOCS_DIR ?= docs/cli
ALL_BUILD_TAGS := "aws,equinixmetal,aks,e2e,baremetal,disruptivee2e,poste2e,equinixmetal_fluo"
ADMISSION_WEBHOOK_SERVER := "quay.io/kinvolk/lokomotive-admission-webhook-server"
# When you bump this, also bump the version in ./.github/workflows/ci.yaml and for the CI image.
GOLANG_VERSION ?= 1.15.10
## Adds a '-dirty' suffix to version string if there are uncommitted changes
changes := $(shell git status --porcelain)
ifeq ($(changes),)
VERSION := $(TAG)
else
VERSION := $(TAG)-dirty
endif
# Use the Go module mirror (https://blog.golang.org/module-mirror-launch).
# This speeds up build time and protects against disappearing dependencies.
ifeq ($(shell (go env GOPROXY)),)
export GOPROXY=https://proxy.golang.org
endif
LDFLAGS := "-X github.com/kinvolk/lokomotive/pkg/version.Version=$(VERSION) -extldflags '-static'"
.NOTPARALLEL:
.PHONY: build
build: update-assets build-slim
.PHONY: build-in-docker
build-in-docker:
# increase ulimit to workaround https://github.com/golang/go/issues/37436
docker run --ulimit memlock=1024000 --rm -ti -v $(shell pwd):/usr/src/lokomotive -w /usr/src/lokomotive golang:$(GOLANG_VERSION) sh -c "make"
.PHONY: build-test
build-test:
go test -run=nonexistent -mod=$(MOD) -tags=$(ALL_BUILD_TAGS) -covermode=atomic -buildmode=exe -v ./... > /dev/null
.PHONY: all
all: build build-test test lint codespell
.PHONY: update-assets
update-assets:
@find assets/ -type d -empty | grep . >/dev/null && echo "Found empty directories in assets/ directory. Remove them and run 'make update-assets' again." || true
@find assets/ -type d -empty | grep . && exit 1 || true
GO111MODULE=on go generate -mod=$(MOD) ./...
.PHONY: build-slim
# Once we change CI code to build outside GOPATH, GO111MODULE can be removed, so
# we rely on defaults.
build-slim:
CGO_ENABLED=0 GO111MODULE=on go build \
-mod=$(MOD) \
-ldflags $(LDFLAGS) \
-buildmode=exe \
-o lokoctl \
github.com/kinvolk/lokomotive/cmd/lokoctl
.PHONY: test
test: run-unit-tests
.PHONY: lint
lint: build-slim build-test lint-bin
lint-bin:
@if [ "$$(git config --get diff.noprefix)" = "true" ]; then printf "\n\ngolangci-lint has a bug and can't run with the current git configuration: 'diff.noprefix' is set to 'true'. To override this setting for this repository, run the following command:\n\n'git config diff.noprefix false'\n\nFor more details, see https://github.com/golangci/golangci-lint/issues/948.\n\n\n"; exit 1; fi
golangci-lint run --new-from-rev=$$(git merge-base $$(cat .git/resource/base_sha 2>/dev/null || echo "origin/master") HEAD) ./...
.PHONY: lint-docker
lint-docker:
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:v1.30.0 make lint
GOFORMAT_FILES := $(shell find . -name '*.go' | grep -v '^./vendor')
.PHONY: run-unit-tests
run-unit-tests:
go test -mod=$(MOD) -covermode=atomic -buildmode=exe ./...
.PHONY: format-go-code
## Formats any go file that differs from gofmt's style
format-go-code:
@gofmt -s -l -w ${GOFORMAT_FILES}
kubeconfig := $(KUBECONFIG)
## Following kubeconfig path is only valid from CI
ifeq ($(RUN_FROM_CI),"true")
kubeconfig := "${HOME}/lokoctl-assets/cluster-assets/auth/kubeconfig"
endif
.PHONY: run-e2e-tests
run-e2e-tests:
KUBECONFIG=${kubeconfig} PLATFORM=${platform} go test -mod=$(MOD) -tags="$(platform),e2e" -covermode=atomic -buildmode=exe -v -count=1 ./test/...
# Test if the metrics are actually being scraped
KUBECONFIG=${kubeconfig} PLATFORM=${platform} go test -mod=$(MOD) -tags="$(platform),poste2e" -covermode=atomic -buildmode=exe -v -count=1 -timeout=17m ./test/...
# This is a test that should be run in the end to reduce the disruption to other tests because
# it will delete a node.
# The timeout is made longer as it will perform actions that will take longer than the default 10 minutes.
KUBECONFIG=${kubeconfig} PLATFORM=${platform} go test -timeout 30m -mod=$(MOD) -tags="$(platform),disruptivee2e" -covermode=atomic -buildmode=exe -v -count=1 ./test/...
.PHONY: all
all: build test
.PHONY: install
install: update-assets install-slim
.PHONY: install-slim
# Once we change CI code to build outside GOPATH, GO111MODULE can be removed,
# so we rely on defaults.
install-slim:
CGO_ENABLED=0 GO111MODULE=on go install \
-mod=$(MOD) \
-ldflags $(LDFLAGS) \
-buildmode=exe \
./cmd/lokoctl
.PHONY: install-packr2
install-packr2:
echo "This target has been removed. This is here only to satisfy CI and will be removed later."
.PHONY: update
update: update-dependencies tidy vendor
.PHONY: update-dependencies
update-dependencies:
GO111MODULE=on go get -u ./...
.PHONY: tidy
tidy:
GO111MODULE=on go mod tidy
.PHONY: vendor
vendor:
GO111MODULE=on go mod vendor
.PHONY: docker-build
docker-build:
docker build -t kinvolk/lokomotive --build-arg GOLANG_VERSION=$(GOLANG_VERSION) .
.PHONY: docker-vendor
docker-vendor: docker-build
docker run --rm -ti -v $(shell pwd):/usr/src/lokomotive kinvolk/lokomotive sh -c "make vendor && chown -R $(shell id -u):$(shell id -g) vendor"
.PHONY: docker-update-assets
docker-update-assets: docker-build
docker run --rm -ti -v $(shell pwd):/usr/src/lokomotive kinvolk/lokomotive sh -c "make update-assets && chown -R $(shell id -u):$(shell id -g) assets"
.PHONY: docker-update-dependencies
docker-update-dependencies: docker-build
docker run --rm -ti -v $(shell pwd):/usr/src/lokomotive kinvolk/lokomotive sh -c "make update-dependencies && chown $(shell id -u):$(shell id -g) go.mod go.sum"
.PHONY: docs
docs:
GO111MODULE=on go run -mod=$(MOD) -buildmode=exe cli/cmd/document/main.go $(DOCS_DIR)
for f in $(DOCS_DIR)/lokoctl*md; do sed -i '1s/^## \(lokoctl.*\)$$/---\ntitle: \1\nweight: 10\n---/' $$f; done
.PHONY: build-and-publish-release
build-and-publish-release: SHELL:=/bin/bash
build-and-publish-release:
goreleaser release --release-notes <(./scripts/print-version-changelog.sh)
.PHONY: codespell
codespell: CODESPELL_SKIP := $(shell cat .codespell.skip | tr \\n ',' | sed 's/,$$//g')
codespell: CODESPELL_BIN := codespell
codespell:
which $(CODESPELL_BIN) >/dev/null 2>&1 || (echo "$(CODESPELL_BIN) binary not found, skipping spell checking"; exit 0)
$(CODESPELL_BIN) --skip $(CODESPELL_SKIP) --ignore-words .codespell.ignorewords --check-filenames --check-hidden
.PHONY: build-webhook
build-webhook:
CGO_ENABLED=0 GO111MODULE=on go build \
-o=admission-webhook-server \
-mod=$(MOD) \
-ldflags $(LDFLAGS) \
./cmd/admission-webhook-server
.PHONY: docker-build-webhook
docker-build-webhook:
docker build -f cmd/admission-webhook-server/Dockerfile -t $(ADMISSION_WEBHOOK_SERVER) --build-arg GOLANG_VERSION=$(GOLANG_VERSION) .
.PHONY: check-working-tree-clean
check-working-tree-clean:
@test -z "$$(git status --porcelain)" || (echo "Commit all changes before running this target"; exit 1)
.PHONY: check-update-assets
check-update-assets: check-working-tree-clean update-assets
@test -z "$$(git status --porcelain)" || (echo "Please run make update-assets and commit the changes."; git --no-pager diff; exit 1)
.PHONY: check-vendor
check-vendor: check-working-tree-clean vendor
@test -z "$$(git status --porcelain)" || (echo "Please run make vendor and commit the changes."; git status; exit 1)
.PHONY: check-docs
check-docs: check-working-tree-clean docs
@test -z "$$(git status --porcelain)" || (echo "Please run make docs and commit the changes."; git status; exit 1)
.PHONY: check-terraform
check-terraform:
terraform fmt -check -recursive ./assets/
.PHONY: ci
ci: build build-test test check-update-assets check-vendor check-docs check-terraform
.PHONY: deploy-ci-cluster
deploy-ci-cluster:
./ci/scripts/deploy-cluster.sh