#!/bin/bash
# This script is for the production environment deployment.
# It's called by the post-receive hook.

set -e

# Navigate to the app directory
cd /home/jimmyg/mold_cost_online_tool || exit

# Environment
export COMPOSE_PROJECT_NAME=mold_cost_production
COMPOSE_FILE="podman-compose.yml"
LOG_FILE="/home/jimmyg/mold_cost_online_tool/logs/deploy.log"

echo "---" >> "$LOG_FILE"
echo "[$(date)] Starting PRODUCTION deployment..." >> "$LOG_FILE"

# The post-receive hook already ensures the code is updated.

# Build the new image
echo "Building new container image..." >> "$LOG_FILE"
podman-compose -f "$COMPOSE_FILE" build --no-cache >> "$LOG_FILE" 2>&1

# Restart the services
echo "Restarting services..." >> "$LOG_FILE"
podman-compose -f "$COMPOSE_FILE" down >> "$LOG_FILE" 2>&1
podman-compose -f "$COMPOSE_FILE" up -d >> "$LOG_FILE" 2>&1

echo "[$(date)] PRODUCTION deployment finished." >> "$LOG_FILE" 