forked from crc-org/crc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
292 lines (230 loc) · 11.1 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
SHELL := /bin/bash
BUNDLE_VERSION = 4.7.2
BUNDLE_EXTENSION = crcbundle
CRC_VERSION = 1.23.1
COMMIT_SHA=$(shell git rev-parse --short HEAD)
MACOS_INSTALL_PATH = /Library/CodeReady Containers
CONTAINER_RUNTIME ?= podman
ifdef OKD_VERSION
BUNDLE_VERSION = $(OKD_VERSION)
CRC_VERSION := $(CRC_VERSION)-OKD
endif
# Go and compilation related variables
BUILD_DIR ?= out
SOURCE_DIRS = cmd pkg test
RELEASE_DIR ?= release
# Docs build related variables
DOCS_BUILD_DIR ?= docs/build
DOCS_BUILD_CONTAINER ?= quay.io/crcont/docs-builder:latest
DOCS_BUILD_TARGET ?= /docs/source/getting_started/master.adoc
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
HOST_BUILD_DIR=$(BUILD_DIR)/$(GOOS)-$(GOARCH)
GOPATH ?= $(shell go env GOPATH)
ORG := github.com/code-ready
REPOPATH ?= $(ORG)/crc
SOURCES := $(shell git ls-files *.go ":^vendor")
RELEASE_INFO := release-info.json
MOCK_BUNDLE ?= false
# Check that given variables are set and all have non-empty values,
# die with an error otherwise.
#
# Params:
# 1. Variable name(s) to test.
# 2. (optional) Error message to print.
check_defined = \
$(strip $(foreach 1,$1, \
$(call __check_defined,$1,$(strip $(value 2)))))
__check_defined = \
$(if $(value $1),, \
$(error Undefined $1$(if $2, ($2))))
# Linker flags
VERSION_VARIABLES := -X $(REPOPATH)/pkg/crc/version.crcVersion=$(CRC_VERSION) \
-X $(REPOPATH)/pkg/crc/version.bundleVersion=$(BUNDLE_VERSION) \
-X $(REPOPATH)/pkg/crc/version.commitSha=$(COMMIT_SHA)
RELEASE_VERSION_VARIABLES := -X $(REPOPATH)/pkg/crc/segment.WriteKey=cvpHsNcmGCJqVzf6YxrSnVlwFSAZaYtp
ifdef OKD_VERSION
VERSION_VARIABLES := $(VERSION_VARIABLES) -X $(REPOPATH)/pkg/crc/version.okdBuild=true
endif
# https://golang.org/cmd/link/
LDFLAGS := $(VERSION_VARIABLES) -extldflags='-static' ${GO_EXTRA_LDFLAGS}
# Add default target
.PHONY: default
default: install
# Create and update the vendor directory
.PHONY: vendor
vendor:
go mod tidy
go mod vendor
.PHONY: vendorcheck
vendorcheck:
./verify-vendor.sh
.PHONY: check
check: cross build_e2e $(HOST_BUILD_DIR)/crc-embedder test cross-lint vendorcheck
# Start of the actual build targets
.PHONY: install
install: $(SOURCES)
go install -ldflags="$(LDFLAGS)" $(GO_EXTRA_BUILDFLAGS) ./cmd/crc
$(BUILD_DIR)/macos-amd64/crc: $(SOURCES)
GOARCH=amd64 GOOS=darwin go build -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/macos-amd64/crc $(GO_EXTRA_BUILDFLAGS) ./cmd/crc
$(BUILD_DIR)/linux-amd64/crc: $(SOURCES)
GOOS=linux GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/linux-amd64/crc $(GO_EXTRA_BUILDFLAGS) ./cmd/crc
$(BUILD_DIR)/windows-amd64/crc.exe: $(SOURCES)
GOARCH=amd64 GOOS=windows go build -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/windows-amd64/crc.exe $(GO_EXTRA_BUILDFLAGS) ./cmd/crc
$(HOST_BUILD_DIR)/crc-embedder: $(SOURCES)
go build --tags="build" -ldflags="$(LDFLAGS)" -o $(HOST_BUILD_DIR)/crc-embedder $(GO_EXTRA_BUILDFLAGS) ./cmd/crc-embedder
.PHONY: cross ## Cross compiles all binaries
cross: $(BUILD_DIR)/macos-amd64/crc $(BUILD_DIR)/linux-amd64/crc $(BUILD_DIR)/windows-amd64/crc.exe
.PHONY: containerized ## Cross compile from container
containerized: clean
${CONTAINER_RUNTIME} build -t crc-build -f images/build .
${CONTAINER_RUNTIME} run --name crc-cross crc-build make cross
${CONTAINER_RUNTIME} cp crc-cross:/opt/app-root/src/out ./
${CONTAINER_RUNTIME} rm crc-cross
${CONTAINER_RUNTIME} rmi crc-build
.PHONY: test
test:
go test -race --tags build -v -ldflags="$(VERSION_VARIABLES)" ./pkg/... ./cmd/...
.PHONY: spec test-rpmbuild
GENERATED_RPM_FILES=packaging/rpm/crc.spec images/rpmbuild/Containerfile
spec: $(GENERATED_RPM_FILES)
test-rpmbuild: spec
${CONTAINER_RUNTIME} build -f images/rpmbuild/Containerfile .
.PHONY: build_docs
build_docs:
${CONTAINER_RUNTIME} run -v $(CURDIR)/docs:/docs:Z --rm $(DOCS_BUILD_CONTAINER) build_docs -b html5 -D /$(DOCS_BUILD_DIR) -o index.html $(DOCS_BUILD_TARGET)
.PHONY: build_docs_pdf
build_docs_pdf:
${CONTAINER_RUNTIME} run -v $(CURDIR)/docs:/docs:Z --rm $(DOCS_BUILD_CONTAINER) build_docs_pdf -D /$(DOCS_BUILD_DIR) -o doc.pdf $(DOCS_BUILD_TARGET)
.PHONY: docs_serve
docs_serve: build_docs
${CONTAINER_RUNTIME} run -it -v $(CURDIR)/docs:/docs:Z --rm -p 8088:8088/tcp $(DOCS_BUILD_CONTAINER) docs_serve
.PHONY: docs_check_links
docs_check_links:
${CONTAINER_RUNTIME} run -it -v $(CURDIR)/docs:/docs:Z --rm $(DOCS_BUILD_CONTAINER) docs_check_links
.PHONY: clean_docs clean_macos_package
clean_docs:
rm -rf $(CURDIR)/docs/build
clean_macos_package:
rm -f packaging/darwin/Distribution
rm -f packaging/darwin/Resources/welcome.html
rm -f packaging/darwin/scripts/postinstall
rm -rf packaging/root/
.PHONY: clean ## Remove all build artifacts
clean: clean_docs clean_macos_package
rm -f $(GENERATED_RPM_FILES)
rm -rf $(BUILD_DIR)
rm -f $(GOPATH)/bin/crc
rm -rf $(RELEASE_DIR)
.PHONY: build_e2e
build_e2e: $(SOURCES)
GOOS=linux go test ./test/e2e/ -c -o $(BUILD_DIR)/linux-amd64/e2e.test
GOOS=windows go test ./test/e2e/ -c -o $(BUILD_DIR)/windows-amd64/e2e.test.exe
GOOS=darwin go test ./test/e2e/ -c -o $(BUILD_DIR)/macos-amd64/e2e.test
.PHONY: integration ## Run integration tests in Ginkgo
integration:
ifndef PULL_SECRET_PATH
export PULL_SECRET_PATH = $(HOME)/Downloads/crc-pull-secret
endif
ifndef BUNDLE_PATH
export BUNDLE_PATH = $(HOME)/Downloads/crc_libvirt_$(BUNDLE_VERSION).$(BUNDLE_EXTENSION)
endif
integration:
@go test -timeout=60m $(REPOPATH)/test/integration -v
.PHONY: e2e ## Run e2e tests
e2e:
GODOG_OPTS = --godog.tags=$(GOOS)
ifndef PULL_SECRET_FILE
PULL_SECRET_FILE = --pull-secret-file=$(HOME)/Downloads/crc-pull-secret
endif
ifndef BUNDLE_LOCATION
BUNDLE_LOCATION = --bundle-location=$(HOME)/Downloads/crc_libvirt_$(BUNDLE_VERSION).$(BUNDLE_EXTENSION)
endif
ifndef CRC_BINARY
CRC_BINARY = --crc-binary=$(GOPATH)/bin
endif
e2e:
@go test --timeout=180m $(REPOPATH)/test/e2e -v $(PULL_SECRET_FILE) $(BUNDLE_LOCATION) $(CRC_BINARY) --bundle-version=$(BUNDLE_VERSION) $(GODOG_OPTS)
.PHONY: fmt
fmt:
@gofmt -l -w $(SOURCE_DIRS)
$(GOPATH)/bin/golangci-lint:
pushd /tmp && GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/[email protected] && popd
# Run golangci-lint against code
.PHONY: lint cross-lint
lint: $(GOPATH)/bin/golangci-lint
$(GOPATH)/bin/golangci-lint run
cross-lint: $(GOPATH)/bin/golangci-lint
GOOS=darwin $(GOPATH)/bin/golangci-lint run
GOOS=linux $(GOPATH)/bin/golangci-lint run
GOOS=windows $(GOPATH)/bin/golangci-lint run
.PHONY: gen_release_info
gen_release_info:
@cat release-info.json.sample | sed s/@CRC_VERSION@/\"$(CRC_VERSION)\"/ > $(RELEASE_INFO)
@sed -i s/@GIT_COMMIT_SHA@/\"$(COMMIT_SHA)\"/ $(RELEASE_INFO)
@sed -i s/@OPENSHIFT_VERSION@/\"$(BUNDLE_VERSION)\"/ $(RELEASE_INFO)
.PHONY: release
release: LDFLAGS += $(RELEASE_VERSION_VARIABLES)
release: cross-lint embed_bundle build_docs_pdf gen_release_info
mkdir $(RELEASE_DIR)
@mkdir -p $(BUILD_DIR)/crc-macos-$(CRC_VERSION)-amd64
@cp LICENSE $(DOCS_BUILD_DIR)/doc.pdf $(BUILD_DIR)/macos-amd64/crc $(BUILD_DIR)/crc-macos-$(CRC_VERSION)-amd64
tar cJSf $(RELEASE_DIR)/crc-macos-amd64.tar.xz -C $(BUILD_DIR) crc-macos-$(CRC_VERSION)-amd64 --owner=0 --group=0
@mkdir -p $(BUILD_DIR)/crc-linux-$(CRC_VERSION)-amd64
@cp LICENSE $(DOCS_BUILD_DIR)/doc.pdf $(BUILD_DIR)/linux-amd64/crc $(BUILD_DIR)/crc-linux-$(CRC_VERSION)-amd64
tar cJSf $(RELEASE_DIR)/crc-linux-amd64.tar.xz -C $(BUILD_DIR) crc-linux-$(CRC_VERSION)-amd64 --owner=0 --group=0
@mkdir -p $(BUILD_DIR)/crc-windows-$(CRC_VERSION)-amd64
@cp LICENSE $(DOCS_BUILD_DIR)/doc.pdf $(BUILD_DIR)/windows-amd64/crc.exe $(BUILD_DIR)/crc-windows-$(CRC_VERSION)-amd64
cd $(BUILD_DIR) && zip -r $(CURDIR)/$(RELEASE_DIR)/crc-windows-amd64.zip crc-windows-$(CRC_VERSION)-amd64
@mv $(RELEASE_INFO) $(RELEASE_DIR)/$(RELEASE_INFO)
pushd $(RELEASE_DIR) && sha256sum * > sha256sum.txt && popd
HYPERKIT_BUNDLENAME = $(BUNDLE_DIR)/crc_hyperkit_$(BUNDLE_VERSION).$(BUNDLE_EXTENSION)
HYPERV_BUNDLENAME = $(BUNDLE_DIR)/crc_hyperv_$(BUNDLE_VERSION).$(BUNDLE_EXTENSION)
LIBVIRT_BUNDLENAME = $(BUNDLE_DIR)/crc_libvirt_$(BUNDLE_VERSION).$(BUNDLE_EXTENSION)
.PHONY: embed_bundle check_bundledir
check_bundledir:
ifeq ($(MOCK_BUNDLE),true)
touch $(HYPERKIT_BUNDLENAME) $(HYPERV_BUNDLENAME) $(LIBVIRT_BUNDLENAME)
endif
@$(call check_defined, BUNDLE_DIR, "Embedding bundle requires BUNDLE_DIR set to a directory containing CRC bundles for all hypervisors")
embed_bundle: clean cross $(HOST_BUILD_DIR)/crc-embedder check_bundledir $(HYPERKIT_BUNDLENAME) $(HYPERV_BUNDLENAME) $(LIBVIRT_BUNDLENAME)
$(HOST_BUILD_DIR)/crc-embedder embed --log-level debug --goos=darwin --bundle-dir=$(BUNDLE_DIR) $(BUILD_DIR)/macos-amd64/crc
$(HOST_BUILD_DIR)/crc-embedder embed --log-level debug --goos=linux --bundle-dir=$(BUNDLE_DIR) $(BUILD_DIR)/linux-amd64/crc
$(HOST_BUILD_DIR)/crc-embedder embed --log-level debug --goos=windows --bundle-dir=$(BUNDLE_DIR) $(BUILD_DIR)/windows-amd64/crc.exe
.PHONY: update-go-version
update-go-version:
./update-go-version.sh 1.14
.PHONY: goversioncheck
goversioncheck:
./verify-go-version.sh
packagedir: LDFLAGS+= -X '$(REPOPATH)/pkg/crc/version.macosInstallPath=$(MACOS_INSTALL_PATH)' $(RELEASE_VERSION_VARIABLES)
packagedir: clean check_bundledir $(BUILD_DIR)/macos-amd64/crc $(HOST_BUILD_DIR)/crc-embedder
sed -e 's/__VERSION__/'$(CRC_VERSION)'/g' -e 's@__INSTALL_PATH__@$(MACOS_INSTALL_PATH)@g' packaging/darwin/Distribution.in >packaging/darwin/Distribution
sed -e 's/__VERSION__/'$(CRC_VERSION)'/g' -e 's@__INSTALL_PATH__@$(MACOS_INSTALL_PATH)@g' packaging/darwin/welcome.html.in >packaging/darwin/Resources/welcome.html
sed -e 's/__VERSION__/'$(CRC_VERSION)'/g' -e 's@__INSTALL_PATH__@$(MACOS_INSTALL_PATH)@g' packaging/darwin/postinstall.in >packaging/darwin/scripts/postinstall
chmod 755 packaging/darwin/scripts/postinstall
mkdir -p packaging/root/"$(MACOS_INSTALL_PATH)"/$(CRC_VERSION)/
$(HOST_BUILD_DIR)/crc-embedder download packaging/root/"$(MACOS_INSTALL_PATH)"/$(CRC_VERSION)/
tar -C packaging/root/"$(MACOS_INSTALL_PATH)"/$(CRC_VERSION)/ -xvzf packaging/root/"$(MACOS_INSTALL_PATH)"/$(CRC_VERSION)/crc-tray-macos.tar.gz
rm packaging/root/"$(MACOS_INSTALL_PATH)"/$(CRC_VERSION)/crc-tray-macos.tar.gz
cp $(HYPERKIT_BUNDLENAME) packaging/root/"$(MACOS_INSTALL_PATH)"/$(CRC_VERSION)/
cp $(BUILD_DIR)/macos-amd64/crc packaging/root/"$(MACOS_INSTALL_PATH)"/$(CRC_VERSION)/
cp LICENSE packaging/darwin/Resources/LICENSE.txt
pkgbuild --analyze --root packaging/root packaging/components.plist
plutil -replace BundleIsRelocatable -bool NO packaging/components.plist
$(BUILD_DIR)/macos-amd64/crc-macos-amd64.pkg: packagedir
./packaging/package.sh $(BUILD_DIR)/macos-amd64
$(BUILD_DIR)/macos-amd64/crc-installer.tar: packagedir
tar -cvf $(BUILD_DIR)/macos-amd64/crc-installer.tar ./packaging
$(GOPATH)/bin/gomod2rpmdeps:
pushd /tmp && GO111MODULE=on go get github.com/cfergeau/gomod2rpmdeps/cmd/gomod2rpmdeps && popd
%.spec: %.spec.in $(GOPATH)/bin/gomod2rpmdeps
@$(GOPATH)/bin/gomod2rpmdeps | sed -e '/__BUNDLED_REQUIRES__/r /dev/stdin' \
-e '/__BUNDLED_REQUIRES__/d' \
-e 's/__VERSION__/'$(CRC_VERSION)'/g' \
-e 's/__OPENSHIFT_VERSION__/'$(BUNDLE_VERSION)'/g' \
$< >$@
%: %.in
@sed -e 's/__VERSION__/'$(CRC_VERSION)'/g' \
-e 's/__OPENSHIFT_VERSION__/'$(BUNDLE_VERSION)'/g' \
$< >$@