Skip to content

Commit 4ed9d3d

Browse files
committed
Unify python-gardenlinux-lib based feature and cname parsing
Signed-off-by: Tobias Wolf <[email protected]>
1 parent 37a5328 commit 4ed9d3d

File tree

9 files changed

+42
-265
lines changed

9 files changed

+42
-265
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ COPY --from=datefudge /usr/bin/datefudge /usr/bin/datefudge
2626
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
29+
RUN python3 -m pip install --break-system-packages -r "/builder/requirements.txt" --root-user-action ignore
2930
RUN mkdir /builder/cert
3031
COPY setup_namespace /usr/sbin/setup_namespace
3132
RUN curl -sSLf https://github.com/gardenlinux/seccomp_fake_xattr/releases/download/latest/seccomp_fake_xattr-$(uname -m).tar.gz \

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+
"$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: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ 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))
13+
cname_parts = $(subst _, , $(subst -, , $1))
14+
cname_gl_commit = $(lastword $(call cname_parts,$1))
15+
gl_version = $(lastword $(filter-out $(call cname_gl_commit,$1), $(call cname_parts,$1)))
16+
cname_gl_version = $(call gl_version,$1)-$(call cname_gl_commit,$1)
17+
cname_arch = $(lastword $(filter-out $(call gl_version,$1) $(call cname_gl_commit,$1), $(call cname_parts,$1)))
1718

1819
define require_var =
1920
ifndef $1
@@ -38,22 +39,22 @@ clean:
3839
.build/%.sentinel:
3940
true
4041

41-
.build/bootstrap-%-$(SHORT_COMMIT).tar: $$(shell ./make_repo_sentinel $$(REPO) $$(call cname_version,$$*))
42+
.build/bootstrap-%.tar: $$(shell ./make_repo_sentinel $$(REPO) $$(call gl_version,$$*))
4243
target '$@'
43-
info 'bootstrapping $*-$(SHORT_COMMIT)'
44+
info 'bootstrapping $*'
4445
arch='$(call cname_arch,$*)'
45-
version='$(call cname_version,$*)'
46+
version='$(call gl_version,$*)'
4647
./bootstrap "$$arch" "$$version" '$(REPO)' keyring.gpg '$@'
4748

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)
49+
.build/%.tar: .build/bootstrap-$$(call cname_arch,$$*)-$$(call cname_gl_version,$$*).tar $(shell ./make_directory_sentinel features) $(shell ./make_directory_sentinel cert)
4950
target '$@' '$<'
5051
info 'configuring rootfs $*-$(SHORT_COMMIT)'
51-
features="$$(./parse_features --feature-dir features --cname '$*' features)"
52-
features_platforms="$$(./parse_features --feature-dir features --cname '$*' platforms)"
53-
features_elements="$$(./parse_features --feature-dir features --cname '$*' elements)"
54-
features_flags="$$(./parse_features --feature-dir features --cname '$*' flags)"
52+
features="$$(gl-features-parse --feature-dir features --default-arch '$$(DEFAULT_ARCH)' --cname '$*' features)"
53+
features_platforms="$$(gl-features-parse --feature-dir features --default-arch '$$(DEFAULT_ARCH)' --cname '$*'platforms)"
54+
features_elements="$$(gl-features-parse --feature-dir features --default-arch '$$(DEFAULT_ARCH)' --cname '$*'elements)"
55+
features_flags="$$(gl-features-parse --feature-dir features --default-arch '$$(DEFAULT_ARCH)' --cname '$*'flags)"
5556
BUILDER_CNAME='$*'
56-
BUILDER_VERSION='$(call cname_version,$*)'
57+
BUILDER_VERSION='$(call gl_version,$*)'
5758
BUILDER_ARCH='$(call cname_arch,$*)'
5859
BUILDER_TIMESTAMP='$(TIMESTAMP)'
5960
BUILDER_COMMIT='$(COMMIT)'
@@ -65,17 +66,17 @@ clean:
6566
./configure '$(word 1,$^)' '$@'
6667

6768
define artifact_template =
68-
.build/%-$(SHORT_COMMIT).$1: $$$$(shell COMMIT=$(SHORT_COMMIT) ./make_get_image_dependencies '$$$$@') $$(shell ./make_directory_sentinel features) $$(shell ./make_directory_sentinel cert)
69+
.build/%.$1: $$$$(shell COMMIT=$(SHORT_COMMIT) ./make_get_image_dependencies '$$$$@') $$(shell ./make_directory_sentinel features) $$(shell ./make_directory_sentinel cert)
6970
script='$$(word 1,$$^)'
7071
input='$$(word 2,$$^)'
7172
target '$$@' "$$$$input"
7273
info 'building $1 image $$*'
73-
features="$$$$(./parse_features --feature-dir features --cname '$$*' features)"
74-
features_platforms="$$$$(./parse_features --feature-dir features --cname '$$*' platforms)"
75-
features_elements="$$$$(./parse_features --feature-dir features --cname '$$*' elements)"
76-
features_flags="$$$$(./parse_features --feature-dir features --cname '$$*' flags)"
74+
features="$$$$(gl-features-parse --feature-dir features --default-arch '$$(DEFAULT_ARCH)' --cname '$$*' features)"
75+
features_platforms="$$$$(gl-features-parse --feature-dir features --default-arch '$$(DEFAULT_ARCH)' --cname '$$*' platforms)"
76+
features_elements="$$$$(gl-features-parse --feature-dir features --default-arch '$$(DEFAULT_ARCH)' --cname '$$*' elements)"
77+
features_flags="$$$$(gl-features-parse --feature-dir features --default-arch '$$(DEFAULT_ARCH)' --cname '$$*' flags)"
7778
BUILDER_CNAME='$$*'
78-
BUILDER_VERSION='$$(call cname_version,$$*)'
79+
BUILDER_VERSION='$$(call gl_version,$$*)'
7980
BUILDER_ARCH='$$(call cname_arch,$$*)'
8081
BUILDER_TIMESTAMP='$$(TIMESTAMP)'
8182
BUILDER_COMMIT='$$(COMMIT)'
@@ -89,15 +90,15 @@ endef
8990

9091
$(foreach artifact_rule,$(shell ./make_get_artifact_rules),$(eval $(call artifact_template,$(artifact_rule))))
9192

92-
.build/%-$(SHORT_COMMIT).artifacts: $$(shell COMMIT=$(SHORT_COMMIT) ./make_list_build_artifacts '$$*')
93+
.build/%.artifacts: $$(shell COMMIT=$(SHORT_COMMIT) DEFAULT_VERSION=$(DEFAULT_VERSION) NATIVE_ARCH=$(NATIVE_ARCH) ./make_list_build_artifacts '$$*')
9394
target '$@'
9495
echo -n > '$@'
9596
for f in $^; do
9697
basename "$$f" | tee -a '$@'
9798
echo "$$(basename "$$f").log" | tee -a '$@'
9899
done
99100

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

103104
# 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)