infra/image/build.sh: Fail if deployment failed or podman is missing

If the deployment was enabled and failed, the script still continued
without failing. If podman was missing it failed without a proper error.

The script now fails and does not enable the services and also does not
commit after the failed deployment. Also is fails if podman is missing.
This commit is contained in:
Thomas Woerner
2024-07-31 15:33:19 +02:00
parent 785681f100
commit 0d246b1c11

View File

@@ -56,6 +56,8 @@ distro=${1:-}
[ -f "${BASEDIR}/dockerfile/${distro}" ] \ [ -f "${BASEDIR}/dockerfile/${distro}" ] \
|| die "${distro} is not a valid distro target.\nUse one of: $(valid_distro)" || die "${distro} is not a valid distro target.\nUse one of: $(valid_distro)"
[ -n "$(command -v "podman")" ] || die "podman is required."
if [ "${deploy_server}" == "Y" ] if [ "${deploy_server}" == "Y" ]
then then
[ -n "$(command -v "ansible-playbook")" ] || die "ansible-playbook is required to install FreeIPA." [ -n "$(command -v "ansible-playbook")" ] || die "ansible-playbook is required to install FreeIPA."
@@ -109,23 +111,32 @@ echo
if [ "${deploy_server}" == "Y" ] if [ "${deploy_server}" == "Y" ]
then then
deployed=false
log info "= Starting ${name} =" log info "= Starting ${name} ="
[ "${container_state}" == "running" ] || podman start "${name}" [ "${container_state}" == "running" ] || podman start "${name}"
echo echo
log info "= Deploying IPA =" log info "= Deploying IPA ="
ansible-playbook -i "${inventory_file}" "${deploy_playbook}" if ansible-playbook -i "${inventory_file}" "${deploy_playbook}"
then
deployed=true
fi
echo echo
log info "= Enabling additional services =" if $deployed; then
podman exec "${name}" systemctl enable fixnet log info "= Enabling additional services ="
podman exec "${name}" systemctl enable fixipaip podman exec "${name}" systemctl enable fixnet
echo podman exec "${name}" systemctl enable fixipaip
echo
fi
log info "= Stopping container ${name} =" log info "= Stopping container ${name} ="
podman stop "${name}" podman stop "${name}"
echo echo
$deployed || die "Deployment failed"
log info "= Committing \"${quayname}:${server_tag}\" =" log info "= Committing \"${quayname}:${server_tag}\" ="
podman commit "${name}" "${quayname}:${server_tag}" podman commit "${name}" "${quayname}:${server_tag}"
echo echo