#!/bin/bash

# script/setup: Set up container for the first time after cloning

set -e

cd "$(dirname "$0")/.."

source version

script/bootstrap

echo "==> Setting up container kontor-quarkus"
if podman image exists localhost/kontor-quarkus:$kontorVersion; then
    echo "  => Image localhost/kontor-quarkus:$kontorVersion available"
fi
if podman container exists kontor-quarkus; then
    if podman ps -q --filter "name=kontor-quarkus"; then
        echo "  => kontor-quarkus is running"
    fi
else
    podman run -d \
        --replace \
        --pod kontor \
        --name kontor-quarkus \
        --label "io.containers.autoupdate=local" \
        --label "PODMAN_SYSTEMD_UNIT=kontor-quarkus.service" \
        --health-cmd='curl -f http://kontor-quarkus:8300/q/health || exit 1' \
        --health-interval=1s \
        --health-timeout=5s \
        --health-retries=10 \
        localhost/kontor-quarkus:$kontorVersion
fi

