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

