diff --git a/diskimage_builder/elements/containerfile/README.rst b/diskimage_builder/elements/containerfile/README.rst index 3ad02729..5fa878c3 100644 --- a/diskimage_builder/elements/containerfile/README.rst +++ b/diskimage_builder/elements/containerfile/README.rst @@ -5,5 +5,10 @@ containerfile Base element for creating images from container files (aka Dockerfiles). -To use this element, create a container file (Dockerfile), and supply -the path to that file in the environment variable `DIB_CONTAINER_FILE`. +Usually this element will be called via a more specific distro element +which provides an environment for building a full image. This element +will search active elements for a container file located in +`containerfiles/${DIB_RELEASE}`. + +Alternatively, to use this element directly supply the path to a +container file in the environment variable `DIB_CONTAINER_FILE`. diff --git a/diskimage_builder/elements/containerfile/root.d/08-containerfile b/diskimage_builder/elements/containerfile/root.d/08-containerfile index 4ea65728..47de3a34 100755 --- a/diskimage_builder/elements/containerfile/root.d/08-containerfile +++ b/diskimage_builder/elements/containerfile/root.d/08-containerfile @@ -25,7 +25,26 @@ if [ -f ${TARGET_ROOT}/.extra_settings ] ; then . ${TARGET_ROOT}/.extra_settings fi -[ -n "$DIB_CONTAINER_FILE" ] +if [ -z "${DIB_CONTAINER_FILE:-}" ]; then + _xtrace=$(set +o | grep xtrace) + set +o xtrace + + eval declare -A image_elements=($(get_image_element_array)) + + for i in "${!image_elements[@]}"; do + element=$i + element_dir=${image_elements[$i]} + + containerfile="${element_dir}/containerfiles/${DIB_RELEASE}" + if [ -f "${containerfile}" ]; then + echo "Found container file ${containerfile}" + DIB_CONTAINER_FILE="${containerfile}" + break + fi + done + + $_xtrace +fi # Use the image cache directory as the default context, so anything # there is automatically available for COPY commands.