Merge pull request #371 from nitkon/master

osbuilder: Add USE_PODMAN as an alternate for USE_DOCKER
This commit is contained in:
Salvador Fuentes 2019-10-02 13:51:57 -05:00 committed by GitHub
commit 494272b0ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 44 additions and 25 deletions

View File

@ -76,8 +76,9 @@ distro specific commands (e.g.: `debootstrap` for Debian or `yum` for CentOS).
The `dracut` build method uses the distro-agnostic tool `dracut` to obtain the same goal. The `dracut` build method uses the distro-agnostic tool `dracut` to obtain the same goal.
By default components are run on the host system. However, some components By default components are run on the host system. However, some components
offer the ability to run from within Docker (for ease of setup) by setting the offer the ability to run from within a container (for ease of setup) by setting the
`USE_DOCKER=true` variable. `USE_DOCKER=true` or `USE_PODMAN=true` variable. If both are set, `USE_DOCKER=true`
takes precedence over `USE_PODMAN=true`.
For more detailed information, consult the documentation for a particular component. For more detailed information, consult the documentation for a particular component.

View File

@ -3,7 +3,7 @@
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
From fedora:latest From docker.io/fedora:latest
RUN [ -n "$http_proxy" ] && sed -i '$ a proxy='$http_proxy /etc/dnf/dnf.conf ; true RUN [ -n "$http_proxy" ] && sed -i '$ a proxy='$http_proxy /etc/dnf/dnf.conf ; true

View File

