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
9495# Builds an RPM package from a spec file.
9596FROM sdk AS rpmbuild
9697ARG PACKAGE
98+ ARG PACKAGE_DEPENDENCIES
99+ ARG KIT_DEPENDENCIES
97100ARG ARCH
98101ARG NOCACHE
99102ARG VARIANT
@@ -129,18 +132,26 @@ RUN \
129132
130133USER root
131134RUN --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
167178COPY --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.
175216FROM sdk AS repobuild
217+ # The list of packages from the variant Cargo.toml package.metadata.build-variant.packages section.
176218ARG 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
177222ARG ARCH
178223ARG NOCACHE
179224
@@ -196,28 +241,36 @@ RUN --mount=target=/host \
196241WORKDIR /root
197242USER root
198243RUN --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
288341USER root
289342RUN --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.
302355FROM repobuild as kmodkitbuild
356+ # The list of packages from the variant Cargo.toml package.metadata.build-variant.packages section.
303357ARG PACKAGES
304358ARG ARCH
305359ARG VERSION_ID
@@ -314,7 +368,7 @@ WORKDIR /tmp
314368RUN --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 \
0 commit comments