mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-06-10 18:55:53 +00:00
This change also removed ansible_python_interpreter setting in the inventory as the interpreter should be discovered by ansible for the distributions. The dockerfiles have been adapted to not force the installation of python3 for CentOS-Stream 8, 9 and 10.
124 lines
3.0 KiB
Bash
Executable File
124 lines
3.0 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"
|
|
|
|
valid_distro() {
|
|
find "${BASEDIR}/dockerfile" -type f -printf "%f\n" | tr "\n" " "
|
|
}
|
|
|
|
usage() {
|
|
local prog="${0##*/}"
|
|
cat << EOF
|
|
usage: ${prog} [-h] [i] distro
|
|
${prog} build a container image to test ansible-freeipa.
|
|
EOF
|
|
}
|
|
|
|
help() {
|
|
cat << EOF
|
|
positional arguments:
|
|
|
|
distro The base distro to build the test container.
|
|
Availble distros: $(valid_distro)
|
|
|
|
optional arguments:
|
|
|
|
-s Deploy IPA server
|
|
|
|
EOF
|
|
}
|
|
|
|
name="ansible-freeipa-image-builder"
|
|
hostname="ipaserver.test.local"
|
|
# Number of cpus is not available in usptream CI (Ubuntu 22.04).
|
|
# cpus="2"
|
|
memory="4g"
|
|
quayname="quay.io/ansible-freeipa/upstream-tests"
|
|
deploy_server="N"
|
|
|
|
while getopts ":hs" option
|
|
do
|
|
case "${option}" in
|
|
h) help && exit 0 ;;
|
|
s) deploy_server="Y" ;;
|
|
*) die -u "Invalid option: ${option}" ;;
|
|
esac
|
|
done
|
|
|
|
shift $((OPTIND - 1))
|
|
distro=${1:-}
|
|
|
|
[ -n "${distro}" ] || die "Distro needs to be given.\nUse one of: $(valid_distro)"
|
|
|
|
[ -f "${BASEDIR}/dockerfile/${distro}" ] \
|
|
|| die "${distro} is not a valid distro target.\nUse one of: $(valid_distro)"
|
|
|
|
container_check
|
|
|
|
if [ "${deploy_server}" == "Y" ]
|
|
then
|
|
[ -n "$(command -v "ansible-playbook")" ] || die "ansible-playbook is required to install FreeIPA."
|
|
|
|
deploy_playbook="${TOPDIR}/playbooks/install-server.yml"
|
|
[ -f "${deploy_playbook}" ] || die "Can't find playbook '${deploy_playbook}'"
|
|
|
|
inventory_file="${BASEDIR}/build-inventory"
|
|
[ -f "${inventory_file}" ] || die "Can't find inventory '${inventory_file}'"
|
|
fi
|
|
|
|
container_state=$(container_get_state "${name}")
|
|
|
|
tag="${distro}-base"
|
|
server_tag="${distro}-server"
|
|
|
|
container_remove_image_if_exists "${tag}"
|
|
[ "${deploy_server}" == "Y" ] && \
|
|
container_remove_image_if_exists "${server_tag}"
|
|
|
|
container_build "${tag}" "${BASEDIR}/dockerfile/${distro}" "${BASEDIR}"
|
|
container_create "${name}" "${tag}" "${hostname}" "${memory}"
|
|
container_commit "${name}" "${quayname}:${tag}"
|
|
|
|
if [ "${deploy_server}" == "Y" ]
|
|
then
|
|
deployed=false
|
|
|
|
[ "${container_state}" != "running" ] && container_start "${name}"
|
|
|
|
container_wait_for_journald "${name}"
|
|
|
|
log info "= Deploying IPA ="
|
|
if ansible-playbook -u root -i "${inventory_file}" "${deploy_playbook}"
|
|
then
|
|
deployed=true
|
|
fi
|
|
echo
|
|
|
|
if $deployed; then
|
|
log info "= Enabling services ="
|
|
container_exec "${name}" systemctl enable fixnet
|
|
container_exec "${name}" systemctl enable fixipaip
|
|
echo
|
|
fi
|
|
|
|
container_stop "${name}"
|
|
|
|
$deployed || die "Deployment failed"
|
|
|
|
container_commit "${name}" "${quayname}:${server_tag}"
|
|
fi
|
|
|
|
log info "= DONE: Image created. ="
|
|
|
|
# For tests:
|
|
# podman start "${name}"
|
|
# while [ -n "$(podman exec ansible-test systemctl list-jobs | grep -vi "no jobs running")" ]; do echo "waiting.."; sleep 5; done
|
|
# # Run tests
|
|
# podman stop "${name}"
|