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

echo "Starting deployment on $(hostname) ($(date))"

# Ensure we're on the development branch and synced with origin
git fetch origin development
git checkout development
git reset --hard origin/development

echo "Pulling latest changes and building containers..."

# Try to pull image updates, but don't fail if registry isn't used
docker compose -f docker-compose.yml pull || true

# Build and bring up containers
docker compose -f docker-compose.yml up -d --build

echo "Cleaning up unused images..."
docker image prune -f || true

echo "Deployment finished successfully."
