Skip to content

Commit 7cee5d2

Browse files
committed
Unify python-gardenlinux-lib based feature and cname parsing
Signed-off-by: Tobias Wolf <wolf@b1-systems.de>
1 parent 98ee0d4 commit 7cee5d2

File tree

8 files changed

+46
-44
lines changed

8 files changed

+46
-44
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
@@ -97,12 +97,9 @@ commit="$(./get_commit)"
9797
timestamp="$(./get_timestamp)"
9898
default_version="$(./get_version)"
9999

100-
101100
if [ "$resolve_cname" = 1 ]; then
102101
arch="$("$container_engine" run --rm "${container_run_opts[@]}" "${container_mount_opts[@]}" "$container_image" dpkg --print-architecture)"
103-
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")"
104-
short_commit="$(head -c 8 <<< "$commit")"
105-
echo "$cname-$short_commit" >&3
102+
"$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"
106103
exit 0
107104
fi
108105

builder/Makefile

Lines changed: 26 additions & 23 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
@@ -24,11 +25,13 @@ endef
2425
required_vars := REPO COMMIT TIMESTAMP DEFAULT_VERSION TEMPFS_SIZE
2526
$(foreach var,$(required_vars),$(eval $(call require_var,$(var))))
2627

27-
PARSE_FEATURES_ARGS :=
28+
GL_ALLOW_FRANKENSTEIN :=
2829
ifdef ALLOW_FRANKENSTEIN
29-
PARSE_FEATURES_ARGS := --allow-frankenstein
30+
GL_ALLOW_FRANKENSTEIN := true
3031
endif
3132

33+
export GL_ALLOW_FRANKENSTEIN
34+
3235
SHORT_COMMIT := $(shell head -c 8 <<< '$(COMMIT)')
3336

3437
DEFAULT_ARCH := $(shell dpkg --print-architecture)
@@ -43,22 +46,22 @@ clean:
4346
.build/%.sentinel:
4447
true
4548

46-
.build/bootstrap-%-$(SHORT_COMMIT).tar: $$(shell ./make_repo_sentinel $$(REPO) $$(call cname_version,$$*))
49+
.build/bootstrap-%.tar: $$(shell ./make_repo_sentinel $$(REPO) $$(call gl_version,$$*))
4750
target '$@'
48-
info 'bootstrapping $*-$(SHORT_COMMIT)'
51+
info 'bootstrapping $*'
4952
arch='$(call cname_arch,$*)'
50-
version='$(call cname_version,$*)'
53+
version='$(call gl_version,$*)'
5154
./bootstrap "$$arch" "$$version" '$(REPO)' keyring.gpg '$@'
5255

53-
.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)
56+
.build/%.tar: .build/bootstrap-$$(call cname_arch,$$*)-$$(call cname_gl_version,$$*).tar $(shell ./make_directory_sentinel features) $(shell ./make_directory_sentinel cert)
5457
target '$@' '$<'
5558
info 'configuring rootfs $*-$(SHORT_COMMIT)'
56-
features="$$(./parse_features $(PARSE_FEATURES_ARGS) --feature-dir features --cname '$*' features)"
57-
features_platforms="$$(./parse_features $(PARSE_FEATURES_ARGS) --feature-dir features --cname '$*' platforms)"
58-
features_elements="$$(./parse_features $(PARSE_FEATURES_ARGS) --feature-dir features --cname '$*' elements)"
59-
features_flags="$$(./parse_features $(PARSE_FEATURES_ARGS) --feature-dir features --cname '$*' flags)"
59+
features="$$(gl-features-parse --feature-dir features --default-arch '$$(DEFAULT_ARCH)' --cname '$*' features)"
60+
features_platforms="$$(gl-features-parse --feature-dir features --default-arch '$$(DEFAULT_ARCH)' --cname '$*'platforms)"
61+
features_elements="$$(gl-features-parse --feature-dir features --default-arch '$$(DEFAULT_ARCH)' --cname '$*'elements)"
62+
features_flags="$$(gl-features-parse --feature-dir features --default-arch '$$(DEFAULT_ARCH)' --cname '$*'flags)"
6063
BUILDER_CNAME='$*'
61-
BUILDER_VERSION='$(call cname_version,$*)'
64+
BUILDER_VERSION='$(call gl_version,$*)'
6265
BUILDER_ARCH='$(call cname_arch,$*)'
6366
BUILDER_TIMESTAMP='$(TIMESTAMP)'
6467
BUILDER_COMMIT='$(COMMIT)'
@@ -70,17 +73,17 @@ clean:
7073
./configure '$(word 1,$^)' '$@'
7174

