-
Notifications
You must be signed in to change notification settings - Fork 203
/
Makefile
348 lines (286 loc) · 11.9 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# Export shell defined to support Ubuntu
export SHELL := $(shell which bash)
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
# Include openshift build-machinery-go libraries
include $(PROJECT_DIR)/vendor/github.com/openshift/build-machinery-go/make/golang.mk
include $(PROJECT_DIR)/vendor/github.com/openshift/build-machinery-go/make/targets/openshift/deps.mk
# TIMESTAMP is defined here, and only here, and propagated through out the build flow. This ensures that every artifact
# (binary version and image tag) all have the exact same build timestamp. Because kubectl/oc expect
# a timestamp composed with ':'s we must adjust the string so that it is still compliant with image tag format.
export BIN_TIMESTAMP ?=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
export TIMESTAMP ?=$(shell echo $(BIN_TIMESTAMP) | tr -d ':' | tr 'T' '-' | tr -d 'Z')
SOURCE_GIT_COMMIT_TIMESTAMP ?= $(shell TZ=UTC0 git show --quiet --date='format-local:%Y%m%d%H%M%S' --format="%cd")
include $(PROJECT_DIR)/Makefile.version.$(shell uname -m).var
MICROSHIFT_VERSION ?= $(subst -clean,,$(shell echo '${OCP_VERSION}-${SOURCE_GIT_COMMIT_TIMESTAMP}-${SOURCE_GIT_COMMIT}-${SOURCE_GIT_TREE_STATE}'))
# Overload SOURCE_GIT_TAG value set in vendor/github.com/openshift/build-machinery-go/make/lib/golang.mk
# because since it doesn't work with our version scheme.
SOURCE_GIT_TAG := ${MICROSHIFT_VERSION}
EMBEDDED_GIT_TAG ?= ${SOURCE_GIT_TAG}
EMBEDDED_GIT_COMMIT ?= ${SOURCE_GIT_COMMIT}
EMBEDDED_GIT_TREE_STATE ?= ${SOURCE_GIT_TREE_STATE}
MAJOR := $(shell echo $(SOURCE_GIT_TAG) | awk -F'[._~-]' '{print $$1}')
MINOR := $(shell echo $(SOURCE_GIT_TAG) | awk -F'[._~-]' '{print $$2}')
PATCH := $(shell echo $(SOURCE_GIT_TAG) | awk -F'[._~-]' '{print $$3}')
SRC_ROOT :=$(shell pwd)
WITH_FLANNEL ?= 0
OUTPUT_DIR :=_output
RPM_BUILD_DIR :=$(OUTPUT_DIR)/rpmbuild
CROSS_BUILD_BINDIR :=$(OUTPUT_DIR)/bin
FROM_SOURCE :=false
ARCH :=$(shell uname -m |sed -e "s/x86_64/amd64/" |sed -e "s/aarch64/arm64/")
PULLSECRET ?= ~/.pull-secret.json
# restrict included verify-* targets to only process project files
GO_PACKAGES=$(go list ./cmd/... ./pkg/...)
# Build to a place we can ignore
GO_BUILD_BINDIR :=$(OUTPUT_DIR)/bin
GO_CACHE :=$(shell go env GOCACHE)
ifeq ($(DEBUG),true)
# throw all the debug info in!
LD_FLAGS =
GC_FLAGS =-gcflags 'all=-N -l'
else
# strip everything we can
LD_FLAGS =-w -s
GC_FLAGS =
endif
include $(PROJECT_DIR)/Makefile.kube_git.var
GO_LD_FLAGS := $(GC_FLAGS) -ldflags " \
-X k8s.io/component-base/version.gitMajor=$(KUBE_GIT_MAJOR) \
-X k8s.io/component-base/version.gitMinor=$(KUBE_GIT_MINOR) \
-X k8s.io/component-base/version.gitVersion=$(KUBE_GIT_VERSION) \
-X k8s.io/component-base/version.gitCommit=$(KUBE_GIT_COMMIT) \
-X k8s.io/component-base/version.gitTreeState=$(KUBE_GIT_TREE_STATE) \
-X k8s.io/component-base/version.buildDate=$(BIN_TIMESTAMP) \
-X k8s.io/client-go/pkg/version.gitMajor=$(KUBE_GIT_MAJOR) \
-X k8s.io/client-go/pkg/version.gitMinor=$(KUBE_GIT_MINOR) \
-X k8s.io/client-go/pkg/version.gitVersion=$(KUBE_GIT_VERSION) \
-X k8s.io/client-go/pkg/version.gitCommit=$(KUBE_GIT_COMMIT) \
-X k8s.io/client-go/pkg/version.gitTreeState=$(KUBE_GIT_TREE_STATE) \
-X k8s.io/client-go/pkg/version.buildDate=$(BIN_TIMESTAMP) \
-X github.com/openshift/microshift/pkg/version.majorFromGit=$(MAJOR) \
-X github.com/openshift/microshift/pkg/version.minorFromGit=$(MINOR) \
-X github.com/openshift/microshift/pkg/version.patchFromGit=$(PATCH) \
-X github.com/openshift/microshift/pkg/version.versionFromGit=$(EMBEDDED_GIT_TAG) \
-X github.com/openshift/microshift/pkg/version.commitFromGit=$(EMBEDDED_GIT_COMMIT) \
-X github.com/openshift/microshift/pkg/version.gitTreeState=$(EMBEDDED_GIT_TREE_STATE) \
-X github.com/openshift/microshift/pkg/version.buildDate=$(BIN_TIMESTAMP) \
$(LD_FLAGS)"
debug:
@echo FLAGS:"$(GO_LD_FLAGS)"
@echo TAG:"$(SOURCE_GIT_TAG)"
@echo SOURCE_GIT_TAG:"$(SOURCE_GIT_TAG)"
@echo MAJOR:"$(MAJOR)"
@echo MINOR:"$(MINOR)"
@echo PATCH:"$(PATCH)"
GO_BUILD_FLAGS :=-tags 'include_gcs include_oss containers_image_openpgp gssapi providerless netcgo osusergo strictfipsruntime'
# Set variables for test-unit target
GO_TEST_FLAGS=$(GO_BUILD_FLAGS)
GO_TEST_PACKAGES=./cmd/... ./pkg/...
# Enable CGO when building microshift binary for access to local libraries.
# Use an environment variable to allow CI to disable when cross-compiling.
export CGO_ENABLED ?= 1
# Specify OCP build tools image tag when building rpm with podman
RPM_BUILDER_IMAGE_TAG := rhel-9-golang-1.23-openshift-4.19
all: generate-config microshift etcd
microshift: build
# A target for local developer workflows. This assumes configure-vm.sh
# was already run to build and install the RPM.
.PHONY: install
install: build
sudo systemctl stop microshift
sudo cp $(OUTPUT_DIR)/bin/microshift* /usr/bin/
sudo systemctl start microshift
.PHONY: etcd
export GO_BUILD_FLAGS
etcd:
GO_LD_FLAGS="$(GC_FLAGS) -ldflags \"\
-X main.majorFromGit=$(MAJOR) \
-X main.minorFromGit=$(MINOR) \
-X main.patchFromGit=$(PATCH) \
-X main.versionFromGit=$(EMBEDDED_GIT_TAG) \
-X main.commitFromGit=$(EMBEDDED_GIT_COMMIT) \
-X main.gitTreeState=$(EMBEDDED_GIT_TREE_STATE) \
-X main.buildDate=$(BIN_TIMESTAMP) \
$(LD_FLAGS)\"" \
$(MAKE) -C etcd
# Default verify target for developers
.PHONY: verify
verify: verify-fast
# Fast verification checks that developers can/should run locally
.PHONY: verify-fast
verify-fast: verify-go verify-assets verify-sh verify-py verify-config verify-rf
# Full verification checks that should run in CI
# Note that jobs using podman (e.g. verify-containers) cannot run as part of
# the verify job.
.PHONY: verify-ci
verify-ci: verify-fast verify-images verify-licenses
.PHONY: verify-images
verify-images:
./scripts/verify/verify-images.sh
.PHONY: verify-licenses
verify-licenses: microshift etcd
./scripts/verify/verify-licenses.sh
.PHONY: verify-assets
verify-assets:
./scripts/verify/verify-assets.sh
.PHONY: verify-go
verify-go: verify-gofmt verify-golangci
.PHONY: verify-golangci
verify-golangci:
./scripts/fetch_tools.sh golangci-lint && \
./_output/bin/golangci-lint run --verbose --timeout 20m0s
.PHONY: verify-sh
verify-sh:
./scripts/verify/verify-shell.sh
.PHONY: verify-py
verify-py:
./scripts/verify/verify-py.sh
.PHONY: verify-rf
verify-rf:
./scripts/verify/verify-rf.sh
# Container check is not run in any default verify target as it uses the podman
# command, which does not work in the containerized verify CI job.
# Container verification is performed as part of the image build procedure.
.PHONY: verify-containers
verify-containers:
./scripts/verify/verify-containers.sh
# Vulnerability check is not run in any default verify target.
# It should be run explicitly before the release to track and fix known vulnerabilities.
# Note: Errors are ignored to allow listing vulnerabilities from all the dependencies
.PHONY: verify-govulncheck
verify-govulncheck: microshift etcd
./scripts/fetch_tools.sh govulncheck
-./_output/bin/govulncheck -mode=binary ./_output/bin/microshift
-./_output/bin/govulncheck -mode=binary ./_output/bin/microshift-etcd
###############################
# post install validate #
###############################
##@ Download utilities
OS := $(shell go env GOOS)
ARCH := $(shell go env GOARCH)
# download-tool will curl any file $2 and install it to $1.
define download-tool
@[ -f $(1) ] || { \
set -e ;\
echo "Downloading $(2)" ;\
curl -sSLo "$(1)" "$(2)" ;\
chmod a+x "$(1)" ;\
}
endef
# Execute kuttl health checks against infra pods
.PHONY: validate-cluster
validate-cluster:
cd validate-microshift && ./kuttl-test.sh
##@ Download utilities
OS := $(shell go env GOOS)
ARCH := $(shell go env GOARCH)
# check if FIPS supported
ifeq (, $(shell go doc goexperiment.Flags | grep -i strictfipsruntime))
GOEXPERIMENT =
else
GOEXPERIMENT = "strictfipsruntime"
endif
###############################
# host build targets #
###############################
_build_local:
@mkdir -p "$(CROSS_BUILD_BINDIR)/$(GOOS)_$(GOARCH)"
+@GOOS=$(GOOS) GOARCH=$(GOARCH) $(MAKE) --no-print-directory build \
GO_BUILD_PACKAGES:=./cmd/microshift \
GO_BUILD_BINDIR:=$(CROSS_BUILD_BINDIR)/$(GOOS)_$(GOARCH)
+@GOOS=$(GOOS) GOARCH=$(GOARCH) \
GO_LD_FLAGS="$(GC_FLAGS) -ldflags \"\
-X main.majorFromGit=$(MAJOR) \
-X main.minorFromGit=$(MINOR) \
-X main.versionFromGit=$(EMBEDDED_GIT_TAG) \
-X main.commitFromGit=$(EMBEDDED_GIT_COMMIT) \
-X main.gitTreeState=$(EMBEDDED_GIT_TREE_STATE) \
-X main.buildDate=$(BIN_TIMESTAMP) \
$(LD_FLAGS)\"" \
GOEXPERIMENT=${GOEXPERIMENT} \
$(MAKE) -C etcd --no-print-directory build \
GO_BUILD_PACKAGES:=./cmd/microshift-etcd \
GO_BUILD_BINDIR:=../$(CROSS_BUILD_BINDIR)/$(GOOS)_$(GOARCH)
cross-build-linux-amd64:
+$(MAKE) _build_local GOOS=linux GOARCH=amd64
.PHONY: cross-build-linux-amd64
cross-build-linux-arm64:
+$(MAKE) _build_local GOOS=linux GOARCH=arm64
.PHONY: cross-build-linux-arm64
cross-build: cross-build-linux-amd64 cross-build-linux-arm64
.PHONY: cross-build
RPM_RELEASE := 1
rpm:
MICROSHIFT_VERSION=${MICROSHIFT_VERSION} \
RPM_RELEASE="${RPM_RELEASE}" \
SOURCE_GIT_TAG=${SOURCE_GIT_TAG} \
SOURCE_GIT_COMMIT=${SOURCE_GIT_COMMIT} \
SOURCE_GIT_TREE_STATE=${SOURCE_GIT_TREE_STATE} \
WITH_FLANNEL=${WITH_FLANNEL} \
./packaging/rpm/make-rpm.sh rpm local
.PHONY: rpm
srpm:
MICROSHIFT_VERSION=${MICROSHIFT_VERSION} \
RPM_RELEASE="${RPM_RELEASE}" \
SOURCE_GIT_TAG=${SOURCE_GIT_TAG} \
SOURCE_GIT_COMMIT=${SOURCE_GIT_COMMIT} \
SOURCE_GIT_TREE_STATE=${SOURCE_GIT_TREE_STATE} \
WITH_FLANNEL=${WITH_FLANNEL} \
./packaging/rpm/make-rpm.sh srpm local
.PHONY: srpm
rpm-podman:
podman build \
--volume /etc/pki/entitlement/:/etc/pki/entitlement \
--build-arg TAG=$(RPM_BUILDER_IMAGE_TAG) \
--build-arg DNF=dnf.real \
--authfile $(PULLSECRET) \
--tag microshift-builder:$(RPM_BUILDER_IMAGE_TAG) \
--file ./packaging/images/Containerfile.rpm-builder \
&& \
podman run \
--rm -i \
--volume $$(pwd):/opt/microshift:z \
--env TARGET_ARCH=$(TARGET_ARCH) \
--env WITH_FLANNEL=$(WITH_FLANNEL) \
microshift-builder:$(RPM_BUILDER_IMAGE_TAG) \
bash -ilc 'cd /opt/microshift && make rpm & pid=$$! ; \
trap "echo Killing make PID $${pid}; kill $${pid}" INT ; \
wait $${pid}'
.PHONY: rpm-podman
###############################
# dev targets #
###############################
clean:
if [ -d '$(OUTPUT_DIR)' ]; then rm -rf '$(OUTPUT_DIR)'; fi
.PHONY: clean
vendor:
go mod vendor
for p in $(sort $(wildcard scripts/auto-rebase/rebase_patches/*.patch)); do \
echo "Applying patch $$p"; \
git mailinfo /dev/null /dev/stderr 2<&1- < $$p | git apply --reject || exit 1; \
done
.PHONY: vendor
# Update the etcd dependencies, including especially MicroShift itself.
vendor-etcd:
$(MAKE) -C etcd vendor
.PHONY: vendor-etcd
# There should be no modified files in the etcd/vendor directory after
# running `make vendor-etcd`.
.PHONY: verify-vendor-etcd
verify: verify-vendor-etcd
verify-vendor-etcd: vendor-etcd
./scripts/verify/verify-vendor-etcd.sh
# Use helper `go generate script` to dynamically config information into packaging info as well as documentation.
.PHONY: generate-config verify-config
generate-config:
./scripts/fetch_tools.sh controller-gen && \
go generate -mod vendor ./pkg/config
verify-config: generate-config
./scripts/verify/verify-config.sh
# Run all of the end to end tests
.PHONY: e2e
e2e:
./test/run.sh
.PHONY: rf-fmt
rf-fmt:
@./test/format.sh