containerfile: add support for Docker
In some build environments Docker is already installed - and adding podman is not an option. Add a new variable to toggle this, and rename the now incorrectly titled DIB_CONTAINERFILE_PODMAN_ROOT to just ...RUNTIME_ROOT to match. Change-Id: I677e4f491b40360dceabdf4f2a9e64c7cb493dc7
This commit is contained in:
parent
e78159cd44
commit
a02cb9ff74
@ -8,11 +8,14 @@ Dockerfiles).
|
|||||||
Usually this element will be called via a more specific distro element
|
Usually this element will be called via a more specific distro element
|
||||||
which provides an environment for building a full image. This element
|
which provides an environment for building a full image. This element
|
||||||
will search active elements for a container file located in
|
will search active elements for a container file located in
|
||||||
`containerfiles/${DIB_RELEASE}`.
|
``containerfiles/${DIB_RELEASE}``.
|
||||||
|
|
||||||
Alternatively, to use this element directly supply the path to a
|
Alternatively, to use this element directly supply the path to a
|
||||||
container file in the environment variable
|
container file in the environment variable
|
||||||
`DIB_CONTAINERFILE_DOCKERFILE`.
|
``DIB_CONTAINERFILE_DOCKERFILE``.
|
||||||
|
|
||||||
Set ``DIB_CONTAINERFILE_PODMAN_ROOT`` to ``1`` to run `podman` as
|
Set ``DIB_CONTAINERFILE_RUNTIME`` to ``docker`` to use Docker for building
|
||||||
`root`.
|
images (default is ``podman``).
|
||||||
|
|
||||||
|
Set ``DIB_CONTAINERFILE_RUNTIME_ROOT`` to ``1`` to run the runtime
|
||||||
|
(Docker or ``podman``, per above) as ``root``.
|
||||||
|
@ -21,6 +21,13 @@ fi
|
|||||||
set -eu
|
set -eu
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
|
: "${DIB_CONTAINERFILE_RUNTIME:=podman}"
|
||||||
|
|
||||||
|
# Convert the old value which was podman specific
|
||||||
|
if [[ "${DIB_CONTAINERFILE_PODMAN_ROOT:-0}" != '0' ]]; then
|
||||||
|
DIB_CONTAINERFILE_RUNTIME_ROOT=1
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -f ${TARGET_ROOT}/.extra_settings ] ; then
|
if [ -f ${TARGET_ROOT}/.extra_settings ] ; then
|
||||||
. ${TARGET_ROOT}/.extra_settings
|
. ${TARGET_ROOT}/.extra_settings
|
||||||
fi
|
fi
|
||||||
@ -52,7 +59,7 @@ DIB_CONTAINER_CONTEXT=${DIB_CONTAINER_CONTEXT:-${DIB_IMAGE_CACHE}/containerfile}
|
|||||||
|
|
||||||
mkdir -p $DIB_CONTAINER_CONTEXT
|
mkdir -p $DIB_CONTAINER_CONTEXT
|
||||||
|
|
||||||
if [[ ${DIB_CONTAINERFILE_PODMAN_ROOT:-0} -gt 0 ]]; then
|
if [[ ${DIB_CONTAINERFILE_RUNTIME_ROOT:-0} -gt 0 ]]; then
|
||||||
_sudo="sudo"
|
_sudo="sudo"
|
||||||
else
|
else
|
||||||
_sudo=""
|
_sudo=""
|
||||||
@ -63,17 +70,17 @@ _podman_export_container="dib-tmp-export-$RANDOM"
|
|||||||
|
|
||||||
function podman_cleanup() {
|
function podman_cleanup() {
|
||||||
echo "Cleaning up container ${_podman_export_container}"
|
echo "Cleaning up container ${_podman_export_container}"
|
||||||
${_sudo} podman rm ${_podman_export_container} || true
|
${_sudo} ${DIB_CONTAINERFILE_RUNTIME} rm ${_podman_export_container} || true
|
||||||
echo "Cleaning up build image ${_podman_build_image}"
|
echo "Cleaning up build image ${_podman_build_image}"
|
||||||
${_sudo} podman rmi ${_podman_build_image} || true
|
${_sudo} ${DIB_CONTAINERFILE_RUNTIME} rmi ${_podman_build_image} || true
|
||||||
}
|
}
|
||||||
|
|
||||||
trap "podman_cleanup" EXIT
|
trap "podman_cleanup" EXIT
|
||||||
|
|
||||||
${_sudo} podman build -t ${_podman_build_image} -f $DIB_CONTAINERFILE_DOCKERFILE $DIB_CONTAINER_CONTEXT
|
${_sudo} ${DIB_CONTAINERFILE_RUNTIME} build -t ${_podman_build_image} -f $DIB_CONTAINERFILE_DOCKERFILE $DIB_CONTAINER_CONTEXT
|
||||||
${_sudo} podman run --name ${_podman_export_container} -d ${_podman_build_image} /bin/sh
|
${_sudo} ${DIB_CONTAINERFILE_RUNTIME} run --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
|
# NOTE(ianw) 2021-11-10 the tar must always be sudo to write out the chroot files
|
||||||
# as other uids
|
# as other uids
|
||||||
${_sudo} podman export ${_podman_export_container} | sudo tar -C $TARGET_ROOT --numeric-owner -xf -
|
${_sudo} ${DIB_CONTAINERFILE_RUNTIME} export ${_podman_export_container} | sudo tar -C $TARGET_ROOT --numeric-owner -xf -
|
||||||
|
|
||||||
sudo rm -f ${TARGET_ROOT}/.extra_settings
|
sudo rm -f ${TARGET_ROOT}/.extra_settings
|
||||||
|
@ -66,4 +66,4 @@
|
|||||||
DIB_OS_CI_YUM_REPOS: "{{ dib_gate_mirror_repos|default(omit) }}"
|
DIB_OS_CI_YUM_REPOS: "{{ dib_gate_mirror_repos|default(omit) }}"
|
||||||
# NOTE(ianw) 2021-10-15 : this might be our bullseye images
|
# NOTE(ianw) 2021-10-15 : this might be our bullseye images
|
||||||
# having issues with non-root podman. This works for now.
|
# having issues with non-root podman. This works for now.
|
||||||
DIB_CONTAINERFILE_PODMAN_ROOT: 1
|
DIB_CONTAINERFILE_RUNTIME_ROOT: 1
|
||||||
|
Loading…
Reference in New Issue
Block a user