Skip to content

Commit 6423af1

Browse files
committed
Unify python-gardenlinux-lib based feature and cname parsing
Signed-off-by: Tobias Wolf <wolf@b1-systems.de>
1 parent 33391d8 commit 6423af1

File tree

9 files changed

+41
-259
lines changed

9 files changed

+41
-259
lines changed

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ COPY --from=resizefat32 /usr/bin/resizefat32 /usr/bin/resizefat32
2727
RUN curl "https://github.com/gardenlinux/aws-kms-pkcs11/releases/download/latest/aws_kms_pkcs11-$(dpkg --print-architecture).so" -sLo "/usr/lib/$(uname -m)-linux-gnu/pkcs11/aws_kms_pkcs11.so"
2828
COPY builder /builder
2929
RUN mkdir /builder/cert
30-
COPY setup_namespace /usr/sbin/setup_namespace
30+
COPY setup_env /usr/sbin/setup_env
3131
RUN curl -sSLf https://github.com/gardenlinux/seccomp_fake_xattr/releases/download/latest/seccomp_fake_xattr-$(uname -m).tar.gz \
3232
| gzip -d \
3333
| tar -xO seccomp_fake_xattr-$(uname -m)/fake_xattr > /usr/bin/fake_xattr \
@@ -37,4 +37,6 @@ RUN mkdir /tmp/sbsign \
3737
&& curl -sSLf https://github.com/gardenlinux/package-sbsigntool/releases/download/0.9.4-3.2gl0/build.tar.xz.0000 | xz -d | tar -x \
3838
&& dpkg -i sbsigntool_*_$(dpkg --print-architecture).deb
3939
RUN echo 'root:1:65535' | tee /etc/subuid /etc/subgid > /dev/null
40-
ENTRYPOINT [ "/usr/sbin/setup_namespace" ]
40+
RUN python3 -m venv /root/.local/builder-python-venv
41+
RUN /root/.local/builder-python-venv/bin/pip install -r "/builder/requirements.txt"
42+
ENTRYPOINT [ "/usr/sbin/setup_env" ]

build

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,9 @@ commit="$(./get_commit)"
9292
timestamp="$(./get_timestamp)"
9393
default_version="$(./get_version)"
9494

95-
9695
if [ "$resolve_cname" = 1 ]; then
9796
arch="$("$container_engine" run --rm "${container_run_opts[@]}" "${container_mount_opts[@]}" "$container_image" dpkg --print-architecture)"
98-
cname="$("$container_engine" run --rm "${container_run_opts[@]}" "${container_mount_opts[@]}" "$container_image" /builder/parse_features --feature-dir /builder/features --default-arch "$arch" --default-version "$default_version" --cname "$1")"
99-
short_commit="$(head -c 8 <<< "$commit")"
100-
echo "$cname-$short_commit" >&3
97+
echo "$("$container_engine" run --rm "${container_run_opts[@]}" "${container_mount_opts[@]}" "$container_image" gl-cname --feature-dir /builder/features --arch "$arch" --version "${default_version}-${commit}" "$1")"
10198
exit 0
10299
fi
103100

builder/Makefile

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ export BASH_ENV := make_bash_env
1010

1111
MAKEFLAGS += --no-builtin-rules
1212

13-
lastword = $(word $(words $1),$1)
14-
prelastword = $(word $(words $1),_ $1)
15-
cname_version = $(call lastword,$(subst -, ,$1))
16-
cname_arch = $(call prelastword,$(subst -, ,$1))
17-
1813
define require_var =
1914
ifndef $1
2015
$$(error '$1 undefined')
@@ -28,6 +23,10 @@ SHORT_COMMIT := $(shell head -c 8 <<< '$(COMMIT)')
2823

2924
DEFAULT_ARCH := $(shell dpkg --print-architecture)
3025

26+
cname_gl_version = $(shell gl-features-parse --feature-dir features --default-arch '$(NATIVE_ARCH)' --default-version '$(DEFAULT_VERSION)-$(SHORT_COMMIT)' --cname '$1' version)
27+
cname_arch = $(shell gl-features-parse --feature-dir features --default-arch '$(NATIVE_ARCH)' --default-version '$(DEFAULT_VERSION)-$(SHORT_COMMIT)' --cname '$1' arch)
28+
gl_version = $(firstword $(subst -, ,$(call cname_gl_version,$1)))
29+
3130
export AWS_DEFAULT_REGION AWS_REGION AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN
3231

3332
.PHONY: clean
@@ -38,19 +37,19 @@ clean:
3837
.build/%.sentinel:
3938
true
4039

41-
.build/bootstrap-%-$(SHORT_COMMIT).tar: $$(shell ./make_repo_sentinel $$(REPO) $$(call cname_version,$$*))
40+
.build/bootstrap-%.tar: $$(shell ./make_repo_sentinel $$(REPO) $$(call cname_gl_version,$$*))
4241
target '$@'
43-
info 'bootstrapping $*-$(SHORT_COMMIT)'
42+
info 'bootstrapping $*'
4443
arch='$(call cname_arch,$*)'
45-
version='$(call cname_version,$*)'
44+
version='$(call gl_version,$*)'
4645
./bootstrap "$$arch" "$$version" '$(REPO)' keyring.gpg '$@'
4746

48-
.build/%-$(SHORT_COMMIT).tar: .build/bootstrap-$$(call cname_arch,$$*)-$$(call cname_version,$$*)-$(SHORT_COMMIT).tar $(shell ./make_directory_sentinel features) $(shell ./make_directory_sentinel cert)
47+
.build/%.tar: .build/bootstrap-$$(call cname_arch,$$*)-$$(call cname_gl_version,$$*).tar $(shell ./make_directory_sentinel features) $(shell ./make_directory_sentinel cert)
4948
target '$@' '$<'
50-
info 'configuring rootfs $*-$(SHORT_COMMIT)'
51-
features="$$(./parse_features --feature-dir features --cname '$*' features)"
49+
info 'configuring rootfs $*'
50+
features="$$(gl-features-parse --feature-dir features --cname '$*' features)"
5251
BUILDER_CNAME='$*'
53-
BUILDER_VERSION='$(call cname_version,$*)'
52+
BUILDER_VERSION='$(call gl_version,$*)'
5453
BUILDER_ARCH='$(call cname_arch,$*)'
5554
BUILDER_TIMESTAMP='$(TIMESTAMP)'
5655
BUILDER_COMMIT='$(COMMIT)'
@@ -59,14 +58,14 @@ clean:
5958
./configure '$(word 1,$^)' '$@'
6059

6160
define artifact_template =
62-
.build/%-$(SHORT_COMMIT).$1: $$$$(shell COMMIT=$(SHORT_COMMIT) ./make_get_image_dependencies '$$$$@') $$(shell ./make_directory_sentinel features) $$(shell ./make_directory_sentinel cert)
61+
.build/%.$1: $$$$(shell COMMIT=$(SHORT_COMMIT) ./make_get_image_dependencies '$$$$@') $$(shell ./make_directory_sentinel features) $$(shell ./make_directory_sentinel cert)
6362
script='$$(word 1,$$^)'
6463
input='$$(word 2,$$^)'
6564
target '$$@' "$$$$input"
6665
info 'building $1 image $$*'
67-
features="$$$$(./parse_features --feature-dir features --cname '$$*' features)"
66+
features="$$$$(gl-features-parse --feature-dir features --cname '$$*' features)"
6867
BUILDER_CNAME='$$*'
69-
BUILDER_VERSION='$$(call cname_version,$$*)'
68+
BUILDER_VERSION='$$(call gl_version,$$*)'
7069
BUILDER_ARCH='$$(call cname_arch,$$*)'
7170
BUILDER_TIMESTAMP='$$(TIMESTAMP)'
7271
BUILDER_COMMIT='$$(COMMIT)'
@@ -77,15 +76,15 @@ endef
7776

7877
$(foreach artifact_rule,$(shell ./make_get_artifact_rules),$(eval $(call artifact_template,$(artifact_rule))))
7978

80-
.build/%-$(SHORT_COMMIT).artifacts: $$(shell COMMIT=$(SHORT_COMMIT) ./make_list_build_artifacts '$$*')
79+
.build/%.artifacts: $$(shell COMMIT=$(SHORT_COMMIT) DEFAULT_VERSION=$(DEFAULT_VERSION) NATIVE_ARCH=$(NATIVE_ARCH) ./make_list_build_artifacts '$$*')
8180
target '$@'
8281
echo -n > '$@'
8382
for f in $^; do
8483
basename "$$f" | tee -a '$@'
8584
echo "$$(basename "$$f").log" | tee -a '$@'
8685
done
8786

88-
%: .build/$$(shell ./parse_features --feature-dir features --default-arch '$$(DEFAULT_ARCH)' --default-version '$$(DEFAULT_VERSION)' --cname '$$*')-$(SHORT_COMMIT).artifacts
87+
%: .build/$$(shell gl-features-parse --feature-dir features --default-arch '$$(DEFAULT_ARCH)' --default-version '$$(DEFAULT_VERSION)-$$(SHORT_COMMIT)' --cname '$$*').artifacts
8988
ln -f -s -r '$<' '.build/$*'
9089

9190
# prevents match anything rule from applying to Makefile and image/convert scripts

builder/make_get_image_dependencies

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ exec 1>&2
77

88
# get longest chain of extensions, but not extensions starting with a number to prevent parsing minor version as extension
99
extension="$(grep -E -o '(\.[a-z][a-zA-Z0-9\-_]*)*$' <<< "$1")"
10-
artifact_base="${1%"-$COMMIT$extension"}"
10+
artifact_base="${1%"$extension"}"
1111
cname="$(basename "$artifact_base")"
1212

1313
[ "$extension" != ".raw" ] || extension=
@@ -18,15 +18,15 @@ input=
1818

1919
if [ -f "image$extension" ]; then
2020
script="image$extension"
21-
input="$artifact_base-$COMMIT.tar"
21+
input="$artifact_base.tar"
2222
fi
2323

2424
if [ -f "convert$extension" ]; then
2525
script="convert$extension"
26-
input="$artifact_base-$COMMIT.raw"
26+
input="$artifact_base.raw"
2727
fi
2828

29-
IFS=',' read -r -a features < <(./parse_features --feature-dir features --cname "$cname" features)
29+
IFS=',' read -r -a features < <(gl-features-parse --feature-dir features --cname "$cname" features)
3030

3131
for feature in "${features[@]}"; do
3232
if [ -s "features/$feature/image$extension" ]; then
@@ -36,7 +36,7 @@ for feature in "${features[@]}"; do
3636
fi
3737
is_feature_script=1
3838
script="features/$feature/image$extension"
39-
input="$artifact_base-$COMMIT.tar"
39+
input="$artifact_base.tar"
4040
fi
4141

4242
if [ -s "features/$feature/convert$extension" ]; then
@@ -46,7 +46,7 @@ for feature in "${features[@]}"; do
4646
fi
4747
is_feature_script=1
4848
script="features/$feature/convert$extension"
49-
input="$artifact_base-$COMMIT.raw"
49+
input="$artifact_base.raw"
5050
fi
5151

5252
# temporarily enable file globbing (+f)
@@ -68,7 +68,7 @@ for feature in "${features[@]}"; do
6868
fi
6969
is_feature_script=1
7070
script="$i"
71-
input="$artifact_base-$COMMIT.${i##*~}"
71+
input="$artifact_base.${i##*~}"
7272
done
7373
done
7474

builder/make_list_build_artifacts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@ shopt -s nullglob
55

66
cname="$1"
77

8-
IFS=',' read -r -a features < <(./parse_features --feature-dir features --cname "$cname" features)
9-
10-
artifacts=(".build/$cname-$COMMIT.tar" ".build/$cname-$COMMIT.release" ".build/$cname-$COMMIT.manifest" ".build/$cname-$COMMIT.requirements")
8+
IFS=',' read -r -a features < <(gl-features-parse --feature-dir features --default-arch "${NATIVE_ARCH}" --default-version "${DEFAULT_VERSION}-${COMMIT}" --cname "$cname" features)
9+
artifacts=(".build/$cname.tar" ".build/$cname.release" ".build/$cname.manifest" ".build/$cname.requirements")
1110

1211
for feature in "${features[@]}"; do
1312
for i in "features/$feature/"{image,convert}.*; do
1413
# get target artifact file extension, usually this is the image/convert script extension
1514
# except if the script extension is of the form filename.extA~extB in which case the artifact extension is .extA only
1615
extension="$(grep -E -o '(\.[a-z][a-zA-Z0-9\-_~]*)*$' <<< "$i")"
17-
artifacts+=(".build/$cname-$COMMIT${extension%~*}")
16+
artifacts+=(".build/$cname${extension%~*}")
1817
done
1918
done
2019

21-
if [ "${#artifacts[@]}" = 4 ] && [ -n "$(./parse_features --feature-dir "features" --cname "$cname" platforms)" ]; then
22-
artifacts+=(".build/$cname-$COMMIT.raw")
20+
if [ "${#artifacts[@]}" = 4 ] && [ -n "$(gl-features-parse --feature-dir "features" --default-arch "${NATIVE_ARCH}" --default-version "${DEFAULT_VERSION}-${COMMIT}" --cname "$cname" platforms)" ]; then
21+
artifacts+=(".build/$cname.raw")
2322
fi
2423

2524
echo "${artifacts[@]}"

0 commit comments

Comments
 (0)