Files
AdventureLog/docker/shared/entrypoint-common.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

93 lines
2.4 KiB
Bash

#!/bin/bash
# Shared startup tasks for backend and AIO containers.
# Source from entrypoint.sh after environment variables are configured.
get_env() {
local var value
for var in "$@"; do
value="$(printenv "$var" 2>/dev/null || true)"
if [[ -n "$value" ]]; then
echo "$value"
return
fi
done
}
check_postgres() {
local db_host db_user db_name db_pass
db_host=$(get_env PGHOST)
db_user=$(get_env POSTGRES_USER PGUSER)
db_name=$(get_env POSTGRES_DB PGDATABASE)
db_pass=$(get_env POSTGRES_PASSWORD PGPASSWORD)
PGPASSWORD="$db_pass" psql -h "$db_host" -U "$db_user" -d "$db_name" -c '\q' >/dev/null 2>&1
}
wait_for_postgres() {
until check_postgres; do
>&2 echo "PostgreSQL is unavailable - sleeping"
sleep 1
done
>&2 echo "PostgreSQL is up - continuing..."
}
run_migrations() {
python manage.py migrate
}
create_superuser_if_needed() {
if [[ -n "${DJANGO_ADMIN_USERNAME:-}" && -n "${DJANGO_ADMIN_PASSWORD:-}" && -n "${DJANGO_ADMIN_EMAIL:-}" ]]; then
echo "Creating superuser..."
python manage.py shell <<EOF
from django.contrib.auth import get_user_model
from allauth.account.models import EmailAddress
User = get_user_model()
if not User.objects.filter(username='$DJANGO_ADMIN_USERNAME').exists():
superuser = User.objects.create_superuser(
username='$DJANGO_ADMIN_USERNAME',
email='$DJANGO_ADMIN_EMAIL',
password='$DJANGO_ADMIN_PASSWORD'
)
print("Superuser created successfully.")
EmailAddress.objects.create(
user=superuser,
email='$DJANGO_ADMIN_EMAIL',
verified=True,
primary=True
)
print("EmailAddress object created successfully for AllAuth.")
else:
print("Superuser already exists.")
EOF
fi
}
run_download_countries() {
if [[ "${SKIP_WORLD_DATA:-}" == "1" ]]; then
>&2 echo "SKIP_WORLD_DATA=1 — skipping download-countries"
return 0
fi
>&2 echo "Running download-countries (first boot may take several minutes; ensure ~2GB RAM is available)..."
python manage.py download-countries
local download_exit=$?
if [[ "$download_exit" -eq 137 ]]; then
>&2 echo "WARNING: download-countries was interrupted (likely out of memory). Retry with more RAM or set SKIP_WORLD_DATA=1."
exit 1
elif [[ "$download_exit" -ne 0 ]]; then
>&2 echo "ERROR: download-countries failed."
exit 1
fi
}
finalize_startup() {
if [[ -f /code/adventurelog.txt ]]; then
cat /code/adventurelog.txt
fi
/code/scripts/write-cron-env.sh
}