-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile.enterprise
109 lines (86 loc) · 3.35 KB
/
Makefile.enterprise
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
# Create the output directory if it does not exist.
ENTERPRISE_BUILD := enterprise/build
$(shell mkdir -p "$(ENTERPRISE_BUILD)")
VERSION := $(shell ./ci/scripts/version.sh)
ARCHES := amd64 arm64 armv7
BINARIES := $(addprefix $(ENTERPRISE_BUILD)/exectrace_$(VERSION)_linux_,$(ARCHES))
IMAGES := $(foreach arch, $(ARCHES), $(ENTERPRISE_BUILD)/exectrace_$(VERSION)_linux_$(arch).tag)
IMAGES_PUSHED := $(foreach image, $(IMAGES), $(image).pushed)
BINARIES_VERSIONLESS := $(addprefix $(ENTERPRISE_BUILD)/exectrace_linux_,$(ARCHES))
IMAGES_VERSIONLESS := $(foreach arch, $(ARCHES), $(ENTERPRISE_BUILD)/exectrace_linux_$(arch).tag)
MAIN_IMAGE := $(ENTERPRISE_BUILD)/exectrace_$(VERSION)_linux.tag
MAIN_IMAGE_PUSHED := $(MAIN_IMAGE).pushed
MAIN_IMAGE_LATEST := $(ENTERPRISE_BUILD)/exectrace_latest_linux.tag
MAIN_IMAGE_LATEST_PUSHED := $(MAIN_IMAGE_LATEST).pushed
.PHONY: clean-enterprise
clean-enterprise:
rm -rf "$(ENTERPRISE_BUILD)"
mkdir -p "$(ENTERPRISE_BUILD)"
.PHONY: build
build: $(BINARIES)
$(BINARIES): $(ENTERPRISE_BUILD)/exectrace_$(VERSION)_linux_%: \
$(shell find . -type f -name '*.go') \
bpf/handler-bpfeb.o \
bpf/handler-bpfel.o
goarch="$*"
goarm=""
if [[ "$${goarch}" == "arm" ]]; then
goarm="7"
elif [[ "$${goarch}" == "armv"* ]] || [[ "$${goarch}" == "arm64v"* ]]; then
goarm="$${goarch//*v/}"
# Remove the v* suffix.
goarch="$${goarch//v*/}"
fi
# TODO: version details
GOOS=linux GOARCH="$${goarch}" GOARM="$${goarm}" go build \
-o "$@" \
./enterprise/cmd/exectrace
$(BINARIES_VERSIONLESS): $(ENTERPRISE_BUILD)/exectrace_linux_%: $(ENTERPRISE_BUILD)/exectrace_$(VERSION)_linux_%
rm -f "$@"
ln "$<" "$@"
$(IMAGES): $(ENTERPRISE_BUILD)/exectrace_$(VERSION)_linux_%.tag: $(ENTERPRISE_BUILD)/exectrace_$(VERSION)_linux_% enterprise/Dockerfile
arch="$*"
image_tag="$$(./enterprise/scripts/image_tag.sh --arch "$${arch}" --version "$(VERSION)")"
# Remap the arch from Golang to Docker.
declare -A arch_map=(
[amd64]="linux/amd64"
[arm64]="linux/arm64"
[arm]="linux/arm/v7"
[armv7]="linux/arm/v7"
)
if [[ "$${arch_map[$${arch}]+exists}" != "" ]]; then
arch="$${arch_map[$${arch}]}"
fi
temp_dir="$$(mktemp -d)"
cp enterprise/Dockerfile "$${temp_dir}/Dockerfile"
cp "$<" "$${temp_dir}/exectrace"
docker build \
--tag "$${image_tag}" \
--build-arg "CODER_VERSION=$(VERSION)" \
"$${temp_dir}"
rm -rf "$${temp_dir}"
echo "$${image_tag}" > "$@"
$(IMAGES_VERSIONLESS): $(ENTERPRISE_BUILD)/exectrace_linux_%.tag: $(ENTERPRISE_BUILD)/exectrace_$(VERSION)_linux_%.tag
rm -f "$@"
ln "$<" "$@"
$(IMAGES_PUSHED): $(ENTERPRISE_BUILD)/exectrace_$(VERSION)_linux_%.tag.pushed: $(ENTERPRISE_BUILD)/exectrace_$(VERSION)_linux_%.tag
docker push "$$(cat "$<")"
cat "$<" > "$@"
# Creating a docker manifest requires the images to be pushed, so this job
# depends on IMAGES_PUSHED instead of IMAGES.
$(MAIN_IMAGE) $(MAIN_IMAGE_LATEST): $(IMAGES_PUSHED)
version="$(VERSION)"
if [[ "$@" == "$(MAIN_IMAGE_LATEST)" ]]; then
version="latest"
fi
image_tag="$$(./enterprise/scripts/image_tag.sh --version "$${version}")"
docker manifest create \
"$${image_tag}" \
$(foreach image, $(IMAGES), "$$(cat "$(image)")")
echo "$${image_tag}" > "$@"
$(MAIN_IMAGE_PUSHED): $(MAIN_IMAGE)
docker manifest push "$$(cat "$<")"
cat "$<" > "$@"
$(MAIN_IMAGE_LATEST_PUSHED): $(MAIN_IMAGE_LATEST)
docker manifest push "$$(cat "$<")"
cat "$<" > "$@"