mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-03-26 21:33:05 +00:00
rjeffman: this is a fixup for infra/images/build.sh
This patch modifies the image building script by adding: - An usage message. - An option "-I" to NOT install IPA to the generated container. - An opiton "-c NAME" to both set the name and use an existing container to ONLY install IPA. - Rename "scenario" to "DISTRO" as "scenario" should be used for the container scenario usage, rather than the distro (I'll change the name also in the Azure scripts) - Use 'log' (from shlog) to print messages.
This commit is contained in:
committed by
Thomas Woerner
parent
b0e03a032d
commit
fb6fed58cb
@@ -3,61 +3,135 @@
|
|||||||
BASEDIR="$(readlink -f "$(dirname "$0")")"
|
BASEDIR="$(readlink -f "$(dirname "$0")")"
|
||||||
TOPDIR="$(readlink -f "${BASEDIR}/../..")"
|
TOPDIR="$(readlink -f "${BASEDIR}/../..")"
|
||||||
|
|
||||||
scenario=${1:-}
|
. "${TOPDIR}/utils/shfun"
|
||||||
name="ansible-test"
|
|
||||||
|
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"
|
hostname="ipaserver.test.local"
|
||||||
cpus="2"
|
# Number of cpus is not available in usptream CI (Ubuntu 22.04).
|
||||||
|
# cpus="2"
|
||||||
memory="4g"
|
memory="4g"
|
||||||
quayname="quay.io/ansible-freeipa/upstream-tests"
|
quayname="quay.io/ansible-freeipa/upstream-tests"
|
||||||
|
deploy_server="N"
|
||||||
|
|
||||||
if [ -z "${scenario}" ]; then
|
while getopts ":hs" option
|
||||||
echo "ERROR: Image needs to be given"
|
do
|
||||||
exit 1
|
case "${option}" in
|
||||||
fi
|
h) help && exit 0 ;;
|
||||||
if [ ! -f "${BASEDIR}/dockerfile/${scenario}" ]; then
|
s) deploy_server="Y" ;;
|
||||||
echo "ERROR: ${scenario} is not a valid image"
|
*) die -u "Invalid option: ${option}" ;;
|
||||||
exit 1
|
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)"
|
||||||
|
|
||||||
|
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}/inventory"
|
||||||
|
[ -f "${inventory_file}" ] || die "Can't find inventory '${inventory_file}'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "= Cleanup existing ${scenario} ="
|
container_state="$(podman ps -q --all --format "{{.State}}" --filter "name=${name}")"
|
||||||
podman image rm "${scenario}" --force
|
|
||||||
echo
|
|
||||||
|
|
||||||
echo "= Building ${scenario} ="
|
tag="${distro}-base"
|
||||||
podman build -t "${scenario}" -f "${BASEDIR}/dockerfile/${scenario}" \
|
server_tag="${distro}-server"
|
||||||
|
|
||||||
|
# in older (as in Ubuntu 22.04) podman versions,
|
||||||
|
# 'podman image rm --force' fails if the image
|
||||||
|
# does not exist.
|
||||||
|
remove_image_if_exists()
|
||||||
|
{
|
||||||
|
local tag_to_remove
|
||||||
|
tag_to_remove="${1}"
|
||||||
|
if podman image exists "${tag_to_remove}"
|
||||||
|
then
|
||||||
|
log info "= Cleanup ${tag_to_remove} ="
|
||||||
|
podman image rm "${tag_to_remove}" --force
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
remove_image_if_exists "${tag}"
|
||||||
|
[ "${deploy_server}" == "Y" ] && remove_image_if_exists "${server_tag}"
|
||||||
|
|
||||||
|
|
||||||
|
log info "= Building ${tag} ="
|
||||||
|
podman build -t "${tag}" -f "${BASEDIR}/dockerfile/${distro}" \
|
||||||
"${BASEDIR}"
|
"${BASEDIR}"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
echo "= Creating ${name} ="
|
log info "= Creating ${name} ="
|
||||||
podman create --privileged --name "${name}" --hostname "${hostname}" \
|
podman create --privileged --name "${name}" --hostname "${hostname}" \
|
||||||
--network bridge:interface_name=eth0 --systemd true \
|
--network bridge:interface_name=eth0 --systemd true \
|
||||||
--cpus "${cpus}" --memory "${memory}" --memory-swap -1 --no-hosts \
|
--memory "${memory}" --memory-swap -1 --no-hosts \
|
||||||
--replace "${scenario}"
|
--replace "${tag}"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
echo "= Starting ${name} ="
|
log info "= Committing \"${quayname}:${tag}\" ="
|
||||||
podman start "${name}"
|
podman commit "${name}" "${quayname}:${tag}"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
echo "= Installing IPA ="
|
if [ "${deploy_server}" == "Y" ]
|
||||||
ansible-playbook -i "${BASEDIR}/inventory" \
|
then
|
||||||
"${TOPDIR}/playbooks/install-server.yml"
|
log info "= Starting ${name} ="
|
||||||
echo
|
[ "${container_state}" == "running" ] || podman start "${name}"
|
||||||
|
echo
|
||||||
|
|
||||||
echo "= Enabling additional services ="
|
log info "= Deploying IPA ="
|
||||||
podman exec "${name}" systemctl enable fixnet
|
ansible-playbook -i "${inventory_file}" "${deploy_playbook}"
|
||||||
podman exec "${name}" systemctl enable fixipaip
|
echo
|
||||||
echo
|
|
||||||
|
|
||||||
echo "= Stopping ${name} ="
|
log info "= Enabling additional services ="
|
||||||
podman stop "${name}"
|
podman exec "${name}" systemctl enable fixnet
|
||||||
echo
|
podman exec "${name}" systemctl enable fixipaip
|
||||||
|
echo
|
||||||
|
|
||||||
|
log info "= Stopping container ${name} ="
|
||||||
|
podman stop "${name}"
|
||||||
|
echo
|
||||||
|
|
||||||
echo "= Committing \"${quayname}:${scenario}\" ="
|
log info "= Committing \"${quayname}:${server_tag}\" ="
|
||||||
podman commit "${name}" "${quayname}:${scenario}"
|
podman commit "${name}" "${quayname}:${server_tag}"
|
||||||
echo
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
echo "= DONE ="
|
log info "= DONE: Image created. ="
|
||||||
|
|
||||||
# For tests:
|
# For tests:
|
||||||
# podman start "${name}"
|
# podman start "${name}"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[ipaserver]
|
[ipaserver]
|
||||||
ansible-test ansible_connection=podman ansible_python_interpreter=/usr/bin/python3
|
ansible-freeipa-image-builder ansible_connection=podman ansible_python_interpreter=/usr/bin/python3
|
||||||
|
|
||||||
[ipaserver:vars]
|
[ipaserver:vars]
|
||||||
ipaadmin_password=SomeADMINpassword
|
ipaadmin_password=SomeADMINpassword
|
||||||
|
|||||||
Reference in New Issue
Block a user