-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathMakefile
More file actions
489 lines (408 loc) · 21.1 KB
/
Makefile
File metadata and controls
489 lines (408 loc) · 21.1 KB
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
GO ?= go
# Files are installed under $(DESTDIR)/$(PREFIX)
PREFIX ?= $(CURDIR)/_output
DEST := $(shell echo "$(DESTDIR)/$(PREFIX)" | sed 's:///*:/:g; s://*$$::')
BINDIR ?= /usr/local/bin
OUTDIR ?= $(CURDIR)/_output
OS_OUTDIR ?= $(OUTDIR)/os
COVERAGE_DIR ?= $(CURDIR)/cov
REPORT_DIR ?= $(CURDIR)/reports
RUN_ID ?= $(GITHUB_RUN_ID)
RUN_ATTEMPT ?= $(GITHUB_RUN_ATTEMPT)
FINCH_CORE_DIR := $(CURDIR)/deps/finch-core
OUTPUT_DIRECTORIES := $(OUTDIR) $(OS_OUTDIR)
$(OUTPUT_DIRECTORIES):
@mkdir -p $@
PACKAGE := github.com/runfinch/finch
BINARYNAME := finch
LIMA_FILENAME := lima
LIMA_EXTENSION := .tar.gz
# Created by the CLI after installation, only used in uninstall step
LIMA_VDE_SUDOERS_FILE := /etc/sudoers.d/finch-lima
# Final installation prefix for vde created by CLI after installation, only used in uninstall step
VDE_INSTALL ?= /opt/finch
ARCH ?= $(shell uname -m)
SUPPORTED_ARCH = false
LICENSEDIR := $(OUTDIR)/license-files
VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.modified' --abbrev=0 --always --tags)
GITCOMMIT ?= $(shell git rev-parse HEAD)$(shell test -z "$(git status --porcelain)" || echo .m)
VERSION_INJECTION := -X $(PACKAGE)/pkg/version.Version=$(VERSION)
VERSION_INJECTION += -X $(PACKAGE)/pkg/version.GitCommit=$(GITCOMMIT)
VERSION_INJECTION += -X $(PACKAGE)/pkg/version.GitCommit=$(GITCOMMIT)
MIN_MACOS_VERSION ?= 11.0
# Inject soci version
-include $(FINCH_CORE_DIR)/deps/soci.conf
VERSION_INJECTION += -X $(PACKAGE)/pkg/config.SociVersion=$(SOCI_VERSION)
VERSION_INJECTION += -X $(PACKAGE)/pkg/config.SociAMD64Sha256Sum=$(SOCI_AMD64_SHA256_DIGEST)
VERSION_INJECTION += -X $(PACKAGE)/pkg/config.SociARM64Sha256Sum=$(SOCI_ARM64_SHA256_DIGEST)
# Inject ecr-cred-helper version
-include $(FINCH_CORE_DIR)/deps/ecr-cred-helper.conf
VERSION_INJECTION += -X $(PACKAGE)/pkg/dependency/credhelper.EcrVersion=$(ECR_CRED_HELPER_VERSION)
VERSION_INJECTION += -X $(PACKAGE)/pkg/dependency/credhelper.EcrAMD64Hash=$(ECR_CRED_HELPER_AMD64_DIGEST)
VERSION_INJECTION += -X $(PACKAGE)/pkg/dependency/credhelper.EcrARM64Hash=$(ECR_CRED_HELPER_ARM64_DIGEST)
FINCH_DAEMON_LOCATION_ROOT ?= $(FINCH_OS_IMAGE_LOCATION_ROOT)/finch-daemon
FINCH_DAEMON_LOCATION ?= $(FINCH_DAEMON_LOCATION_ROOT)/finch-daemon
FINCH_DAEMON_CREDHELPER_LOCATION ?= $(FINCH_DAEMON_LOCATION_ROOT)/docker-credential-finch
FINCH_CRED_LOCATION_ROOT ?= $(FINCH_OS_IMAGE_LOCATION_ROOT)/finch-cred
FINCH_CREDSERVER_LOCATION ?= $(FINCH_CRED_LOCATION_ROOT)/credserver
FINCHHOST_CREDHELPER_LOCATION ?= $(FINCH_CRED_LOCATION_ROOT)/docker-credential-finchhost
GOOS ?= $(shell $(GO) env GOOS)
ifeq ($(GOOS),windows)
BINARYNAME := $(addsuffix .exe, $(BINARYNAME))
endif
.DEFAULT_GOAL := all
INSTALLED ?= false
REGISTRY ?= ""
ifneq (,$(findstring arm64,$(ARCH)))
SUPPORTED_ARCH = true
LIMA_ARCH = aarch64
else ifneq (,$(findstring x86_64,$(ARCH)))
SUPPORTED_ARCH = true
LIMA_ARCH = x86_64
endif
# This variable is used to inject the version of Lima (via ldflags) to be used with Lima's
# osutil.LimaUser function.
-include $(FINCH_CORE_DIR)/deps/lima-bundles.conf
# This value isn't used on Linux, but the symbol is currently defined on all platforms, so
# it doesn't hurt to always inject it right now.
VERSION_INJECTION += -X $(PACKAGE)/pkg/lima.LimaVersion=$(LIMA_VERSION)
LDFLAGS = "-w $(VERSION_INJECTION)"
.PHONY: arch-test
arch-test:
@if [ $(SUPPORTED_ARCH) != "true" ]; then echo "Unsupported architecture: $(ARCH)"; exit "1"; fi
# OS will be set on Windows (to Windows_NT), and undefined otherwise unless
# it is explicity specified on the commandline.
# On Unix (or, not-Windows), query OS and set it using uname -s
BUILD_OS ?= $(OS)
ifeq ($(BUILD_OS),)
BUILD_OS = $(shell uname -s)
endif
remote-all: arch-test finch install.finch-core-dependencies finch.yaml networks.yaml config.yaml $(OUTDIR)/finch-daemon/finch@.service
ifeq ($(BUILD_OS), Windows_NT)
include Makefile.windows
all: remote-all
else ifeq ($(BUILD_OS), Darwin)
include Makefile.darwin
all: remote-all
else ifeq ($(BUILD_OS), Linux)
# on Linux, we only need to build "finch"
all: finch
endif
.PHONY: install.finch-core-dependencies
install.finch-core-dependencies:
OUTDIR=$(OUTDIR) ARCH=$(ARCH) "$(MAKE)" -C $(FINCH_CORE_DIR) install.dependencies
# For Finch on macOS and Windows, the container runtime archive locations and digests are set
# based on the values set in deps/finch-core/deps/container-runtime-full-archive.conf
-include $(FINCH_CORE_DIR)/deps/container-runtime-full-archive.conf
CONTAINER_RUNTIME_ARCHIVE_AARCH64_LOCATION ?= "$(ARTIFACT_BASE_URL)/$(AARCH64_ARTIFACT)"
CONTAINER_RUNTIME_ARCHIVE_AARCH64_DIGEST ?= "sha256:$(AARCH64_256_DIGEST)"
CONTAINER_RUNTIME_ARCHIVE_X86_64_LOCATION ?= "$(ARTIFACT_BASE_URL)/$(X86_64_ARTIFACT)"
CONTAINER_RUNTIME_ARCHIVE_X86_64_DIGEST ?= "sha256:$(X86_64_256_DIGEST)"
# Inject dependency versions for E2E VM serial tests
E2E_VM_VERSION_INJECTION := $(VERSION_INJECTION)
E2E_VM_VERSION_INJECTION += -X $(PACKAGE)/e2e/vm.NerdctlVersion=v$(NERDCTL_VERSION)
E2E_VM_VERSION_INJECTION += -X $(PACKAGE)/e2e/vm.ContainerdVersion=v$(CONTAINERD_VERSION)
E2E_VM_VERSION_INJECTION += -X $(PACKAGE)/e2e/vm.BuildKitVersion=v$(BUILDKIT_VERSION)
E2E_VM_VERSION_INJECTION += -X $(PACKAGE)/e2e/vm.RuncVersion=$(RUNC_VERSION)
E2E_VM_LDFLAGS := -w $(E2E_VM_VERSION_INJECTION)
.PHONY: finch.yaml
finch.yaml: $(OS_OUTDIR)/finch.yaml
.PHONY: networks.yaml
networks.yaml:
# networking configuration
mkdir -p $(OUTDIR)/lima/data/_config/
cp networks.yaml $(OUTDIR)/lima/data/_config/
.PHONY: config.yaml
config.yaml:
cp config.yaml $(OUTDIR)/config.yaml
.PHONY: copy
copy:
mkdir -p $(DEST)
(cd _output && tar -cf - * | tar -xvf - -C $(DEST) )
.PHONY: install
install: copy
sudo ln -sf $(DEST)/bin/finch "$(BINDIR)/finch"
@if [ -f $(DEST)/cred-helpers/docker-credential-osxkeychain ]; then \
sudo ln -sf $(DEST)/cred-helpers/docker-credential-osxkeychain "$(BINDIR)/docker-credential-osxkeychain"; \
fi
uninstall.finch:
@test -f "$(BINDIR)/$(BINARYNAME)" || echo "finch not found in $(BINDIR) prefix"
if [ "$$(readlink "$(BINDIR)/$(BINARYNAME)")" = "$(DEST)/bin/$(BINARYNAME)" ]; then sudo rm "$(BINDIR)/$(BINARYNAME)"; fi
if [ "$$(readlink "$(BINDIR)/docker-credential-osxkeychain")" = "$(DEST)/cred-helpers/docker-credential-osxkeychain" ]; then sudo rm "$(BINDIR)/docker-credential-osxkeychain"; fi
-@rm -rf $(DEST)/bin 2>/dev/null || true
-@rm -rf $(DEST)/lima 2>/dev/null || true
-@rm -rf $(DEST)/os 2>/dev/null || true
-@rm -rf $(DEST)/dependencies 2>/dev/null || true
.PHONY: uninstall.vde
uninstall.vde:
sudo rm -rf $(VDE_INSTALL)
sudo rm -rf $(LIMA_VDE_SUDOERS_FILE)
.PHONY: uninstall
uninstall: uninstall.finch
.PHONY: finch
ifeq ($(GOOS),windows)
finch: finch-windows finch-all
else ifeq ($(GOOS),darwin)
finch: finch-macos
else ifeq ($(NATIVE_BUILD),true)
finch: finch-native
else
finch: finch-all
endif
finch-windows:
GOBIN=$(GOBIN) go install github.com/tc-hib/go-winres
$(GO) generate cmd/finch/main_windows.go
finch-macos: export CGO_CFLAGS := -mmacosx-version-min=$(MIN_MACOS_VERSION)
finch-macos: export CGO_LDFLAGS := -mmacosx-version-min=$(MIN_MACOS_VERSION)
finch-macos: finch-unix
finch-unix: finch-all
finch-native: GO_BUILD_TAGS += native
finch-native: finch-all
E2E_COVERAGE ?=
finch-all:
$(GO) build $(if $(E2E_COVERAGE),-cover) -ldflags $(LDFLAGS) -tags "$(GO_BUILD_TAGS)" -o $(OUTDIR)/bin/$(BINARYNAME) $(PACKAGE)/cmd/finch
"$(MAKE)" build-credential-helper
"$(MAKE)" build-credential-daemon
.PHONY: build-credential-helper
build-credential-helper:
ifeq ($(GOOS),darwin)
# Build finchhost credential helper for VM
GOOS=linux GOARCH=$(shell go env GOARCH) $(GO) build -ldflags $(LDFLAGS) -o $(OUTDIR)/finch-cred/docker-credential-finchhost $(PACKAGE)/cmd/finchhost-credential-helper
endif
.PHONY: build-credential-daemon
build-credential-daemon:
ifeq ($(GOOS),darwin)
# Build credential daemon for host
$(GO) build -ldflags $(LDFLAGS) -o $(OUTDIR)/finch-cred/credserver $(PACKAGE)/cmd/credserver
endif
.PHONY: release
release: check-licenses all download-licenses
$(OUTDIR)/finch-daemon/finch@.service:
cp finch@.service $(OUTDIR)/finch-daemon/finch@.service
.PHONY: coverage
coverage:
go test $(shell go list ./... | grep -v e2e | grep -v benchmark | grep -v mocks)
go tool cover -html=test-coverage.out
.PHONY: download-licenses
# Licenses of all the third-party dependencies must be downloaded in this build target
# because we need to include them in our release for legal reasons.
# These dependencies include Go modules in go.mod, Github Actions in .github/workflows, system-level dependencies (e.g., lima), etc.
#
# Dependencies in pkg/tools.go need to be manually added below. For more details, see the comments of `check-licenses`.
# Note that technically we don't need to explicitly download all of them (e.g., mockgen; see the next paragraph re. lima for more details),
# but it's just easier to have one entry here for each entry in `pkg/tools.go` instead of trying to understand which are not needed.
#
# At the time of writing, technically we don't need to explicitly download lima,
# but we still choose to do so because `go-licenses save` takes care of code-level dependencies,
# while lima is more like a system-level dependency, and it just happens to be also a code-level dependency right now,
# but it could be removed from go.mod one day, so it may be better to make it clear here.
download-licenses: GOBIN = $(CURDIR)/tools_bin
download-licenses:
GOBIN=$(GOBIN) go install github.com/google/go-licenses
$(GOBIN)/go-licenses save ./... --save_path="$(LICENSEDIR)" --force --include_tests
### dependencies in tools.go - start ###
# for go.uber.org/mock/mockgen
mkdir -p "$(LICENSEDIR)/go.uber.org/mock"
curl https://raw.githubusercontent.com/golang/mock/main/LICENSE --output "$(LICENSEDIR)/go.uber.org/mock/LICENSE"
# for github.com/google/go-licenses
mkdir -p "$(LICENSEDIR)/github.com/google/go-licenses"
curl https://raw.githubusercontent.com/google/go-licenses/master/LICENSE --output "$(LICENSEDIR)/github.com/google/go-licenses/LICENSE"
# for golang.org/x/tools/cmd/stringer
mkdir -p "$(LICENSEDIR)/golang.org/x/tools"
chmod -R u+w "$(LICENSEDIR)/golang.org/x/tools" 2>/dev/null || true
curl https://raw.githubusercontent.com/golang/tools/master/LICENSE --output "$(LICENSEDIR)/golang.org/x/tools/LICENSE"
### dependencies in tools.go - end ###
### dependencies in benchmark.yaml - start ###
mkdir -p "$(LICENSEDIR)/github.com/benchmark-action/github-action-benchmark"
curl https://raw.githubusercontent.com/benchmark-action/github-action-benchmark/master/LICENSE.txt --output "$(LICENSEDIR)/github.com/benchmark-action/github-action-benchmark/LICENSE.txt"
### dependencies in benchmark.yaml - end ###
### dependencies in ci.yaml - start ###
mkdir -p "$(LICENSEDIR)/github.com/actions/checkout"
curl https://raw.githubusercontent.com/actions/checkout/main/LICENSE --output "$(LICENSEDIR)/github.com/actions/checkout/LICENSE"
mkdir -p "$(LICENSEDIR)/github.com/actions/setup-go"
curl https://raw.githubusercontent.com/actions/setup-go/main/LICENSE --output "$(LICENSEDIR)/github.com/actions/setup-go/LICENSE"
mkdir -p "$(LICENSEDIR)/github.com/golangci/golangci-lint-action"
curl https://raw.githubusercontent.com/golangci/golangci-lint-action/master/LICENSE --output "$(LICENSEDIR)/github.com/golangci/golangci-lint-action/LICENSE"
mkdir -p "$(LICENSEDIR)/github.com/avto-dev/markdown-lint"
curl https://raw.githubusercontent.com/avto-dev/markdown-lint/master/LICENSE --output "$(LICENSEDIR)/github.com/avto-dev/markdown-lint/LICENSE"
mkdir -p "$(LICENSEDIR)/github.com/ludeeus/action-shellcheck"
curl https://raw.githubusercontent.com/ludeeus/action-shellcheck/blob/2.0.0/LICENSE --output "$(LICENSEDIR)/github.com/ludeeus/action-shellcheck/LICENSE"
### dependencies in ci.yaml - end ###
### dependencies in lint-pr-title.yaml - start ###
mkdir -p "$(LICENSEDIR)/github.com/amannn/action-semantic-pull-request"
curl https://raw.githubusercontent.com/amannn/action-semantic-pull-request/main/LICENSE --output "$(LICENSEDIR)/github.com/amannn/action-semantic-pull-request/LICENSE"
### dependencies in lint-pr-title.yaml - end ###
### dependencies in release-please.yaml - start ###
mkdir -p "$(LICENSEDIR)/github.com/googleapis/release-please"
curl https://raw.githubusercontent.com/googleapis/release-please/main/LICENSE --output "$(LICENSEDIR)/github.com/googleapis/release-please/LICENSE"
### dependencies in release-please.yaml - end ###
### system-level dependencies - start ###
mkdir -p "$(LICENSEDIR)/github.com/lima-vm/lima"
curl https://raw.githubusercontent.com/lima-vm/lima/master/LICENSE --output "$(LICENSEDIR)/github.com/lima-vm/lima/LICENSE"
### system-level dependencies - end ###
.PHONY: check-licenses
# Guidelines:
#
# - The dependencies in pkg/tools.go are not included, so one has to manually verify the license when a new tool is added.
# According to https://github.com/google/go-licenses#build-tags,
# we could use `GOFLAGS="-tags=tools"` to include the file, but the following error will occur:
# `import "golang.org/x/tools/cmd/stringer" is a program, not an importable package`.
# - There are many allowed licenses, but to keep things easy to follow, below we only list the ones currently used by our dependencies.
#
# Explanations:
#
# - golang.org/x dependencies are ignored because some of them incur the following warning:
# `contains non-Go code that can't be inspected for further dependencies`, which can clutter the output.
# They can be safely ignored because they are still part of the Go Project according to https://pkg.go.dev/golang.org/x,
# so they should be the same as the standard library license-wise.
# - github.com/runfinch/finch is ignored because we don't have to check our own license.
# Moreover, if we don't ignore it, the following error will occur:
# `module github.com/runfinch/finch has empty version, defaults to HEAD. The license URL may be incorrect. Please verify!`.
# `module github.com/multiformats/go-base36 has a Apache license and MIT license but not written as LICENSE format`
check-licenses: GOBIN = $(CURDIR)/tools_bin
check-licenses:
go mod download
GOBIN=$(GOBIN) go install github.com/google/go-licenses
$(GOBIN)/go-licenses check --ignore golang.org/x,github.com/runfinch/finch --ignore github.com/multiformats/go-base36 --allowed_licenses Apache-2.0,BSD-2-Clause,BSD-3-Clause,ISC,MIT,MPL-2.0 --include_tests ./...
COVERAGE_THRESH = 60
.PHONY: add-credhelper-to-path
add-credhelper-to-path:
ifeq ($(GOOS),darwin)
@if [ -f $(OUTDIR)/cred-helpers/docker-credential-osxkeychain ]; then \
chmod +x $(OUTDIR)/cred-helpers/docker-credential-osxkeychain; \
codesign -s - -f $(OUTDIR)/cred-helpers/docker-credential-osxkeychain; \
sudo ln -sf $(OUTDIR)/cred-helpers/docker-credential-osxkeychain /usr/local/bin/docker-credential-osxkeychain; \
fi
endif
.PHONY: test-unit
test-unit:
go test -coverprofile=coverage.out $(shell go list ./... | grep -v e2e | grep -v benchmark | grep -v mocks | grep -v version | grep -v flog | grep -v system | grep -v fmemory | grep -v coverage | grep -v devcontainer_patch) -shuffle on
go run coverage/coverage.go $(COVERAGE_THRESH)
# test-e2e assumes the VM instance doesn't exist, please make sure to remove it before running.
#
# Container tests and VM tests can be run in any order, but they must be run sequentially.
# For more details, see the package-level comment of the e2e package.
.PHONY: create-coverage-dir
create-coverage-dir:
mkdir -p $(COVERAGE_DIR)
.PHONY: create-report-dir
create-report-dir:
mkdir -p $(REPORT_DIR)
.PHONY: test-e2e
test-e2e: test-e2e-vm-serial test-e2e-container
.PHONY: test-e2e-vm-serial
test-e2e-vm-serial: create-report-dir create-coverage-dir add-credhelper-to-path
FINCH_GOCOVERDIR=$(COVERAGE_DIR) go test -coverpkg=./... -ldflags "$(E2E_VM_LDFLAGS)" -timeout 2h ./e2e/vm -test.v -test.gocoverdir=$(COVERAGE_DIR) -ginkgo.vv -ginkgo.timeout=2h -ginkgo.flake-attempts=3 -ginkgo.json-report=$(REPORT_DIR)/$(RUN_ID)-$(RUN_ATTEMPT)-e2e-vm-serial-report.json --installed="$(INSTALLED)"
.PHONY: test-e2e-container
test-e2e-container: create-report-dir create-coverage-dir add-credhelper-to-path
FINCH_GOCOVERDIR=$(COVERAGE_DIR) go test -coverpkg=./... -ldflags $(LDFLAGS) -timeout 2h ./e2e/container -test.v -test.gocoverdir=$(COVERAGE_DIR) -ginkgo.vv -ginkgo.timeout=2h -ginkgo.flake-attempts=3 -ginkgo.json-report=$(REPORT_DIR)/$(RUN_ID)-$(RUN_ATTEMPT)-e2e-container-report.json --installed="$(INSTALLED)"
.PHONY: test-e2e-vm
test-e2e-vm: create-report-dir create-coverage-dir
FINCH_GOCOVERDIR=$(COVERAGE_DIR) go test -coverpkg=./... -ldflags "$(E2E_VM_LDFLAGS)" -timeout 2h ./e2e/vm -test.v -test.gocoverdir=$(COVERAGE_DIR) -ginkgo.vv -ginkgo.timeout=2h -ginkgo.flake-attempts=3 -ginkgo.json-report=$(REPORT_DIR)/$(RUN_ID)-$(RUN_ATTEMPT)-e2e-vm-report.json --installed="$(INSTALLED)" --registry="$(REGISTRY)"
.PHONY: test-e2e-cov
test-e2e-cov:
go tool covdata percent -i=$(COVERAGE_DIR) -pkg=$(shell go list ./... | grep -v e2e | grep -v benchmark | grep -v version | tr '\n' ',')
GINKGO = go run github.com/onsi/ginkgo/v2/ginkgo
# Common ginkgo options: -v for verbose mode, --focus="test name" for running single tests
GFLAGS ?= --race --randomize-all --randomize-suites
ifeq ($(INSTALLED),true)
DAEMON_DOCKER_HOST := "unix:///Applications/Finch/lima/data/finch/sock/finch.sock"
else
DAEMON_DOCKER_HOST := "unix://$(OUTDIR)/lima/data/finch/sock/finch.sock"
endif
.PHONY: test-e2e-daemon
test-e2e-daemon:
-@$(OUTDIR)/bin/$(BINARYNAME) vm stop -f || true
-@$(OUTDIR)/bin/$(BINARYNAME) vm remove -f
-@$(OUTDIR)/bin/$(BINARYNAME) vm init
@echo '{}' > $(HOME)/.finch/config.json
cd $(FINCH_CORE_DIR)/src/finch-daemon && \
STATIC=1 GOOS=linux GOARCH=$(GOARCH) make && \
DOCKER_CONFIG="$(HOME)/.finch" \
DOCKER_HOST=$(DAEMON_DOCKER_HOST) \
DOCKER_API_VERSION="v1.41" \
TEST_E2E=1 \
go test ./e2e -timeout 30m -test.v -ginkgo.vv \
-ginkgo.randomize-all -ginkgo.flake-attempts=3 \
-ginkgo.json-report=$(REPORT_DIR)/$(RUN_ID)-$(RUN_ATTEMPT)-e2e-daemon-report.json \
--subject="$(OUTDIR)/bin/$(BINARYNAME)" \
--daemon-context-subject-prefix="$(OUTDIR)/lima/bin/limactl shell finch sudo" \
--daemon-context-subject-env="LIMA_HOME=$(OUTDIR)/lima/data"
# TODO: Blkio devices are not getting created in test environment, skipping for now
.PHONY: test-e2e-daemon-linux
test-e2e-daemon-linux:
# Create symlink for buildkit socket path compatibility
mkdir -p /run/buildkit
mkdir -p /var/lib/finch/buildkit
ln -sf /var/lib/finch/buildkit/buildkitd.sock /run/buildkit/buildkitd.sock || true
cd $(FINCH_CORE_DIR)/src/finch-daemon && \
DOCKER_HOST="unix:///run/finch.sock" \
DOCKER_API_VERSION="v1.41" \
TEST_E2E=1 \
go test ./e2e -p 1 -timeout 2h -test.v -ginkgo.vv \
-ginkgo.flake-attempts=3 \
-ginkgo.skip="should create container with specified blkio settings options" \
-ginkgo.randomize-all -ginkgo.json-report=$(REPORT_DIR)/$(RUN_ID)-$(RUN_ATTEMPT)-e2e-daemon-report.json \
--subject="/usr/bin/finch"
.PHONY: test-benchmark
test-benchmark:
cd benchmark/all && go test -ldflags $(LDFLAGS) -bench=. -benchmem --installed="$(INSTALLED)"
.PHONY: test-benchmark-vm
test-benchmark-vm:
cd benchmark/vm && go test -ldflags $(LDFLAGS) -bench=. -benchmem --installed="$(INSTALLED)"
.PHONY: test-benchmark-container
test-benchmark-container:
cd benchmark/container && go test -ldflags $(LDFLAGS) -bench=. -benchmem --installed="$(INSTALLED)"
.PHONY: gen-code
# Since different projects may have different versions of tool binaries,
# GOBIN is introduced to maintain a set of tool binaries dedicated to our project use.
#
# To add a new tool binary to the recipe below, please also checkout out `pkg/tools.go`.
gen-code: GOBIN = $(CURDIR)/tools_bin
gen-code:
GOBIN=$(GOBIN) go install go.uber.org/mock/mockgen
GOBIN=$(GOBIN) go install golang.org/x/tools/cmd/stringer
# Make sure that we are using the tool binaries which are just built to generate code.
ifeq ($(GOOS),windows)
powershell ./scripts/gen-code-windows.ps1
else
PATH=$(GOBIN):$(PATH) go generate ./...
endif
.PHONY: lint
# To run golangci-lint locally: https://golangci-lint.run/usage/install/#local-installation
lint:
env GOOS=windows golangci-lint run
env GOOS=darwin golangci-lint run
.PHONY: mdlint
# Install it locally: https://github.com/igorshubovych/markdownlint-cli#installation
# Or see `mdlint-ctr` below or https://github.com/DavidAnson/markdownlint#related.
mdlint:
markdownlint --ignore CHANGELOG.md '**/*.md'
.PHONY: mdlint-ctr
# If markdownlint is not installed, you can run markdownlint within a container.
mdlint-ctr:
$(BINARYNAME) run --rm -v "$(shell pwd):/repo:ro" -w /repo avtodev/markdown-lint:v1 --ignore CHANGELOG.md '**/*.md'
.PHONY: clean
ifeq ($(GOOS),windows)
clean:
-@rm -rf $(OUTDIR) 2>/dev/null || true
-@"$(MAKE)" -C $(FINCH_CORE_DIR) clean
-@rm ./*.tar.gz 2>/dev/null || true
-@rm ./*.qcow2 2>/dev/null || true
-@rm ./test-coverage.* 2>/dev/null || true
else
clean:
-sudo pkill '^socket_vmnet'
-sudo pkill '^qemu-system-'
-sudo pkill '^limactl'
-sudo rm -rf "/opt/finch/"
-sudo rm -rf "/private/var/run/finch-lima"
-sudo rm -rf "/private/etc/sudoers.d/finch-lima"
-@rm -rf $(OUTDIR) 2>/dev/null || true
-@$(MAKE) -C $(FINCH_CORE_DIR) clean
-@rm ./*.tar.gz 2>/dev/null || true
-@rm ./*.qcow2 2>/dev/null || true
-@rm ./test-coverage.* 2>/dev/null || true
endif