#!/bin/bash
set -euo pipefail

CONTAINER_NAME="website"
CONTAINER_TAG="thomaswilson/website:latest"
DATABASE_URL="file:/data/local.db"

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
DATA_DIR="${ROOT_DIR}/data"
LOCAL_VOLUME="${DATA_DIR}:/data:Z"

mkdir -p "${DATA_DIR}"

podman container stop "$CONTAINER_NAME" || true
podman container rm "$CONTAINER_NAME" || true

podman build -t "$CONTAINER_TAG" -f "$ROOT_DIR/web.Dockerfile" "$ROOT_DIR"

podman run -d \
  -p 3000:3000 \
  --name "$CONTAINER_NAME" \
  -e PRIVATE_DATABASE_URL="$DATABASE_URL" \
  -e DATABASE_URL="$DATABASE_URL" \
  -v "$LOCAL_VOLUME" \
  --restart unless-stopped \
  "$CONTAINER_TAG"
