Skip to content

Commit 8ae705a

Browse files
bcresseywebern
andcommitted
twoliter: update Dockerfile for per-package rpm directories
Update the buildsys Dockerfile so that it works with RPM packages being outputted to sub-directories, i.e. build/package-name/ Co-authored-by: Matt Briggs <brigmatt@amazon.com> Co-authored-by: Ben Cressey <bcressey@amazon.com> Signed-off-by: Ben Cressey <bcressey@amazon.com>
1 parent 015c5f8 commit 8ae705a

File tree

2 files changed

+82
-24
lines changed

2 files changed

+82
-24
lines changed

twoliter/embedded/build.Dockerfile

Lines changed: 78 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# syntax=docker/dockerfile:1.4.3
2-
# This Dockerfile has two sections which are used to build rpm.spec packages and to create
3-
# Bottlerocket images, respectively. They are marked as Section 1 and Section 2. buildsys
4-
# uses Section 1 during build-package calls and Section 2 during build-variant calls.
2+
# This Dockerfile has three sections which are used to build rpm.spec packages, to create
3+
# kits, and to create Bottlerocket images, respectively. They are marked as Sections 1-3.
4+
# buildsys uses Section 1 during build-package calls, Section 2 during build-kit calls,
5+
# and Section 3 during build-variant calls.
56
#
67
# Several commands start with RUN --mount=target=/host, which mounts the docker build
78
# context (which in practice is the root of the Bottlerocket repository) as a read-only
@@ -94,6 +95,8 @@ RUN \
9495
# Builds an RPM package from a spec file.
9596
FROM sdk AS rpmbuild
9697
ARG PACKAGE
98+
ARG PACKAGE_DEPENDENCIES
99+
ARG KIT_DEPENDENCIES
97100
ARG ARCH
98101
ARG NOCACHE
99102
ARG VARIANT
@@ -129,18 +132,26 @@ RUN \
129132

130133
USER root
131134
RUN --mount=target=/host \
132-
ln -s /host/build/rpms/*.rpm ./rpmbuild/RPMS \
133-
&& createrepo_c \
135+
for pkg in ${PACKAGE_DEPENDENCIES} ; do \
136+
ln -s /host/build/rpms/${pkg}/*.rpm ./rpmbuild/RPMS ; \
137+
done && \
138+
createrepo_c \
134139
-o ./rpmbuild/RPMS \
135140
-x '*-debuginfo-*.rpm' \
136141
-x '*-debugsource-*.rpm' \
137142
--no-database \
138-
/host/build/rpms \
139-
&& cp .rpmmacros /etc/rpm/macros \
140-
&& dnf -y \
143+
./rpmbuild/RPMS && \
144+
cp .rpmmacros /etc/rpm/macros && \
145+
declare -a KIT_REPOS && \
146+
for kit in ${KIT_DEPENDENCIES} ; do \
147+
KIT_REPOS+=("--repofrompath=${kit},/host/build/kits/${kit}/${ARCH}" --enablerepo "${kit}") ; \
148+
done && \
149+
echo "${KIT_REPOS[@]}" && \
150+
dnf -y \
141151
--disablerepo '*' \
142152
--repofrompath repo,./rpmbuild/RPMS \
143153
--enablerepo 'repo' \
154+
"${KIT_REPOS[@]}" \
144155
--nogpgcheck \
145156
--forcearch "${ARCH}" \
146157
builddep rpmbuild/SPECS/${PACKAGE}.spec
@@ -167,13 +178,47 @@ FROM scratch AS package
167178
COPY --from=rpmbuild /home/builder/rpmbuild/RPMS/*/*.rpm /output/
168179

169180
############################################################################################
170-
# Section 2: The following build stages are used to create a Bottlerocket image once all of
171-
# the rpm files have been created by repeatedly using Section 1.
181+
# Section 2: The following build stages are used to create a Bottlerocket kit once all of
182+
# the rpm files have been created by repeatedly using Section 1. This process can occur more
183+
# than once because packages can depend on kits and those kits depend on packages that must
184+
# be built first.
172185

173186
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
174-
# Creates an RPM repository from packages created in Section 1.
187+
# Builds a kit from RPM packages.
188+
FROM sdk AS kitbuild
189+
ARG KIT
190+
ARG PACKAGE_DEPENDENCIES
191+
ARG ARCH
192+
ARG NOCACHE
193+
194+
WORKDIR /home/builder
195+
USER builder
196+
197+
RUN --mount=target=/host \
198+
/host/build/tools/rpm2kit \
199+
--packages-dir=/host/build/rpms \
200+
--arch="${ARCH}" \
201+
"${PACKAGE_DEPENDENCIES[@]/#/--package=}" \
202+
--output-dir=/home/builder/output \
203+
&& echo ${NOCACHE}
204+
205+
# Copies kit artifacts from the previous stage to their expected location so that buildsys
206+
# can find them and copy them out.
207+
FROM scratch AS kit
208+
COPY --from=kitbuild /home/builder/output/. /output/
209+
210+
############################################################################################
211+
# Section 3: The following build stages are used to create a Bottlerocket image once all of
212+
# the rpm files have been created by repeatedly using Sections 1 and 2.
213+
214+
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
215+
# Creates an RPM repository from packages created in Section 1 and kits from Section 2.
175216
FROM sdk AS repobuild
217+
# The list of packages from the variant Cargo.toml package.metadata.build-variant.packages section.
176218
ARG PACKAGES
219+
# The complete list of non-kit packages required by way of pure package-to-package dependencies.
220+
ARG PACKAGE_DEPENDENCIES
221+
ARG KIT_DEPENDENCIES
177222
ARG ARCH
178223
ARG NOCACHE
179224

