homelab-codex-ws/scripts/deploy/deploy-node.sh

67 lines
1.9 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# deployment-node.sh - To be run on the execution node (SOLARIA, PIHA, VPS)
# This script pulls the latest changes and ensures services are running.
set -e
# Configuration
REPO_PATH="${HOME}/homelab-codex-ws"
RUNTIME_PATH="/opt/homelab"
HOSTNAME=$(hostname | tr '[:lower:]' '[:upper:]')
echo "--- Starting Deployment on ${HOSTNAME} ---"
# 1. Update Repository
if [ ! -d "$REPO_PATH" ]; then
echo "Error: Repository not found at $REPO_PATH"
exit 1
fi
cd "$REPO_PATH"
echo "Pulling latest changes..."
git pull
# 2. Identify Services
# Based on our convention, we look for services assigned to this host
# For now, we'll check if a 'services.txt' exists in the host folder
SERVICE_LIST="${REPO_PATH}/hosts/$(hostname | tr '[:upper:]' '[:lower:]')/services.txt"
if [ ! -f "$SERVICE_LIST" ]; then
echo "No services.txt found for ${HOSTNAME}. Skipping service deployment."
exit 0
fi
# 3. Deploy Services
while IFS= read -r service || [ -n "$service" ]; do
[[ "$service" =~ ^#.*$ ]] && continue # Skip comments
[[ -z "$service" ]] && continue # Skip empty lines
echo "Deploying service: ${service}..."
COMPOSE_FILE="${REPO_PATH}/services/${service}/docker-compose.yml"
if [ ! -f "$COMPOSE_FILE" ]; then
echo "Warning: Compose file not found for ${service} at ${COMPOSE_FILE}"
continue
fi
# Target directory in runtime
TARGET_DIR="${RUNTIME_PATH}/services/${service}"
mkdir -p "$TARGET_DIR"
# We use the compose file from the repo directly
# but we can also handle overrides here
OVERRIDE_FILE="${RUNTIME_PATH}/config/${service}/docker-compose.override.yml"
COMPOSE_CMD="docker compose -f ${COMPOSE_FILE}"
if [ -f "$OVERRIDE_FILE" ]; then
echo "Using override file for ${service}"
COMPOSE_CMD="${COMPOSE_CMD} -f ${OVERRIDE_FILE}"
fi
$COMPOSE_CMD up -d --remove-orphans
done < "$SERVICE_LIST"
echo "--- Deployment Complete ---"