7275
define artifact_template =
73-
.build/%-$(SHORT_COMMIT).$1: $$$$(shell COMMIT=$(SHORT_COMMIT) ./make_get_image_dependencies '$$$$@') $$(shell ./make_directory_sentinel features) $$(shell ./make_directory_sentinel cert)
76+
.build/%.$1: $$$$(shell COMMIT=$(SHORT_COMMIT) ./make_get_image_dependencies '$$$$@') $$(shell ./make_directory_sentinel features) $$(shell ./make_directory_sentinel cert)
7477
script='$$(word 1,$$^)'
7578
input='$$(word 2,$$^)'
7679
target '$$@' "$$$$input"
7780
info 'building $1 image $$*'
78-
features="$$$$(./parse_features $(PARSE_FEATURES_ARGS) --feature-dir features --cname '$$*' features)"
79-
features_platforms="$$$$(./parse_features $(PARSE_FEATURES_ARGS) --feature-dir features --cname '$$*' platforms)"
80-
features_elements="$$$$(./parse_features $(PARSE_FEATURES_ARGS) --feature-dir features --cname '$$*' elements)"
81-
features_flags="$$$$(./parse_features $(PARSE_FEATURES_ARGS) --feature-dir features --cname '$$*' flags)"
81+
features="$$$$(gl-features-parse --feature-dir features --default-arch '$$(DEFAULT_ARCH)' --cname '$$*' features)"
82+
features_platforms="$$$$(gl-features-parse --feature-dir features --default-arch '$$(DEFAULT_ARCH)' --cname '$$*' platforms)"
83+
features_elements="$$$$(gl-features-parse --feature-dir features --default-arch '$$(DEFAULT_ARCH)' --cname '$$*' elements)"
84+
features_flags="$$$$(gl-features-parse --feature-dir features --default-arch '$$(DEFAULT_ARCH)' --cname '$$*' flags)"
8285
BUILDER_CNAME='$$*'
83-
BUILDER_VERSION='$$(call cname_version,$$*)'
86+
BUILDER_VERSION='$$(call gl_version,$$*)'
8487
BUILDER_ARCH='$$(call cname_arch,$$*)'
8588
BUILDER_TIMESTAMP='$$(TIMESTAMP)'
8689
BUILDER_COMMIT='$$(COMMIT)'
@@ -94,15 +97,15 @@ endef
9497

9598
$(foreach artifact_rule,$(shell ./make_get_artifact_rules),$(eval $(call artifact_template,$(artifact_rule))))
9699

97-
.build/%-$(SHORT_COMMIT).artifacts: $$(shell COMMIT=$(SHORT_COMMIT) ./make_list_build_artifacts '$$*')
100+
.build/%.artifacts: $$(shell COMMIT=$(SHORT_COMMIT) DEFAULT_VERSION=$(DEFAULT_VERSION) NATIVE_ARCH=$(NATIVE_ARCH) ./make_list_build_artifacts '$$*')
98101
target '$@'
99102
echo -n > '$@'
100103
for f in $^; do
101104
basename "$$f" | tee -a '$@'
102105
echo "$$(basename "$$f").log" | tee -a '$@'
103106
done
104107

105-
%: .build/$$(shell ./parse_features $(PARSE_FEATURES_ARGS) --feature-dir features --default-arch '$$(DEFAULT_ARCH)' --default-version '$$(DEFAULT_VERSION)' --cname '$$*')-$(SHORT_COMMIT).artifacts
108+
%: .build/$$(shell gl-features-parse --feature-dir features --default-arch '$$(DEFAULT_ARCH)' --default-version '$$(DEFAULT_VERSION)-$$(SHORT_COMMIT)' --cname '$$*').artifacts
106109
ln -f -s -r '$<' '.build/$*'
107110

108111
# 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 --allow-frankenstein --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 --allow-frankenstein --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 --allow-frankenstein --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[@]}"

builder/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Basic Python requirements for Garden Linux
2+
3+
gardenlinux @ git+https://github.com/gardenlinux/python-gardenlinux-lib.git@0.11.0

pkg.list

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ openssl
2323
ostree
2424
ostree-boot
2525
python3
26-
python3-mako
27-
python3-networkx
28-
python3-pefile
29-
python3-yaml
26+
python3-setuptools
27+
python3-pip
3028
qemu-utils
3129
squashfs-tools
3230
systemd

setup_namespace

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set -eufo pipefail
44

55
if [ "${1-}" = --second-stage ]; then
66
shift
7+
78
mount -t tmpfs -o size=4G tmpfs /tmp
89
cleanup_permissions () {
910
if [ -d /builder/.build ]; then

0 commit comments

Comments
 (0)