-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathstartup.sh
executable file
·36 lines (28 loc) · 1.21 KB
/
startup.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
# This script should be executed just after all the contains are built and the started for first time
# Two ways to execute the script:
# ./startup.sh docker-compose.yml --collect-static
# ./startup.sh docker-compose.yml
if [ -z "$1" ];
then echo "No File Param Passed";
exit 1
fi
# Making migrations files
docker-compose -f $1 exec -T backend python manage.py makemigrations
# Migrating changes into the database
docker-compose -f $1 exec -T backend python manage.py migrate
if [ "$2" = "--collect-static" ];
then
echo "Performing Collect Static"
# Calling collectstatic to dump all the static files
docker-compose -f $1 exec -T backend python manage.py collectstatic --no-input
else
echo "Skipping collect static"
fi
# Creating a superuser using the environment variables
docker-compose -f $1 exec -T backend python manage.py shell -c "from django.contrib.auth import get_user_model; \
import os; \
User = get_user_model(); \
username=os.environ.get('DJANGO_SUPERUSER_USERNAME'); \
password=os.environ.get('DJANGO_SUPERUSER_PASSWORD'); \
email=os.environ.get('DJANGO_SUPERUSER_EMAIL'); \
User.objects.filter(username=username).exists() or User.objects.create_superuser(username, email, password)"