2025-12-24 14:35:17 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
# Database initialization entrypoint for PieFed
|
|
|
|
|
# This script runs as a Kubernetes Job before web/worker pods start
|
|
|
|
|
|
2026-01-14 22:33:45 +02:00
|
|
|
# Source common functions (wait_for_db, wait_for_redis, log)
|
|
|
|
|
. /usr/local/bin/entrypoint-common.sh
|
2025-12-24 14:35:17 +01:00
|
|
|
|
|
|
|
|
log "Starting PieFed database initialization..."
|
|
|
|
|
|
|
|
|
|
# Main initialization sequence
|
|
|
|
|
main() {
|
|
|
|
|
# Change to application directory
|
|
|
|
|
cd /app
|
|
|
|
|
|
|
|
|
|
# Wait for dependencies
|
|
|
|
|
wait_for_db
|
|
|
|
|
wait_for_redis
|
|
|
|
|
|
|
|
|
|
# Run database migrations
|
|
|
|
|
log "Running database migrations..."
|
|
|
|
|
export FLASK_APP=pyfedi.py
|
|
|
|
|
|
|
|
|
|
# Run Flask database migrations
|
|
|
|
|
flask db upgrade
|
|
|
|
|
log "Database migrations completed"
|
|
|
|
|
|
|
|
|
|
# Populate community search index
|
|
|
|
|
log "Populating community search..."
|
|
|
|
|
flask populate_community_search
|
|
|
|
|
log "Community search populated"
|
|
|
|
|
|
|
|
|
|
# Ensure log files have correct ownership for dual logging (file + stdout)
|
|
|
|
|
if [ -f /app/logs/pyfedi.log ]; then
|
|
|
|
|
chown piefed:piefed /app/logs/pyfedi.log
|
|
|
|
|
chmod 664 /app/logs/pyfedi.log
|
|
|
|
|
log "Fixed log file ownership for piefed user"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
log "Database initialization completed successfully!"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Run the main function
|
|
|
|
|
main
|
|
|
|
|
|