Skip to content
Snippets Groups Projects
Commit 50ba326e authored by Thomas Woerner's avatar Thomas Woerner
Browse files

infra/image/build.sh: Use new shcontainer

This removes a lot of duplicate code from the script.
parent 691e5915
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
BASEDIR="$(readlink -f "$(dirname "$0")")" BASEDIR="$(readlink -f "$(dirname "$0")")"
TOPDIR="$(readlink -f "${BASEDIR}/../..")" TOPDIR="$(readlink -f "${BASEDIR}/../..")"
# shellcheck disable=SC1091
. "${BASEDIR}/shcontainer"
# shellcheck disable=SC1091
. "${TOPDIR}/utils/shfun" . "${TOPDIR}/utils/shfun"
valid_distro() { valid_distro() {
...@@ -56,7 +59,7 @@ distro=${1:-} ...@@ -56,7 +59,7 @@ 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." container_check
if [ "${deploy_server}" == "Y" ] if [ "${deploy_server}" == "Y" ]
then then
...@@ -69,77 +72,46 @@ then ...@@ -69,77 +72,46 @@ then
[ -f "${inventory_file}" ] || die "Can't find inventory '${inventory_file}'" [ -f "${inventory_file}" ] || die "Can't find inventory '${inventory_file}'"
fi fi
container_state="$(podman ps -q --all --format "{{.State}}" --filter "name=${name}")" container_state=$(container_get_state "${name}")
tag="${distro}-base" tag="${distro}-base"
server_tag="${distro}-server" server_tag="${distro}-server"
# in older (as in Ubuntu 22.04) podman versions, container_remove_image_if_exists "${tag}"
# 'podman image rm --force' fails if the image [ "${deploy_server}" == "Y" ] && \
# does not exist. container_remove_image_if_exists "${server_tag}"
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}" container_build "${tag}" "${BASEDIR}/dockerfile/${distro}" "${BASEDIR}"
[ "${deploy_server}" == "Y" ] && remove_image_if_exists "${server_tag}" container_create "${name}" "${tag}" "${hostname}" "${memory}"
container_commit "${name}" "${quayname}:${tag}"
log info "= Building ${tag} ="
podman build -t "${tag}" -f "${BASEDIR}/dockerfile/${distro}" \
"${BASEDIR}"
echo
log info "= Creating ${name} ="
podman create --privileged --name "${name}" --hostname "${hostname}" \
--network bridge:interface_name=eth0 --systemd true \
--memory "${memory}" --memory-swap -1 --no-hosts \
--replace "${tag}"
echo
log info "= Committing \"${quayname}:${tag}\" ="
podman commit "${name}" "${quayname}:${tag}"
echo
if [ "${deploy_server}" == "Y" ] if [ "${deploy_server}" == "Y" ]
then then
deployed=false deployed=false
log info "= Starting ${name} =" [ "${container_state}" != "running" ] && container_start "${name}"
[ "${container_state}" == "running" ] || podman start "${name}"
echo container_wait_for_journald "${name}"
log info "= Deploying IPA =" log info "= Deploying IPA ="
if ansible-playbook -i "${inventory_file}" "${deploy_playbook}" if ansible-playbook -u root -i "${inventory_file}" "${deploy_playbook}"
then then
deployed=true deployed=true
fi fi
echo echo
if $deployed; then if $deployed; then
log info "= Enabling additional services =" log info "= Enabling services ="
podman exec "${name}" systemctl enable fixnet container_exec "${name}" systemctl enable fixnet
podman exec "${name}" systemctl enable fixipaip container_exec "${name}" systemctl enable fixipaip
echo echo
fi fi
log info "= Stopping container ${name} =" container_stop "${name}"
podman stop "${name}"
echo
$deployed || die "Deployment failed" $deployed || die "Deployment failed"
log info "= Committing \"${quayname}:${server_tag}\" =" container_commit "${name}" "${quayname}:${server_tag}"
podman commit "${name}" "${quayname}:${server_tag}"
echo
fi fi
log info "= DONE: Image created. =" log info "= DONE: Image created. ="
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment