#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd -- "$SCRIPT_DIR/.." && pwd)"

ENV_FILE="$ROOT_DIR/.env"
COMPOSE_FILE="$ROOT_DIR/docker/compose.yml"

if [ ! -f "$ENV_FILE" ]; then
  echo "Error: env file not found at $ENV_FILE" >&2
  exit 1
fi

set -a
source "$ENV_FILE"
set +a

sudo docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE" pull \
  "$BACKEND_CONTAINER_NAME" "$DASHBOARD_CONTAINER_NAME"
sudo docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE" up -d \
  "$BACKEND_CONTAINER_NAME" "$DASHBOARD_CONTAINER_NAME"
