forked from tinkerbell/osie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules.mk.j2
262 lines (224 loc) · 8.2 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
alpine_version_aarch64 := 3.4
alpine_version_x86_64 := 3.7
arches := aarch64 x86_64
x86s := x86_64
arms := 2a2 aarch64 amp hua qcom tx2
parches := $(sort $(arms) $(x86s))
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)))
SHELL := bash
.SHELLFLAGS := -o pipefail -c
.SUFFIXES:
MAKEFLAGS += --no-builtin-rules
v := $(shell git describe --dirty)
ifeq (-g,$(findstring -g,$v))
build_git_version := true
endif
ifeq (-dirty,$(findstring -dirty,$v))
build_git_version := true
endif
ifeq (true,${build_git_version})
t := $(word 1, $(subst -, ,$v))
n := $(word 2, $(subst -, ,$v))
c := $(shell git rev-parse --short HEAD)
d := ,dirty
d := $(subst dirty,$d,$(findstring dirty,$v))
b := $(shell git symbolic-ref HEAD | sed -e 's|^refs/heads/||' -e 's|/|-|g' -e 's|^|,b=|')
v := $t-n=$n,c=$c$b$d
v := $(patsubst %dirty,dirty,$v)
endif
v := osie-$v
# ensure build/$v always exists without having to add as an explicit dependency
$(shell mkdir -p build/$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/)
E=@echo
E+=
ifeq ($(V),1)
Q=
else
Q=@
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-aarch6 test-x86_64 test-packet-networking v
all: build/$v/osie-aarch64.tar.gz build/$v/osie-x86_64.tar.gz
test: test-aarch64 test-x86_64 test-packet-networking
v:
@echo $v
packaged-apps := $(subst apps/,build/$v/,${apps})
packaged-grubs := $(addprefix build/$v/,$(subst -,/,${grubs}))
packaged-osie-runners := build/$v/osie-runner-x86_64.tar.gz
packaged-osies := build/$v/osie-aarch64.tar.gz build/$v/osie-x86_64.tar.gz
packaged-repos := build/$v/repo-aarch64 build/$v/repo-x86_64
packages := ${packaged-apps} ${packaged-grubs} ${packaged-osie-runners} ${packaged-osies} ${packaged-repos}
.PHONY:{% for platform in platforms.keys() %} package-{{platform}}
{%- endfor %}
{% for platform in platforms.keys() -%}
packaged-{{platform}} := build/$v/initramfs-{{platform}} build/$v/modloop-{{platform}} build/$v/vmlinuz-{{platform}}
package-{{platform}}: ${packaged-{{platform}}}
packages += ${packaged-{{platform}}}
{% endfor %}
package: build/$v.tar.gz build/$v.tar.gz.sha512sum
package-common: package-apps package-grubs
package-apps: ${packaged-apps}
package-grubs: ${packaged-grubs}
package-osies: ${packaged-osies}
package-repos: ${packaged-repos}
deploy: package
$(E)"UPLOAD s3/tinkerbell-oss/osie-uploads/$v.tar.gz"
$(Q)mc cp build/$v.tar.gz s3/tinkerbell-oss/osie-uploads/$v.tar.gz
$(Q)if [[ $${DRONE_BRANCH:-} == "master" ]]; then mc cp s3/tinkerbell-oss/osie-uploads/$v.tar.gz s3/tinkerbell-oss/osie-uploads/latest.tar.gz; fi
$(Q)echo "deploy this build with the following command:"
$(Q)echo -n "./scripts/deploy osie update $v -m \"$$"
$(Q)echo -n "(sed -n '/^## \[/,$$ {/\S/!q; p}' CHANGELOG.md)\" "
$(Q)echo -n "$$(sed 's|.*= ||' build/$v.tar.gz.sha512sum)"
$(Q)echo
upload-test: ${packages}
$(E)"UPLOAD s3/tinkerbell-oss/osie-uploads/osie-testing/$v/"
$(Q)mc cp --recursive build/$v/ s3/tinkerbell-oss/osie-uploads/osie-testing/$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/$v.tar.gz: ${packages}
$(E)"TAR.GZ $@"
$(Q)cd build && \
tar -cO $(sort $(subst build/,,$^)) | pigz >$(@F).tmp && \
mv $(@F).tmp $(@F)
build/$v.tar.gz.sha512sum: build/$v.tar.gz
$(E)"SHASUM $@"
$(Q)sha512sum --tag $^ | sed 's|build/||' >$@
${packaged-grubs}: ${grubs}
$(E)"INSTALL $@"
$(Q)install -Dm644 $(addprefix grub/,$(subst /,-,$(patsubst build/$v/grub/%,%,$@))) $@
build/$v/%-rc: apps/%-rc
$(E)"INSTALL $@"
$(Q)install -D -m644 $< $@
build/$v/%.sh: apps/%.sh
$(E)"INSTALL $@"
$(Q)install -D -m644 $< $@
build/$v/osie-%: build/osie-%
$(E)"INSTALL $@"
$(Q)install -D -m644 $< $@
{% for platform, arch in platforms.items() %}
build/$v/initramfs-{{platform}}: build/$v-rootfs-{{platform}} installer/alpine/init-{{arch}}
$(E)"CPIO $@"
$(Q) install -m755 installer/alpine/init-{{arch}} build/$v-rootfs-{{platform}}/init
$(Q) (cd build/$v-rootfs-{{platform}} && find -print0 | bsdcpio --null --quiet -oH newc | pigz -9) >[email protected]
$(Q) install -D -m644 [email protected] $@
$(Q) touch $@
{% endfor %}
build/$v/modloop-%: build/modloop-%
$(E)"INSTALL $@"
$(Q)install -D -m644 $< $@
build/$v/vmlinuz-%: build/vmlinuz-%
$(E)"INSTALL $@"
$(Q)install -D -m644 $< $@
build/$v/test-initramfs-%/test-initramfs: build/$v/initramfs-% installer/alpine/init-%
$(E)"BUILD $@"
$(Q) rm -rf $(@D)
$(Q) mkdir -p $(@D)
$(Q) cp $^ $(@D)/
$(Q) mv $(@D)/$(<F) $(@D)/initramfs.cpio.gz
$(Q) cd $(@D) && \
sed -i 's|curl |curl --insecure |g' init-* && \
mv init-* init && \
chmod +x init && \
gunzip 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 ci 2>&1 | tee [email protected] >/dev/$T
touch $@
{% for arch in platforms.values() | unique | sort -%}
test-{{arch}}: $(cprs) build/osie-test-env package-apps package-grubs build/$v/osie-{{arch}}.tar.gz build/$v/osie-runner-{{arch}}.tar.gz build/$v/repo-{{arch}} ${packaged-{{arch}}} ci/ifup.sh ci/vm.sh build/$v/test-initramfs-{{arch}}/test-initramfs
$(E)"DOCKER $@"
ifneq ($(CI),drone)
$(Q)docker run --rm -ti \
--privileged \
--name $(@F) \
--volume $(CURDIR):/osie:ro \
--env OSES \
--env UEFI \
osie-test-env \
/osie/ci/vm.sh tests -C /osie/build/$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/$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/$v-rootfs-%: build/initramfs-%
$(E)"EXTRACT $@"
$(Q)rm -rf $@
$(Q)mkdir $@
$(Q)bsdtar -xf $< -C $@
test-packet-networking: build/osie-test-env docker/scripts/packet-networking ci/test-network.sh $(shell find ci/network-test-files/ -type f | grep -v ':')
$(E)"DOCKER $@"
ifneq ($(CI),drone)
$(Q)docker run --rm -ti \
--name $(@F) \
--dns=147.75.207.207 \
--cap-add=NET_ADMIN \
--volume "$(CURDIR):/$(CURDIR):ro" \
--volume "$(CURDIR)/network-coverage/:/coverage" \
--workdir "$(CURDIR)" \
-e MAKERS=${MAKERS} \
-e MODES=${MODES} \
-e OSES=${OSES} \
-e TYPES=${TYPES} \
osie-test-env \
ci/vm.sh network_test | tee build/[email protected] >/dev/$T
else
mkdir -p build/network-coverage
ln -nsf $(CURDIR)/build/network-coverage /coverage
ci/vm.sh network_test | tee build/[email protected] >/dev/$T
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 $@"
$(Q)sed '${SED}' $< > $<.$*
$(Q)docker build -t osie:$* -f $<.$* $(<D) 2>&1 | tee [email protected] >/dev/$T
$(Q)docker save osie:$* > [email protected]
$(Q)mv [email protected] $@
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 $@"
$(Q)sed '${SED}' $< > $<.$*
$(Q)docker build -t osie-runner:$* -f $<.$* $(<D) 2>&1 | tee [email protected] >/dev/$T
$(Q)docker save osie-runner:$* > [email protected]
$(Q)mv [email protected] $@
build/osie-runner-aarch64.tar.gz:
$(E)"FAKE $@"
$(Q) touch $@
build/$v/repo-aarch64:
$(E)"LN $@"
$(Q)ln -nsf ../../../alpine/edge $@
build/repo-aarch64:
$(Q)echo edge > $@
build/$v/repo-x86_64:
$(E)"LN $@"
$(Q)ln -nsf ../../../alpine/v${alpine_version_x86_64} $@
build/repo-x86_64:
$(Q)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 $@"
$(Q)ln -nsf ../$< $@
{% endfor -%}