From 7d782ae1c95cebb110bdf9e437276590f427406e Mon Sep 17 00:00:00 2001 From: Michal Nasiadka Date: Tue, 15 Mar 2022 13:17:42 +0000 Subject: [PATCH] containerfile: Add support for setting network driver Change-Id: Ia885237406bf4c7b9d49b349f374558ae746401f --- diskimage_builder/elements/containerfile/README.rst | 3 +++ .../elements/containerfile/root.d/08-containerfile | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/diskimage_builder/elements/containerfile/README.rst b/diskimage_builder/elements/containerfile/README.rst index c734f39a..093eee5a 100644 --- a/diskimage_builder/elements/containerfile/README.rst +++ b/diskimage_builder/elements/containerfile/README.rst @@ -19,3 +19,6 @@ images (default is ``podman``). Set ``DIB_CONTAINERFILE_RUNTIME_ROOT`` to ``1`` to run the runtime (Docker or ``podman``, per above) as ``root``. + +Set ``DIB_CONTAINERFILE_NETWORK_DRIVER`` to a network driver of your choice +(e.g. host) to use it instead of the default bridge during build. diff --git a/diskimage_builder/elements/containerfile/root.d/08-containerfile b/diskimage_builder/elements/containerfile/root.d/08-containerfile index 9dbe0d92..9bc961e2 100755 --- a/diskimage_builder/elements/containerfile/root.d/08-containerfile +++ b/diskimage_builder/elements/containerfile/root.d/08-containerfile @@ -28,6 +28,12 @@ if [[ "${DIB_CONTAINERFILE_PODMAN_ROOT:-0}" != '0' ]]; then DIB_CONTAINERFILE_RUNTIME_ROOT=1 fi +if [[ -z "${DIB_CONTAINERFILE_NETWORK_DRIVER:-}" ]]; then + DIB_CONTAINERFILE_RUNTIME_NETWORK="" +else + DIB_CONTAINERFILE_RUNTIME_NETWORK="--network ${DIB_CONTAINERFILE_NETWORK_DRIVER:-}" +fi + if [ -f ${TARGET_ROOT}/.extra_settings ] ; then . ${TARGET_ROOT}/.extra_settings fi @@ -77,8 +83,8 @@ function podman_cleanup() { trap "podman_cleanup" EXIT -${_sudo} ${DIB_CONTAINERFILE_RUNTIME} build -t ${_podman_build_image} -f $DIB_CONTAINERFILE_DOCKERFILE $DIB_CONTAINER_CONTEXT -${_sudo} ${DIB_CONTAINERFILE_RUNTIME} run --name ${_podman_export_container} -d ${_podman_build_image} /bin/sh +${_sudo} ${DIB_CONTAINERFILE_RUNTIME} build ${DIB_CONTAINERFILE_RUNTIME_NETWORK} -t ${_podman_build_image} -f $DIB_CONTAINERFILE_DOCKERFILE $DIB_CONTAINER_CONTEXT +${_sudo} ${DIB_CONTAINERFILE_RUNTIME} run ${DIB_CONTAINERFILE_RUNTIME_NETWORK} --name ${_podman_export_container} -d ${_podman_build_image} /bin/sh # NOTE(ianw) 2021-11-10 the tar must always be sudo to write out the chroot files # as other uids ${_sudo} ${DIB_CONTAINERFILE_RUNTIME} export ${_podman_export_container} | sudo tar -C $TARGET_ROOT --numeric-owner -xf -