Skip to content

Commit

Permalink
Fixed #43 - docker configuration for deployment (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbedroid authored Jul 16, 2022
1 parent bc45569 commit d61c13c
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 21 deletions.
2 changes: 1 addition & 1 deletion django/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ FROM python:3.9.3-slim-buster
#RUN addgroup --system app && adduser --system --group app

# Create Directory
ENV APP_HOME=/srv/webapp
ENV APP_HOME=/srv/app

RUN mkdir -p $APP_HOME
RUN mkdir -p $APP_HOME/static
Expand Down
2 changes: 1 addition & 1 deletion django/Dockerfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ FROM python:3.9.3-slim-buster
RUN addgroup --system app && adduser --system --group app

# Create Directory
ENV APP_HOME=/srv/webapp
ENV APP_HOME=/srv/app

RUN mkdir -p $APP_HOME
RUN mkdir -p $APP_HOME/static
Expand Down
6 changes: 1 addition & 5 deletions django/Dockerfile.stage
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ FROM python:3.9.3-slim-buster
# RUN addgroup --system app && adduser --system --group app

# Create Directory
# Heroku
ENV APP_HOME=/app

# Digital Ocean
# ENV APP_HOME=/srv/webapp
ENV APP_HOME=/srv/app

RUN mkdir -p $APP_HOME
RUN mkdir -p $APP_HOME/static
Expand Down
21 changes: 16 additions & 5 deletions django/entrypoint.do.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

#Production EntryPoint
# Production EntryPoint

if [ "$DATABASE" = "postgres" ]
then
Expand All @@ -20,16 +20,27 @@ fi;
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser --noinput

if [ "$run_fixtures" = true ];
then
echo "\n Running Django Fixture \n"
cat << EOF
|-------------------------------------|
| Running Django Fixtures.... |
|-------------------------------------|
EOF
python manage.py loaddata categories
python manage.py loaddata galleries
python manage.py loaddata photos
python manage.py collectstatic --noinput
else
cat << EOF
|-------------------------------------|
| Ignoring Django Fixtures... |
|-------------------------------------|
# Disable run fixture command
export run_fixtures=false
#heroku config:add run_fixtures=false
EOF
fi;
exec "$@"
27 changes: 22 additions & 5 deletions django/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

#Entrypoint for Local Development
# Local Development Environment

if [ "$DATABASE" = "postgres" ]
then
Expand All @@ -20,9 +20,26 @@ fi;
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser --noinput
python manage.py loaddata categories
python manage.py loaddata galleries
python manage.py loaddata photos
python manage.py collectstatic --noinput
if [ "$run_fixtures" = true ];
then
cat << EOF
|-------------------------------------|
| Running Django Fixtures.... |
|-------------------------------------|
EOF
python manage.py loaddata categories
python manage.py loaddata galleries
python manage.py loaddata photos
python manage.py collectstatic --noinput
else
cat << EOF
|-------------------------------------|
| Ignoring Django Fixtures... |
|-------------------------------------|
EOF
fi;
exec "$@"
2 changes: 2 additions & 0 deletions docker-compose.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: "3.3"

services:
django:
restart: always
image: "${DJANGO_IMAGE}"
container_name: django
command: gunicorn photoshare.wsgi:application --worker-tmp-dir /dev/shm --workers=2 --threads=4 --worker-class=gthread --log-file=- --bind 0.0.0.0:8000
Expand All @@ -18,6 +19,7 @@ services:
- redis

db:
restart: always
image: postgres:9.6.22-buster
container_name: db
ports:
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: "3.3"

services:
django:
restart: always
image: "${DJANGO_IMAGE}"
container_name: django
command: gunicorn photoshare.wsgi:application --worker-tmp-dir /dev/shm --workers=2 --threads=4 --worker-class=gthread --log-file=- --bind 0.0.0.0:8000
Expand All @@ -17,7 +18,8 @@ services:
- db
- redis
db:
image: postgres:12.0-alpine
restart: always
image: postgres:9.6.22-buster
container_name: db
restart: always
ports:
Expand Down
7 changes: 4 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@
version: "3.3"
services:
django:
restart: always
build:
context: ./django
dockerfile: Dockerfile
container_name: dev-django
command: python manage.py runserver 0.0.0.0:8000
command: gunicorn photoshare.wsgi:application --worker-tmp-dir /dev/shm --workers=2 --threads=4 --worker-class=gthread --log-file=- --bind 0.0.0.0:8000
environment:
- REDIS_URL=redis://redis:6379/
ports:
- 8001:8000
env_file:
- ./.env.dev
volumes:
- ./django/:/srv/app
- static:/srv/app/static
- media:/srv/app/media
depends_on:
- db
- redis

db:
image: postgres:12.0-alpine
restart: always
image: postgres:9.6.22-buster
container_name: dev-db
restart: always
ports:
Expand Down

0 comments on commit d61c13c

Please sign in to comment.