Skip to content

Instantly share code, notes, and snippets.

@katoozi
Last active June 26, 2020 12:34
Show Gist options
  • Save katoozi/63f23801bf862721d13cd4ba2fd07f75 to your computer and use it in GitHub Desktop.
Save katoozi/63f23801bf862721d13cd4ba2fd07f75 to your computer and use it in GitHub Desktop.
start django application inside a docker image
#!/bin/sh
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
start_django(){
echo -e "${GREEN}-----------Start Collecting Static Files.--------------${NC}"
python manage.py collectstatic --no-input
echo -e "\n${GREEN}-----------Done Collecting Static Files.---------------${NC}\n"
echo -e "${GREEN}-----------Start Applying Django Migrations.-----------${NC}"
python manage.py migrate
echo -e "${GREEN}-----------Done Applying Django Migrations.------------${NC}\n"
echo -e "\n${GREEN}-----------Start Compile Messages.------------${NC}"
if [ "$COMPILE_MESSAGES" = "True" ]; then
echo "$COMPILE_MESSAGES_LANGUAGES" | awk '{
n = split($0, t, ",")
for (i = 0; ++i <= n;)
print t[i]
}' | while read language; do
python manage.py compilemessages -l $language
done
fi
echo -e "${GREEN}-----------Done Compile Messages.-------------${NC}\n"
echo -e "${GREEN}-----------Starting Django Server.------------${NC}\n"
if [ "$DEBUG_MODE" = "True" ]; then
echo -e "${RED}Start Django Server In Debug Mode. Are You Sure!!!!.${NC}\n"
python manage.py runserver 0.0.0.0:${BIND_PORT:-8000}
else
gunicorn project.wsgi -b 0.0.0.0:${BIND_PORT:-8000} --workers ${GUNICORN_NUM_WORKERS:-2} --log-level=${GUNICORN_LOG_LEVEL:-info} --log-file=-
fi
echo -e "${GREEN}-----------Stoping Django Server.------------${NC}\n"
}
start_django
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment