upstream CI: Allow podman options when creating containers

When using containers to test ansible-freeipa there's a need to deal
with 'podman' the development environment and the Azure environment. In
the Azure environment, with Ubuntu hosts, using 'cap-add' does not allow
FreeIPA to be installed on the containers, and they need to be executed
with privileged mode. On the other hand, on development environments,
such as recent Fedora hosts, there's no need to run the container with
extra privileges.

This patch modifies the utility function 'container_create' to allow the
usage of key-value argumes such as "cpus=4" and "privileged", that will
be used in the container creation.

The currently available options are "privileged", "cpus", "memory" and
"hostname". By default "cpus=2" and "hostname=ipaserver.test.local".

Also, too make the image build script more self-contained, if the
required Ansible collections are not installed, they will be temporarily
installed so that the image can be built.
This commit is contained in:
Rafael Guterres Jeffman
2024-10-25 14:18:57 -03:00
parent a8ce235261
commit c979843b1a
3 changed files with 55 additions and 17 deletions

View File

@@ -9,24 +9,35 @@ TOPDIR="$(readlink -f "${SCRIPTDIR}/../..")"
container_create() {
local name=${1}
local image=${2}
local hostname=${3}
local memory=${4:-"3g"}
local cpus=${5:-"2"}
shift 2
declare -a extra_opts=()
for opt in "$@"
do
[ -z "${opt}" ] && continue
case "${opt}" in
hostname=*) extra_opts+=("--${opt}") ;;
cpus=*) extra_opts+=("--${opt}") ;;
memory=*) extra_opts+=("--${opt}") ;;
privileged) extra_opts+=("--${opt}") ;;
*) log error "container_create: Invalid option: ${opt}" ;;
esac
done
[ -n "${hostname}" ] || die "No hostname given"
# ensure default values are set
[[ " ${extra_opts[*]} " =~ " --cpus=" ]] || extra_opts+=("--cpus=2")
[[ " ${extra_opts[*]} " =~ " --hostname=" ]] \
|| extra_opts+=("--hostname=ipaserver.test.local")
log info "= Creating ${name} ="
podman create \
--security-opt label=disable \
--name "${name}" \
--hostname "${hostname}" \
--network bridge:interface_name=eth0 \
--systemd true \
--cpus "${cpus}" \
--memory "${memory}" \
--name "${name}" \
--memory-swap -1 \
--no-hosts \
--replace \
"${extra_opts[@]}" \
"${image}"
echo
}