forked from tinkerbell/osie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules.mk.j2
292 lines (249 loc) · 10.6 KB
/
rules.mk.j2
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
# vim: set filetype=make :
# Only use the recipes defined in these makefiles
MAKEFLAGS += --no-builtin-rules
.SUFFIXES:
# Delete target files if there's an error
# This avoids a failure to then skip building on next run if the output is created by shell redirection for example
.DELETE_ON_ERROR:
# Treat the whole recipe as a one shell script/invocation instead of one-per-line
.ONESHELL:
# Use bash instead of plain sh
SHELL := bash
.SHELLFLAGS := -o pipefail -euc
alpine_version_aarch64 := 3.4
alpine_version_x86_64 := 3.12
arches := aarch64 x86_64
x86s := x86_64
arms := 2a2 aarch64 amp hua qcom tx2
parches := $(sort $(arms) $(x86s))
gitversion=$(shell git rev-parse HEAD)
gitbranch=$(shell git symbolic-ref --short HEAD)
dronebuild=$(shell echo $${DRONE_BUILD:-none})
target_checksum = $(word 4,$(subst -, ,$(1)))
build_path = $(word 3,$(1))/$(word 2,$(1))-vanilla-$(word 1,$(1))
target_to_path = $(call build_path,$(subst -, ,$(1)))
ifdef DRONE_BUILD_NUMBER
ifdef DRONE_COMMIT_SHA
v := ${DRONE_BUILD_NUMBER}-${DRONE_COMMIT_SHA}
endif
endif
ifndef v
v := $(shell git describe --dirty)
endif
# ensure build/osie-$v always exists without having to add as an explicit dependency
$(shell mkdir -p build/osie-$v)
apps := $(shell git ls-files apps/)
cprs := $(shell git ls-files ci/cpr/)
grubs := $(shell git ls-files grub/)
osiesrcs := $(shell git ls-files docker/)
ifeq ($(V),1)
E := :
else
E := @echo
endif
ifeq ($(T),1)
override undefine T
T := stdout
else
override undefine T
T := null
endif
.PHONY: all deploy package package-apps package-grubs test test-aarch64 test-x86_64 v
v:
@echo $v
packaged-apps := $(subst apps/,build/osie-$v/,${apps})
packaged-grubs := $(addprefix build/osie-$v/,$(subst -,/,${grubs}))
packaged-discover-metals := build/osie-$v/discover-metal-x86_64.tar.gz
packaged-osie-runners := build/osie-$v/osie-runner-x86_64.tar.gz
packaged-osies := build/osie-$v/osie-aarch64.tar.gz build/osie-$v/osie-x86_64.tar.gz
packaged-repos := build/osie-$v/repo-aarch64 build/osie-$v/repo-x86_64
packages := ${packaged-apps} ${packaged-grubs} ${packaged-discover-metals} ${packaged-osie-runners} ${packaged-osies} ${packaged-repos}
.PHONY:{% for platform in platforms.keys() %} package-{{platform}}
{%- endfor %}
{% for platform in platforms.keys() -%}
packaged-{{platform}} := build/osie-$v/initramfs-{{platform}} build/osie-$v/modloop-{{platform}} build/osie-$v/vmlinuz-{{platform}}
package-{{platform}}: ${packaged-{{platform}}}
packages += ${packaged-{{platform}}}
{% endfor %}
package-apps: ${packaged-apps}
package-grubs: ${packaged-grubs}
package-osies: ${packaged-osies}
package-repos: ${packaged-repos}
s3Bucket := tinkerbell-oss
ifdef DRONE_PULL_REQUEST
s3Bucket := tinkerbell-oss-pr
endif
deploy-to-s3: package
$(E) "UPLOAD s3/tinkerbell-oss/osie-uploads/osie-$v.tar.gz"
mc cp build/osie-$v.tar.gz s3/${s3Bucket}/osie-uploads/osie-$v.tar.gz
if [[ $${DRONE_BUILD_EVENT:-} == "push" ]] && [[ $${DRONE_BRANCH:-} == "main" ]]; then
mc cp s3/tinkerbell-oss/osie-uploads/osie-$v.tar.gz s3/tinkerbell-oss/osie-uploads/latest.tar.gz
fi
$(E) "UPLOAD s3/tinkerbell-oss/osie-uploads/osie-$v.tar.gz.sha512sum"
mc cp build/osie-$v.tar.gz.sha512sum s3/${s3Bucket}/osie-uploads/osie-$v.tar.gz.sha512sum
if [[ $${DRONE_BUILD_EVENT:-} == "push" ]] && [[ $${DRONE_BRANCH:-} == "main" ]]; then
sed 's| (.*) | (latest.tar.gz) |' build/osie-$v.tar.gz.sha512sum >build/latest.tar.gz.sha512sum
mc cp s3/tinkerbell-oss/osie-uploads/latest.tar.gz.sha512sum s3/tinkerbell-oss/osie-uploads/latest.tar.gz.sha512sum
fi
echo
echo "EM specific info: deploy this build from the deploy-osie repo with the following command:"
echo "./deploy update osie-$v $(shell awk '{print $$NF}' build/osie-$v.tar.gz.sha512sum)"
upload-test: ${packages}
$(E) "UPLOAD s3/tinkerbell-oss/osie-uploads/osie-testing/osie-$v/"
mc cp --recursive build/osie-$v/ s3/tinkerbell-oss/osie-uploads/osie-testing/osie-$v/ || (
session=$$(mc session list --json | jq -r .sessionId)
for i in {1..5}; do
mc session resume $$session && exit 0
done
mc session clear $$sesion
exit 1
)
build/osie-$v.tar.gz: ${packages}
$(E) "TAR.GZ $@"
cd build
tar -cO $(sort $(subst build/,,$^)) | pigz >$(@F)
build/osie-$v.tar.gz.sha512sum: build/osie-$v.tar.gz
$(E) "SHASUM $@"
sha512sum --tag $^ | sed 's|build/||' >$@
${packaged-grubs}: ${grubs}
$(E) "INSTALL $@"
install -Dm644 $(addprefix grub/,$(subst /,-,$(patsubst build/osie-$v/grub/%,%,$@))) $@
build/osie-$v/%-rc: apps/%-rc
$(E) "INSTALL $@"
install -D -m644 $< $@
build/osie-$v/%.sh: apps/%.sh
$(E) "INSTALL $@"
install -D -m644 $< $@
build/osie-$v/%.tar.gz: build/%.tar.gz
$(E) "INSTALL $@"
install -D -m644 $< $@
{% for platform, arch in platforms.items() %}
build/osie-$v/initramfs-{{platform}}: build/osie-$v-rootfs-{{platform}} installer/alpine/init-{{arch}}
$(E) "CPIO $@"
install -m755 installer/alpine/init-{{arch}} build/osie-$v-rootfs-{{platform}}/init
(cd build/osie-$v-rootfs-{{platform}} && find -print0 | bsdcpio --null --quiet -oH newc | pigz -9) >[email protected]
install -D -m644 [email protected] $@
touch $@
{% endfor %}
build/osie-$v/modloop-%: build/modloop-%
$(E) "INSTALL $@"
install -D -m644 $< $@
build/osie-$v/vmlinuz-%: build/vmlinuz-%
$(E) "INSTALL $@"
install -D -m644 $< $@
build/osie-$v/test-initramfs-%/test-initramfs: build/osie-$v/initramfs-% installer/alpine/init-%
$(E) "BUILD $@"
rm -rf $(@D)
mkdir -p $(@D)
cp $^ $(@D)/
mv $(@D)/$(<F) $(@D)/initramfs.cpio.gz
cd $(@D)
sed -i 's|curl |curl --insecure |g' init-*
mv init-* init
chmod +x init
unpigz initramfs.cpio.gz
echo init | cpio -oH newc --append -O initramfs.cpio
pigz -9 initramfs.cpio
mv initramfs.cpio.gz $(@F)
build/osie-test-env: ci/Dockerfile
docker build -t osie-test-env:$v ci 2>&1 | tee [email protected] >/dev/$T
touch $@
{% for arch in platforms.values() | unique | sort -%}
{%- if arch == "aarch64" %}
ifneq ($(CI),drone)
test-{{arch}}: /proc/sys/fs/binfmt_misc/qemu-aarch64
endif
{% endif %}
test-{{arch}}: $(cprs) build/osie-test-env package-apps package-grubs build/osie-$v/osie-{{arch}}.tar.gz build/osie-$v/osie-runner-{{arch}}.tar.gz build/osie-$v/repo-{{arch}} ${packaged-{{arch}}} ci/ifup.sh ci/vm.sh build/osie-$v/test-initramfs-{{arch}}/test-initramfs ## Run VM based tests for {{arch}}
$(E) "DOCKER $@"
ifneq ($(CI),drone)
docker run --rm -ti \
--privileged \
--name $(@F) \
--volume $(CURDIR):/osie:ro \
--env OSES \
--env UEFI \
osie-test-env:$v \
/osie/ci/vm.sh tests -C /osie/build/osie-$v -k vmlinuz-{{arch}} -i test-initramfs-{{arch}}/test-initramfs -m modloop-{{arch}} -a {{arch}} 2>&1 | tee build/[email protected] >/dev/$T
else
ci/vm.sh tests -C build/osie-$v -k vmlinuz-{{arch}} -i test-initramfs-{{arch}}/test-initramfs -m modloop-{{arch}} -a {{arch}} 2>&1 | tee build/[email protected] >/dev/$T
endif
{% endfor %}
build/osie-$v-rootfs-%: build/initramfs-%
$(E) "EXTRACT $@"
rm -rf $@
mkdir $@
bsdtar -xf $< -C $@
build/discover-metal-x86_64.tar.gz:
$(E) "DOCKER $@"
docker pull quay.io/packet/discover-metal 2>&1 | tee [email protected] >/dev/$T
docker save quay.io/packet/discover-metal:latest | pigz >$@
ifneq ($(CI),drone)
build/osie-aarch64.tar.gz: /proc/sys/fs/binfmt_misc/qemu-aarch64
endif
build/osie-aarch64.tar.gz: SED=/FROM/ s|.*|FROM multiarch/ubuntu-debootstrap:arm64-xenial|
build/osie-x86_64.tar.gz: SED=
build/osie-%.tar.gz: docker/Dockerfile ${osiesrcs}
$(E) "DOCKER $@"
sed '${SED}' $< > $<.$*
docker build --squash --build-arg GITVERSION=${gitversion} --build-arg GITBRANCH=${gitbranch} --build-arg DRONEBUILD=${dronebuild} -t osie:$* -f $<.$* $(<D) 2>&1 | tee [email protected] >/dev/$T
docker save osie:$* | pigz >$@
ifneq ($(CI),drone)
build/osie-runner-aarch64.tar.gz: /proc/sys/fs/binfmt_misc/qemu-aarch64
endif
build/osie-runner-aarch64.tar.gz: SED=/FROM/ s|.*|FROM multiarch/alpine:arm64-v3.7|
build/osie-runner-x86_64.tar.gz: SED=
build/osie-runner-%.tar.gz: osie-runner/Dockerfile $(shell git ls-files osie-runner)
$(E) "DOCKER $@"
sed '${SED}' $< > $<.$*
docker build --squash --build-arg GITVERSION=${gitversion} --build-arg GITBRANCH=${gitbranch} --build-arg DRONEBUILD=${dronebuild} -t osie-runner:$* -f $<.$* $(<D) 2>&1 | tee [email protected] >/dev/$T
docker save osie-runner:$* | pigz >$@
build/osie-runner-aarch64.tar.gz:
$(E) "FAKE $@"
touch $@
build/osie-$v/repo-aarch64:
$(E) "LN $@"
ln -nsf ../../../alpine/edge $@
build/repo-aarch64:
echo edge > $@
build/osie-$v/repo-x86_64:
$(E) "LN $@"
ln -nsf ../../../alpine/v${alpine_version_x86_64} $@
build/repo-x86_64:
echo v${alpine_version_x86_64} > $@
{% for platform in platforms %}
build/initramfs-{{platform}}: installer/alpine/assets-{{platform}}/initramfs
build/modloop-{{platform}}: installer/alpine/assets-{{platform}}/modloop
build/vmlinuz-{{platform}}: installer/alpine/assets-{{platform}}/vmlinuz
build/initramfs-{{platform}} build/modloop-{{platform}} build/vmlinuz-{{platform}}:
$(E) "LN $@"
ln -nsf ../$< $@
{% endfor -%}
assets-aarch64: installer/alpine/assets-aarch64/initramfs installer/alpine/assets-aarch64/modloop installer/alpine/assets-aarch64/vmlinuz
ifneq ($(CI),drone)
build/osie-alpine-initramfs-builder-aarch64: /proc/sys/fs/binfmt_misc/qemu-aarch64
endif
build/osie-alpine-initramfs-builder-aarch64: installer/alpine/Dockerfile installer/alpine/build.sh installer/alpine/eclypsiumdriver-alpine-* installer/alpine/qemu-aarch64-static
$(E) "IMAGE $@"
sed '/^FROM alpine/ s| .*| arm64v8/alpine:3.6\nCOPY qemu-aarch64-static /usr/bin|' installer/alpine/Dockerfile >installer/alpine/Dockerfile.aarch64
docker build -f installer/alpine/Dockerfile.aarch64 -t $@ installer/alpine/ 2>&1 | tee [email protected] >/dev/$T
touch $@
assets-x86_64: installer/alpine/assets-x86_64/initramfs installer/alpine/assets-x86_64/modloop installer/alpine/assets-x86_64/vmlinuz
build/osie-alpine-initramfs-builder-x86_64: installer/alpine/Dockerfile installer/alpine/build.sh installer/alpine/eclypsiumdriver-alpine-*
$(E) "IMAGE $@"
docker build -f installer/alpine/Dockerfile -t $@ installer/alpine/ 2>&1 | tee [email protected] >/dev/$T
touch $@
installer/alpine/assets-x86_64/initramfs installer/alpine/assets-x86_64/modloop installer/alpine/assets-x86_64/vmlinuz: build/osie-alpine-initramfs-builder-x86_64
$(E) "BUILD $@"
docker run --rm -v ${PWD}/${@D}/:/assets/ --name=osie-assets-x86_64-${@F} $< ${@F} 2>&1 | tee build/osie-assets-x86_64-${@F}.log >/dev/$T
installer/alpine/qemu-aarch64-static:
$(E) "GET $@"
wget https://github.com/multiarch/qemu-user-static/releases/download/v5.0.0-2/$(@F) -O $@
chmod 755 $@
/proc/sys/fs/binfmt_misc/qemu-aarch64:
$(E) 'You need to configure qemu-aarch64-static for aarch64 programs, for example:'
$(E) ''
$(E) ' docker run --rm --privileged multiarch/qemu-user-static:register --reset'
$(E) ''
$(E) 'and can disable all binfmt with:'
$(E) ''