-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
87 lines (74 loc) · 3.12 KB
/
Copy pathdocker-entrypoint.sh
File metadata and controls
87 lines (74 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
set -e
# Generate a secure SECRET_KEY if not set
if [ -z "$SECRET_KEY" ] || [ "$SECRET_KEY" = "your-secret-key-here-change-in-production" ] || [ "$SECRET_KEY" = "django-insecure-)32-g7%2_@jy@ycdh1lh2*)2pg8y$ftwd88j*vuc%ev%%t(@-f" ]; then
echo "Generating secure SECRET_KEY..."
export SECRET_KEY=$(python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())')
echo "✓ SECRET_KEY generated"
echo ""
echo "IMPORTANT: For production deployments, save this SECRET_KEY to your environment:"
echo "SECRET_KEY=$SECRET_KEY"
echo ""
fi
# Check if we're using PostgreSQL and wait for it to be ready
DATABASE_TYPE="${DATABASE_TYPE:-sqlite}"
if [ "$DATABASE_TYPE" = "postgres" ] || [ "$DATABASE_TYPE" = "postgresql" ]; then
echo "Waiting for PostgreSQL to be ready..."
# Extract host and port from DATABASE_URL if set
if [ -n "$DATABASE_URL" ]; then
DB_HOST=$(echo "$DATABASE_URL" | sed -n 's/.*@\(.*\):.*/\1/p')
DB_PORT=$(echo "$DATABASE_URL" | sed -n 's/.*:\([0-9]*\)\/.*/\1/p')
DB_USER=$(echo "$DATABASE_URL" | sed -n 's/.*:\/\/\(.*\):.*/\1/p')
else
DB_HOST="${DATABASE_HOST:-db}"
DB_PORT="${DATABASE_PORT:-5432}"
DB_USER="${DATABASE_USER:-blik}"
fi
# Check if pg_isready is available
if command -v pg_isready > /dev/null 2>&1; then
until pg_isready -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER"; do
echo "PostgreSQL is unavailable - sleeping"
sleep 1
done
echo "PostgreSQL is up and running"
else
echo "Warning: pg_isready not found. Proceeding without PostgreSQL health check."
fi
else
echo "Using SQLite database - no connection wait needed"
fi
echo "Running database migrations..."
python manage.py migrate --noinput
echo "Running upgrade steps..."
python manage.py upgrade
echo "Collecting static files..."
python manage.py collectstatic --noinput --clear
echo "Setting up organization..."
python manage.py setup_organization
echo "Setting up superuser..."
python manage.py setup_superuser
echo ""
echo "========================================="
echo "Blik is ready!"
echo "========================================="
if [ -n "$DJANGO_SUPERUSER_USERNAME" ]; then
echo "Admin username: $DJANGO_SUPERUSER_USERNAME"
if [ -z "$DJANGO_SUPERUSER_PASSWORD" ]; then
echo "WARNING: No superuser password set!"
echo "Please create a superuser manually:"
echo " docker-compose exec web python manage.py createsuperuser"
fi
else
echo "No auto-setup configured."
echo "Create a superuser with:"
echo " docker-compose exec web python manage.py createsuperuser"
fi
echo "========================================="
echo ""
# Set up cron for daily tasks (send_cycle_reminders)
# Pass environment variables to cron by dumping them to a file
env | grep -E '^(DATABASE_|SECRET_KEY|SITE_|ALLOWED_HOSTS|DEBUG|EMAIL_|ENCRYPTION_KEY|DJANGO_|PYTHONUNBUFFERED|PATH)' > /app/.env.cron 2>/dev/null || true
echo "0 9 * * * cd /app && export \$(cat /app/.env.cron | xargs) && python manage.py send_cycle_reminders >> /var/log/cron.log 2>&1" | crontab -
service cron start
echo "Cron started (send_cycle_reminders daily at 09:00 UTC)"
exec "$@"