#!/bin/bash
# start.sh — Start GnommoEditor on the server.
# Safe to run repeatedly (e.g. after a reboot).
# The `gnommo` network is shared with gu_common/gnommoweb; create it here
# if it doesn't already exist so startup is not order-dependent.

set -e

# Ensure shared external volumes exist
for vol in glitch_postgres_data glitch_minio_data; do
  if ! docker volume inspect "$vol" >/dev/null 2>&1; then
    echo "==> Creating volume: $vol"
    docker volume create "$vol"
  fi
done

# Ensure the shared gnommo network exists
if ! docker network inspect gnommo >/dev/null 2>&1; then
  echo "==> Creating shared Docker network: gnommo"
  docker network create gnommo
fi

# Bring up services
echo "==> Starting GnommoEditor..."
docker compose -f docker-compose.prod.yml --env-file .env.prod up -d "$@"

echo "==> Done."
