Skip to content

Commit 9e5e820

Browse files
bcresseyginglis13
authored andcommitted
build.Dockerfile: support dnf5 for rpm download
"--downloadonly" is not a global option for dnf5; it's only supported for certain commands like "download" and "install". On the surface, "download" seems like a more appropriate command than "install", but in dnf5 it doesn't download all dependencies; it skips some of the conditional ones which are needed at install time. That leaves "install", but in dnf5, "install" doesn't support a "--downloaddir" option and always writes downloaded RPMs to the cache directory. To add dnf5 support, work around the "install" limitation by setting the cache directory option, and then pruning the output so we end up with all RPMs stored in a single top-level directory again. To retain dnf4 support, check whether "--downloaddir" is allowed, and pass that option if it is. Unlike dnf5, dnf4 won't copy packages from a local directory to the cache, so the option is required to copy the RPMs rather than just solving the transaction. Drop the unnecessary `createrepo_c` command while we're at it, since none of the subsequent stages care about the resulting repository. Signed-off-by: Ben Cressey <[email protected]>
1 parent 22b2516 commit 9e5e820

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

twoliter/embedded/build.Dockerfile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,20 +294,23 @@ RUN --mount=target=/host \
294294
EXTERNAL_KIT_REPOS+=("--repofrompath=${REPO_NAME},${REPO_PATH}" --enablerepo "${REPO_NAME}"); \
295295
done && \
296296
echo "${EXTERNAL_KIT_REPOS[@]}" && \
297+
mkdir -p /local/rpms && \
298+
download_dir_opt="$(dnf install --help | grep -Fwq downloaddir && echo "--downloaddir /local/rpms" ||:)" && \
297299
dnf -y \
298300
--disablerepo '*' \
299301
--repofrompath repo,./rpmbuild/RPMS \
300302
--enablerepo 'repo' \
301303
"${KIT_REPOS[@]}" \
302304
"${EXTERNAL_KIT_REPOS[@]}" \
303305
--nogpgcheck \
304-
--downloadonly \
305-
--downloaddir . \
306306
--forcearch "${ARCH}" \
307-
install $(printf "bottlerocket-%s\n" metadata ${PACKAGES}) && \
308-
mkdir -p /local/rpms && \
309-
mv *.rpm /local/rpms && \
310-
createrepo_c /local/rpms && \
307+
--setopt=cachedir=/local/rpms \
308+
install \
309+
--downloadonly \
310+
${download_dir_opt} \
311+
$(printf "bottlerocket-%s\n" metadata ${PACKAGES}) && \
312+
find /local/rpms -mindepth 2 -type f -name '*.rpm' -exec mv -t /local/rpms {} + && \
313+
find /local/rpms -mindepth 1 ! -name '*.rpm' -delete && \
311314
rm /output && \
312315
rm /bypass && \
313316
echo ${NOCACHE}

0 commit comments

Comments
 (0)