forked from harvester/eventrouter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
119 lines (87 loc) · 2.79 KB
/
Copy pathMakefile
File metadata and controls
119 lines (87 loc) · 2.79 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
ROOT := $(realpath $(dir $(realpath $(firstword $(MAKEFILE_LIST)))))
comma := ,
# some systems require opt-in for buildx
DOCKER_BUILDKIT := 1
export DOCKER_BUILDKIT
ifdef CI
BOLD :=
CYAN :=
RESET :=
else
BOLD := \033[1m
CYAN := \033[36m
RESET := \033[0m
endif
BANNER = @printf "$(BOLD)$(CYAN)[target: $@]$(RESET)\n"
# Allocate a TTY in dev (for ctrl+c) but not in CI
MK_DOCKER_RUN_OPTS_TTY := $(if $(CI),,-it)
export MK_DOCKER_RUN_OPTS_TTY
# Safely detect a unique system identifier into a variable
MK_SYSTEM_ID := $(strip $(shell \
if [ -s /etc/machine-id ]; then \
cat /etc/machine-id 2>/dev/null; \
elif command -v hostname >/dev/null 2>&1; then \
hostname 2>/dev/null; \
else \
echo -n "unknown"; \
fi))
# User might have several repos in a host. Distinguish each by using the abs path of the repo
MK_REPO_ID := $(shell \
if command -v sha256sum >/dev/null 2>&1; then \
printf '%s' "$(ROOT)$(MK_SYSTEM_ID)" | sha256sum | cut -c1-8; \
else \
printf '%s' "$(ROOT)$(MK_SYSTEM_ID)" | shasum -a 256 | cut -c1-8; \
fi)
export MK_REPO_ID
MK_DOCKER_PROGRESS ?= plain
export MK_DOCKER_PROGRESS
MK_VALIDATE_CACHE_IMAGE := eventrouter-image-builder-validate-cache:$(MK_REPO_ID)
MK_TEST_CACHE_IMAGE := eventrouter-image-builder-test-cache:$(MK_REPO_ID)
# Legacy dapper env variables
REPO ?=
TAG ?=
export REPO TAG
MK_HOST_ARCH := $(shell uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
export MK_HOST_ARCH
DOCKER_BUILD = docker build \
--progress=$(MK_DOCKER_PROGRESS) \
--build-arg MK_REPO_ID \
--build-arg MK_HOST_ARCH \
-f $(ROOT)/Dockerfile $(ROOT)
.PHONY: build ci default package release test validate gen-version-env gen-version-env-debug clean-all
# ---- Directories ----
$(ROOT)/bin:
@mkdir -p $@
# ---- Pre-generate version env for container builds (no .git needed inside Docker) ----
# Also handles git worktree checkouts where .git is a pointer file to an external directory.
gen-version-env:
$(BANNER)
@bash $(ROOT)/scripts/version > /dev/null
# ---- Generate and show the version env for debugging ----
gen-version-env-debug:
$(BANNER)
@bash $(ROOT)/scripts/version debug
# ---- Compile eventrouter binaries ----
build: gen-version-env | $(ROOT)/bin
$(BANNER)
$(DOCKER_BUILD) --target build-output --output type=local,dest=.
# ---- Validate ----
validate: gen-version-env
$(BANNER)
$(DOCKER_BUILD) --target validate -t $(MK_VALIDATE_CACHE_IMAGE)
# ---- Test ----
test: gen-version-env
$(BANNER)
$(DOCKER_BUILD) --target test -t $(MK_TEST_CACHE_IMAGE)
# ---- Package eventrouter image ----
package: build
$(BANNER)
ARCH=$(MK_HOST_ARCH) $(ROOT)/scripts/package
# ---- Clean cached images ----
clean-all:
$(BANNER)
@docker rmi -f $(MK_VALIDATE_CACHE_IMAGE) $(MK_TEST_CACHE_IMAGE) || true
.DEFAULT_GOAL := ci
ci: build package validate test
default: build package
release: ci