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

ROOT=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd)
env_file=${1:-"$ROOT/.env.edge"}

if [[ "$env_file" != /* ]]; then
  env_file="$ROOT/$env_file"
fi

if [[ ! -f "$env_file" ]]; then
  echo "Edge environment does not exist: $env_file" >&2
  exit 1
fi

"$ROOT/scripts/validate-edge-env.sh" "$env_file"

exec docker compose \
  --project-directory "$ROOT" \
  --env-file "$env_file" \
  --file "$ROOT/compose.edge.yaml" \
  up -d --build --wait --remove-orphans
