-
Notifications
You must be signed in to change notification settings - Fork 52
/
docker-entrypoint.sh
executable file
·78 lines (63 loc) · 2.74 KB
/
docker-entrypoint.sh
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
#!/bin/bash
export APP_HOST=${APP_HOST:-0.0.0.0}
export APP_PORT=${APP_PORT:-8303}
export POSTGRES_HOST=${POSTGRES_HOST:-db}
export POSTGRES_PORT=${POSTGRES_PORT:-5432}
export RABBITMQ_HOST=${RABBITMQ_HOST:-rabbitmq}
export RABBITMQ_PORT=${RABBITMQ_PORT:-5672}
# export MEMCACHED_HOST=${MEMCACHED_HOST:-memcached}
# export MEMCACHED_PORT=${MEMCACHED_PORT:-11211}
export SUPER_USERNAME=${SUPER_USERNAME:-admin}
export SUPER_PASSWORD=${SUPER_PASSWORD:-Bonjour1!}
export SUPER_EMAIL=${SUPER_EMAIL:-admin@hears.patrowl.io}
export SUPER_ORGNAME=${SUPER_ORGNAME:-Private}
echo "[+] Wait for DB availability"
while !</dev/tcp/$POSTGRES_HOST/$POSTGRES_PORT; do sleep 1; done
echo "[+] Wait for RabbitMQ availability"
while !</dev/tcp/$RABBITMQ_HOST/$RABBITMQ_PORT; do sleep 1; done
# echo "[+] Wait for Memcached availability"
# while !</dev/tcp/$MEMCACHED_HOST/$MEMCACHED_PORT; do sleep 1; done
echo "[+] VERSION"
cat VERSION
echo "[+] Activate python virtualenv"
cd backend_app
source env/bin/activate
# Collect static files
echo "[+] Collect static files"
python manage.py collectstatic --noinput
# Apply database migrations
echo "[+] Make database migrations for User"
python manage.py makemigrations users
# Apply database migrations
echo "[+] Apply database migrations for User"
python manage.py migrate users
# Apply database migrations
echo "[+] Make database migrations"
python manage.py makemigrations
# Apply database migrations
echo "[+] Apply database migrations"
python manage.py migrate
# Create default admin user
echo "[+] Create default admin user if needed"
echo -e "from django.contrib.auth import get_user_model\r\
User = get_user_model()\r\
if not User.objects.filter(username='admin').exists():\r\
User.objects.create_superuser('$SUPER_USERNAME', '$SUPER_EMAIL', '$SUPER_PASSWORD')" | python manage.py shell
echo "[+] Create default admin private organization if needed"
echo -e "\r\
from organizations.models import Organization, OrganizationUser, OrganizationOwner\r\
from django.contrib.auth import get_user_model\r\
admin_user = get_user_model().objects.get(username='$SUPER_USERNAME')\r\
if admin_user.organizations_organization.count() == 0:\r\
admin_org = Organization.objects.create(name='$SUPER_ORGNAME', is_active=True)\r\
admin_org.save()\r\
org_user = OrganizationUser.objects.create(user=admin_user, organization=admin_org, is_admin=True)\r\
org_user.save()\r\
org_owner = OrganizationOwner.objects.create(organization=admin_org, organization_user=org_user)\r\
org_owner.save()" | python manage.py shell
# Start Supervisord (Celery workers)
echo "[+] Start Supervisord (Celery workers)"
supervisord -c var/etc/supervisord.conf
# Start server
echo "[+] Starting server"
gunicorn -b $APP_HOST:$APP_PORT backend_app.wsgi:application --timeout 300