Files
AdventureLog/adventurelog/scripts/install/lib/deploy.sh
Sean Morley 7f6bf1390a Add Docker and environment configuration files for AdventureLog
- Introduced .dockerignore to exclude unnecessary files from Docker context.
- Added .env.aio.example for minimal configuration of the AdventureLog All-in-One setup.
- Updated .env.example to include optional SITE_URL and GUNICORN_WORKERS settings.
- Enhanced deploy.sh script for improved deployment flexibility and backup options.
- Updated docker-compose files to use PostGIS 16-3.5 and added health checks for services.
- Created docker-compose.aio.yml for All-in-One deployment configuration.
- Improved health checks and service dependencies in docker-compose.dev.yml and docker-compose.yml.
- Added GitHub workflows for building and pushing Docker images, including smoke tests for AIO setup.
2026-06-06 18:54:25 -04:00

119 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
# Deploy containers and wait for health.
set -euo pipefail
validate_env_file() {
if [[ ! -f "scripts/validate-env.sh" ]]; then
log_warning "validate-env.sh not found — skipping validation"
return 0
fi
log_info "Validating $ENV_FILE ..."
if ! bash scripts/validate-env.sh "$ENV_FILE"; then
log_error "Environment validation failed"
exit 1
fi
log_success "Environment validated"
}
print_pull_failure_help() {
echo "" >&2
log_error "Failed to pull Docker images."
echo "" >&2
echo "Common fixes:" >&2
echo " • Check your internet connection" >&2
echo " • If you see 'denied' from ghcr.io, wait a moment and retry" >&2
echo " • Try: docker login ghcr.io (only if using a private registry token)" >&2
echo " • Manual pull: docker compose --env-file ${ENV_FILE} -f ${COMPOSE_FILE} pull" >&2
echo "" >&2
echo "To build from source instead, clone the full AdventureLog repo and run:" >&2
echo " docker compose -f docker-compose.aio.yml build && docker compose -f docker-compose.aio.yml up -d" >&2
echo "" >&2
}
start_services() {
if [[ "$DRY_RUN" == true ]]; then
log_info "[dry-run] Would run: run_compose pull && run_compose up -d"
return 0
fi
log_info "Pulling Docker images (this may take a few minutes)..."
echo "" >&2
if ! run_compose pull; then
print_pull_failure_help
exit 1
fi
echo "" >&2
log_success "Images pulled"
log_info "Starting containers..."
if run_compose up -d --remove-orphans --wait 2>/dev/null; then
log_success "Containers started"
elif run_compose up -d --remove-orphans; then
log_success "Containers started (without --wait)"
else
log_error "Failed to start containers"
run_compose ps || true
exit 1
fi
}
wait_for_health() {
local url="${1:-$SITE_URL}"
local max_attempts="${2:-300}"
local attempt=1
local health_url="${url%/}/health"
if [[ "$DRY_RUN" == true ]]; then
log_info "[dry-run] Would wait for $health_url"
return 0
fi
log_info "Waiting for AdventureLog (up to $((max_attempts / 6)) minutes on first boot)..."
while (( attempt <= max_attempts )); do
if curl -fsS -o /dev/null "$health_url" 2>/dev/null; then
echo "" >&2
log_success "Health check passed: $health_url"
return 0
fi
local pct=$(( attempt * 100 / max_attempts ))
local frame='⠋'
case $(( attempt % 4 )) in
1) frame='⠙' ;;
2) frame='⠹' ;;
3) frame='⠸' ;;
esac
printf "\r ${CYAN}${frame}${NC} Waiting for ${health_url} ${DIM}(${pct}%%)${NC} " >&2
sleep 2
((attempt++)) || true
done
printf "\r\033[K" >&2
log_warning "Health check timed out — service may still be starting (first boot imports world data)"
run_compose ps || true
log_info "Recent logs:"
docker logs "$LOG_CONTAINER" --tail 30 2>&1 || true
}
cleanup_on_failure() {
if [[ -f ".env.aio.backup" ]]; then
mv .env.aio.backup .env.aio 2>/dev/null || true
fi
if [[ -f ".env.backup" ]]; then
mv .env.backup .env 2>/dev/null || true
fi
if [[ "$DRY_RUN" != true ]] && command -v docker &>/dev/null; then
run_compose down --remove-orphans 2>/dev/null || true
fi
}
run_deploy_phase() {
print_step_header 6 "$WIZARD_TOTAL" "Deploy"
validate_env_file
start_services
print_step_header 7 "$WIZARD_TOTAL" "Health check"
if [[ "$SETUP_TYPE" == "aio" ]]; then
wait_for_health "$SITE_URL" 300
else
wait_for_health "$FRONTEND_ORIGIN" 300
fi
}