@@ -196,28 +241,36 @@ RUN --mount=target=/host \
196241
WORKDIR /root
197242
USER root
198243
RUN --mount=target=/host \
199-
mkdir -p /local/rpms ./rpmbuild/RPMS \
200-
&& ln -s /host/build/rpms/*.rpm ./rpmbuild/RPMS \
201-
&& ln -s /home/builder/rpmbuild/RPMS/*/*.rpm ./rpmbuild/RPMS \
202-
&& createrepo_c \
244+
mkdir -p ./rpmbuild/RPMS && \
245+
for pkg in ${PACKAGE_DEPENDENCIES} ; do \
246+
ln -s /host/build/rpms/${pkg}/*.rpm ./rpmbuild/RPMS ; \
247+
done && \
248+
ln -s /home/builder/rpmbuild/RPMS/*/*.rpm ./rpmbuild/RPMS && \
249+
createrepo_c \
203250
-o ./rpmbuild/RPMS \
204251
-x '*-debuginfo-*.rpm' \
205252
-x '*-debugsource-*.rpm' \
206253
--no-database \
207-
./rpmbuild/RPMS \
208-
&& echo '%_dbpath %{_sharedstatedir}/rpm' >> /etc/rpm/macros \
209-
&& dnf -y \
254+
./rpmbuild/RPMS && \
255+
echo '%_dbpath %{_sharedstatedir}/rpm' >> /etc/rpm/macros && \
256+
declare -a KIT_REPOS && \
257+
for kit in ${KIT_DEPENDENCIES} ; do \
258+
KIT_REPOS+=("--repofrompath=${kit},/host/build/kits/${kit}/${ARCH}" --enablerepo "${kit}") ; \
259+
done && \
260+
dnf -y \
210261
--disablerepo '*' \
211262
--repofrompath repo,./rpmbuild/RPMS \
212263
--enablerepo 'repo' \
264+
"${KIT_REPOS[@]}" \
213265
--nogpgcheck \
214266
--downloadonly \
215267
--downloaddir . \
216268
--forcearch "${ARCH}" \
217-
install $(printf "bottlerocket-%s\n" metadata ${PACKAGES}) \
218-
&& mv *.rpm /local/rpms \
219-
&& createrepo_c /local/rpms \
220-
&& echo ${NOCACHE}
269+
install $(printf "bottlerocket-%s\n" metadata ${PACKAGES}) && \
270+
mkdir -p /local/rpms && \
271+
mv *.rpm /local/rpms && \
272+
createrepo_c /local/rpms && \
273+
echo ${NOCACHE}
221274

222275
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
223276
# Builds a Bottlerocket image.
@@ -288,7 +341,7 @@ WORKDIR /root
288341
USER root
289342
RUN --mount=target=/host \
290343
mkdir -p /local/migrations \
291-
&& find /host/build/rpms/ -maxdepth 1 -type f \
344+
&& find /host/build/rpms/os/ -maxdepth 1 -type f \
292345
-name "bottlerocket-migrations-*.rpm" \
293346
-not -iname '*debuginfo*' \
294347
-exec cp '{}' '/local/migrations/' ';' \
@@ -300,6 +353,7 @@ RUN --mount=target=/host \
300353
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
301354
# Creates an archive of kernel development sources and toolchain.
302355
FROM repobuild as kmodkitbuild
356+
# The list of packages from the variant Cargo.toml package.metadata.build-variant.packages section.
303357
ARG PACKAGES
304358
ARG ARCH
305359
ARG VERSION_ID
@@ -314,7 +368,7 @@ WORKDIR /tmp
314368
RUN --mount=target=/host \
315369
mkdir -p /local/archives \
316370
&& KERNEL="$(printf "%s\n" ${PACKAGES} | awk '/^kernel-/{print $1}')" \
317-
&& find /host/build/rpms/ -maxdepth 1 -type f \
371+
&& find /host/build/rpms/${KERNEL}/ -maxdepth 1 -type f \
318372
-name "bottlerocket-${KERNEL}-archive-*.rpm" \
319373
-exec cp '{}' '/local/archives/' ';' \
320374
&& /host/build/tools/rpm2kmodkit \

twoliter/embedded/build.Dockerfile.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
!/build/rpms/*.rpm
77
/build/rpms/*-debuginfo-*.rpm
88
/build/rpms/*-debugsource-*.rpm
9+
!/build/rpms/*/*.rpm
10+
/build/rpms/*/*-debuginfo-*.rpm
11+
/build/rpms/*/*-debugsource-*.rpm
12+
!/build/kits/
913
!/build/tools/*
1014
**/target/*
1115
/sbkeys

0 commit comments

Comments
 (0)