mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-03-26 21:33:05 +00:00
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.
96 lines
2.3 KiB
Bash
Executable File
96 lines
2.3 KiB
Bash
Executable File
#!/bin/bash -eu
|
|
|
|
BASEDIR="$(readlink -f "$(dirname "$0")")"
|
|
TOPDIR="$(readlink -f "${BASEDIR}/../..")"
|
|
|
|
# shellcheck disable=SC1091
|
|
. "${BASEDIR}/shcontainer"
|
|
# shellcheck disable=SC1091
|
|
. "${TOPDIR}/utils/shfun"
|
|
|
|
usage() {
|
|
local prog="${0##*/}"
|
|
cat << EOF
|
|
usage: ${prog} [-h] [-l] [-n HOSTNAME ] image
|
|
${prog} start a prebuilt ansible-freeipa test container image.
|
|
EOF
|
|
}
|
|
|
|
help() {
|
|
cat << EOF
|
|
positional arguments:
|
|
|
|
image The image to start, leave empty to get list of images
|
|
|
|
optional arguments:
|
|
|
|
-h Show this message
|
|
-l Try to use local image first, if not found download.
|
|
-n HOSTNAME Set container hostname
|
|
|
|
NOTE:
|
|
- The hostname must be the same as the hostname of the container
|
|
when FreeIPA was deployed. Use only if you built the image and
|
|
defined its hostname.
|
|
|
|
EOF
|
|
}
|
|
|
|
list_images() {
|
|
local quay_api="https://quay.io/api/v1/repository/ansible-freeipa/upstream-tests/tag"
|
|
log info "Available images on quay:"
|
|
curl --silent -L "${quay_api}" | jq '.tags[]|.name' | tr -d '"'| sort | uniq | sed "s/.*/ &/"
|
|
echo
|
|
log info "Local images (use -l):"
|
|
local_image=$(container_image_list "${repo}:")
|
|
echo "${local_image}" | sed -e "s/.*://" | sed "s/.*/ &/"
|
|
echo
|
|
}
|
|
|
|
repo="quay.io/ansible-freeipa/upstream-tests"
|
|
name="ansible-freeipa-tests"
|
|
hostname="ipaserver.test.local"
|
|
try_local_first="N"
|
|
|
|
while getopts ":hln:" option
|
|
do
|
|
case "${option}" in
|
|
h) help && exit 0 ;;
|
|
l) try_local_first="Y" ;;
|
|
n) hostname="${OPTARG}" ;;
|
|
*) die -u "Invalid option: ${option}" ;;
|
|
esac
|
|
done
|
|
|
|
shift $((OPTIND - 1))
|
|
image=${1:-}
|
|
|
|
container_check
|
|
|
|
if [ -z "${image}" ]; then
|
|
list_images
|
|
exit 0
|
|
fi
|
|
|
|
local_image=
|
|
if [ "${try_local_first}" == "Y" ]; then
|
|
log info "= Trying to use local image first ="
|
|
local_image=$(container_image_list "${repo}:${image}")
|
|
[ -n "${local_image}" ] && log info "Found ${local_image}"
|
|
echo
|
|
fi
|
|
if [ -z "${local_image}" ]; then
|
|
log info "= Downloading from quay ="
|
|
local_image=$(container_pull "${repo}:${image}")
|
|
echo
|
|
fi
|
|
|
|
[ -z "${local_image}" ] && die "Image '${image}' is not valid"
|
|
|
|
container_create "${name}" "${local_image}" "hostname=${hostname}"
|
|
container_start "${name}"
|
|
container_wait_for_journald "${name}"
|
|
container_wait_up "${name}"
|
|
|
|
log info "Container ${name} is ready to be used."
|