Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for using repo mirrors for rocky-container-stackhpc #59

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions elements/containerfile/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
=============
containerfile
=============

Base element for creating images from container files (aka
Dockerfiles).

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_CONTAINERFILE_DOCKERFILE``.

Set ``DIB_CONTAINERFILE_RUNTIME`` to ``docker`` to use Docker for building
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.

Set ``DIB_CONTAINERFILE_BUILDOPTS`` to pass any other options to build command, e.g. ``--from docker.io/library/ubuntu:jammy --build-arg=HTTP_PROXY=http://10.20.30.2:1234``
1 change: 1 addition & 0 deletions elements/containerfile/element-provides
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
operating-system
97 changes: 97 additions & 0 deletions elements/containerfile/root.d/08-containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash
#
# Copyright 2015 Hewlett-Packard Development Company, L.P.
# Copyright 2019 Red Hat, INC.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
if [ ${DIB_DEBUG_TRACE:-1} -gt 0 ]; then
set -x
fi
set -eu
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 [[ -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

if [ -z "${DIB_CONTAINERFILE_DOCKERFILE:-}" ]; 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_CONTAINERFILE_DOCKERFILE="${containerfile}"
break
fi
done

$_xtrace

if [ -z "${DIB_CONTAINERFILE_DOCKERFILE:-}" ]; then
echo "*** DIB_CONTAINERFILE_DOCKERFILE not specified or found!"
exit 1
fi
fi

# Use the image cache directory as the default context, so anything
# there is automatically available for COPY commands.
DIB_CONTAINER_CONTEXT=${DIB_CONTAINER_CONTEXT:-${DIB_IMAGE_CACHE}/containerfile}

mkdir -p $DIB_CONTAINER_CONTEXT

if [[ ${DIB_CONTAINERFILE_RUNTIME_ROOT:-0} -gt 0 ]]; then
_sudo="sudo"
else
_sudo=""
fi

_podman_build_image="dib-tmp-work-image-$RANDOM"
_podman_export_container="dib-tmp-export-$RANDOM"

function podman_cleanup() {
echo "Cleaning up container ${_podman_export_container}"
${_sudo} ${DIB_CONTAINERFILE_RUNTIME} rm ${_podman_export_container} || true
echo "Cleaning up build image ${_podman_build_image}"
${_sudo} ${DIB_CONTAINERFILE_RUNTIME} rmi ${_podman_build_image} || true
}

trap "podman_cleanup" EXIT

${_sudo} ${DIB_CONTAINERFILE_RUNTIME} build ${DIB_CONTAINERFILE_RUNTIME_NETWORK} -t ${_podman_build_image} -f $DIB_CONTAINERFILE_DOCKERFILE ${DIB_CONTAINERFILE_BUILDOPTS:-} $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 -

sudo rm -f ${TARGET_ROOT}/.extra_settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Verify we can build an image from a containerfile.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
openstack-ci-mirrors
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# For the openstack-ci-mirrors element
export DISTRO_NAME=ubuntu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
path="$( dirname $path)"
export DIB_CONTAINERFILE_DOCKERFILE="$path/files/Dockerfile"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM docker.io/library/ubuntu:jammy
RUN touch /testfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tar
12 changes: 12 additions & 0 deletions elements/rocky-container-stackhpc/containerfiles/9-stackhpc
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Based on https://github.com/openstack/diskimage-builder/blob/master/diskimage_builder/elements/rocky-container/containerfiles/9

FROM docker.io/rockylinux/rockylinux:9
ARG ROCKY_USE_MIRROR=false
ARG ROCKY_APPSTREAM_URL
ARG ROCKY_BASEOS_URL

RUN if [ ${ROCKY_USE_MIRROR} = "true" ]; then \
dnf -y install 'dnf-command(config-manager)' && \
dnf clean all && \
mkdir /tmp/orig_repos && mv -f /etc/yum.repos.d/* /tmp/orig_repos/ && \
dnf config-manager --add-repo ${ROCKY_APPSTREAM_URL} && \
dnf config-manager --add-repo ${ROCKY_BASEOS_URL} && \
dnf -y distro-sync && \
rm -f /etc/yum.repos.d/rocky*.repo; fi

RUN dnf group install -y 'Minimal Install' --allowerasing && \
dnf install -y findutils util-linux \
Expand Down