@ -89,6 +89,8 @@ Extra environment variables:
FS_TYPE: Filesystem type to use. Only xfs and ext4 are supported. FS_TYPE: Filesystem type to use. Only xfs and ext4 are supported.
USE_DOCKER: If set will build image in a Docker Container (requries docker) USE_DOCKER: If set will build image in a Docker Container (requries docker)
DEFAULT: not set DEFAULT: not set
USE_PODMAN: If set and USE_DOCKER not set, will build image in a Podman Container (requries podman)
DEFAULT: not set
Following diagram shows how the resulting image will look like Following diagram shows how the resulting image will look like
@ -117,8 +119,8 @@ EOT
} }
# build the image using docker # build the image using container engine
build_with_docker() { build_with_container() {
local rootfs="$1" local rootfs="$1"
local image="$2" local image="$2"
local fs_type="$3" local fs_type="$3"
@ -126,16 +128,16 @@ build_with_docker() {
local root_free_space="$5" local root_free_space="$5"
local agent_bin="$6" local agent_bin="$6"
local agent_init="$7" local agent_init="$7"
local docker_image_name="image-builder-osbuilder" local container_image_name="image-builder-osbuilder"
local shared_files="" local shared_files=""
image_dir=$(readlink -f "$(dirname "${image}")") image_dir=$(readlink -f "$(dirname "${image}")")
image_name=$(basename "${image}") image_name=$(basename "${image}")
docker build \ "${container_engine}" build \
--build-arg http_proxy="${http_proxy}" \ --build-arg http_proxy="${http_proxy}" \
--build-arg https_proxy="${https_proxy}" \ --build-arg https_proxy="${https_proxy}" \
-t "${docker_image_name}" "${script_dir}" -t "${container_image_name}" "${script_dir}"
readonly mke2fs_conf="/etc/mke2fs.conf" readonly mke2fs_conf="/etc/mke2fs.conf"
if [ -f "${mke2fs_conf}" ]; then if [ -f "${mke2fs_conf}" ]; then
@ -145,7 +147,7 @@ build_with_docker() {
#Make sure we use a compatible runtime to build rootfs #Make sure we use a compatible runtime to build rootfs
# In case Clear Containers Runtime is installed we dont want to hit issue: # In case Clear Containers Runtime is installed we dont want to hit issue:
#https://github.com/clearcontainers/runtime/issues/828 #https://github.com/clearcontainers/runtime/issues/828
docker run \ "${container_engine}" run \
--rm \ --rm \
--runtime runc \ --runtime runc \
--privileged \ --privileged \
@ -161,7 +163,7 @@ build_with_docker() {
-v "${rootfs}":"/rootfs" \ -v "${rootfs}":"/rootfs" \
-v "${image_dir}":"/image" \ -v "${image_dir}":"/image" \
${shared_files} \ ${shared_files} \
${docker_image_name} \ ${container_image_name} \
bash "/osbuilder/${script_name}" -o "/image/${image_name}" /rootfs bash "/osbuilder/${script_name}" -o "/image/${image_name}" /rootfs
} }
@ -466,9 +468,15 @@ main() {
exit 0 exit 0
fi fi
if [ -n "${USE_DOCKER}" ] ; then if [ -n "${USE_DOCKER}" ]; then
build_with_docker "${rootfs}" "${image}" "${fs_type}" "${block_size}" \ container_engine="docker"
"${root_free_space}" "${agent_bin}" "${agent_init}" elif [ -n "${USE_PODMAN}" ]; then
container_engine="podman"
fi
if [ -n "$container_engine" ]; then
build_with_container "${rootfs}" "${image}" "${fs_type}" "${block_size}" \
"${root_free_space}" "${agent_bin}" "${agent_init}" "${container_engine}"
exit $? exit $?
fi fi

View File

@ -3,7 +3,7 @@
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
From golang:@GO_VERSION@-alpine From docker.io/golang:@GO_VERSION@-alpine
RUN apk update && apk add \ RUN apk update && apk add \
git \ git \

View File

@ -3,7 +3,7 @@
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
From centos:@OS_VERSION@ From docker.io/centos:@OS_VERSION@
@SET_PROXY@ @SET_PROXY@

View File

@ -3,7 +3,7 @@
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
From fedora:30 From docker.io/fedora:30
@SET_PROXY@ @SET_PROXY@

View File

@ -4,7 +4,7 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# NOTE: OS_VERSION is set according to config.sh # NOTE: OS_VERSION is set according to config.sh
from debian:@OS_VERSION@ from docker.io/debian:@OS_VERSION@
# RUN commands # RUN commands
RUN apt-get update && apt-get install -y curl wget systemd debootstrap git build-essential chrony RUN apt-get update && apt-get install -y curl wget systemd debootstrap git build-essential chrony

View File

@ -3,7 +3,7 @@
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
FROM euleros:@OS_VERSION@ FROM docker.io/euleros:@OS_VERSION@
@SET_PROXY@ @SET_PROXY@

View File

@ -3,7 +3,7 @@
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
From fedora:@OS_VERSION@ From docker.io/fedora:@OS_VERSION@
@SET_PROXY@ @SET_PROXY@

View File

@ -126,6 +126,10 @@ USE_DOCKER If set, build the rootfs inside a container (requires
Docker). Docker).
Default value: <not set> Default value: <not set>
USE_PODMAN If set and USE_DOCKER not set, then build the rootfs inside
a podman container (requires podman).
Default value: <not set>
DOCKER_RUNTIME Docker runtime to use when USE_DOCKER is set. DOCKER_RUNTIME Docker runtime to use when USE_DOCKER is set.
Default value: runc Default value: runc
@ -177,7 +181,7 @@ docker_extra_args()
args+=" --cap-add SYS_ADMIN" args+=" --cap-add SYS_ADMIN"
# When AppArmor is enabled, mounting inside a container is blocked with docker-default profile. # When AppArmor is enabled, mounting inside a container is blocked with docker-default profile.
# See https://github.com/moby/moby/issues/16429 # See https://github.com/moby/moby/issues/16429
args+=" --security-opt apparmor:unconfined" args+=" --security-opt apparmor=unconfined"
;; ;;
*) *)
;; ;;
@ -308,17 +312,23 @@ build_rootfs_distro()
echo "Required Go version: $GO_VERSION" echo "Required Go version: $GO_VERSION"
if [ -z "${USE_DOCKER}" ] ; then if [ -z "${USE_DOCKER}" ] && [ -z "${USE_PODMAN}" ]; then
#Generate an error if the local Go version is too old #Generate an error if the local Go version is too old
foundVersion=$(go version | sed -E "s/^.+([0-9]+\.[0-9]+\.[0-9]+).*$/\1/g") foundVersion=$(go version | sed -E "s/^.+([0-9]+\.[0-9]+\.[0-9]+).*$/\1/g")
compare_versions "$GO_VERSION" $foundVersion || \ compare_versions "$GO_VERSION" $foundVersion || \
die "Your Go version $foundVersion is older than the minimum expected Go version $GO_VERSION" die "Your Go version $foundVersion is older than the minimum expected Go version $GO_VERSION"
else else
if [ -n "${USE_DOCKER}" ]; then
container_engine="docker"
elif [ -n "${USE_PODMAN}" ]; then
container_engine="podman"
fi
image_name="${distro}-rootfs-osbuilder" image_name="${distro}-rootfs-osbuilder"
generate_dockerfile "${distro_config_dir}" generate_dockerfile "${distro_config_dir}"
docker build \ "$container_engine" build \
--build-arg http_proxy="${http_proxy}" \ --build-arg http_proxy="${http_proxy}" \
--build-arg https_proxy="${https_proxy}" \ --build-arg https_proxy="${https_proxy}" \
-t "${image_name}" "${distro_config_dir}" -t "${image_name}" "${distro_config_dir}"
@ -353,7 +363,7 @@ build_rootfs_distro()
#Make sure we use a compatible runtime to build rootfs #Make sure we use a compatible runtime to build rootfs
# In case Clear Containers Runtime is installed we dont want to hit issue: # In case Clear Containers Runtime is installed we dont want to hit issue:
#https://github.com/clearcontainers/runtime/issues/828 #https://github.com/clearcontainers/runtime/issues/828
docker run \ "$container_engine" run \
--env https_proxy="${https_proxy}" \ --env https_proxy="${https_proxy}" \
--env http_proxy="${http_proxy}" \ --env http_proxy="${http_proxy}" \
--env AGENT_VERSION="${AGENT_VERSION}" \ --env AGENT_VERSION="${AGENT_VERSION}" \

View File

@ -5,7 +5,7 @@
#suse: docker image to be used to create a rootfs #suse: docker image to be used to create a rootfs
#@OS_VERSION@: Docker image version to build this dockerfile #@OS_VERSION@: Docker image version to build this dockerfile
from opensuse/leap from docker.io/opensuse/leap
# This dockerfile needs to provide all the componets need to build a rootfs # This dockerfile needs to provide all the componets need to build a rootfs
# Install any package need to create a rootfs (package manager, extra tools) # Install any package need to create a rootfs (package manager, extra tools)

View File

@ -5,7 +5,7 @@
#ubuntu: docker image to be used to create a rootfs #ubuntu: docker image to be used to create a rootfs
#@OS_VERSION@: Docker image version to build this dockerfile #@OS_VERSION@: Docker image version to build this dockerfile
from ubuntu:@OS_VERSION@ from docker.io/ubuntu:@OS_VERSION@
# This dockerfile needs to provide all the componets need to build a rootfs # This dockerfile needs to provide all the componets need to build a rootfs
# Install any package need to create a rootfs (package manager, extra tools) # Install any package need to create a rootfs (package manager, extra tools)