Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[story/EDROP-14] #15

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Dockerfile-prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.13
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

WORKDIR /edrop

RUN apt-get update && apt-get install -y supervisor && \
apt-get clean && rm -rf /var/lib/apt/lists/*

COPY edrop-gunicorn.sh /edrop/edrop-gunicorn.sh
COPY supervisor.service /etc/systemd/system/supervisor.service
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

CMD ["supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ To run this Django app, the easiest is to run it via Docker.

- Make sure Docker is installed.
- Make sure there is a folder `data/db` in this folder (if it's the first time you run this project, you will need to create `db` inside `data`).
- Then from this directory, run `docker compose up`
- To run the dev server from this directory, run `docker compose up`
- To run the production server from this directory, run `docker compose -f docker-compose-prod.yml up`
- The app will be available at http://localhost:8000/.

## Developing the App
Expand Down
33 changes: 33 additions & 0 deletions docker-compose-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: "3.9"

services:
db:
image: postgres:16
platform: linux/amd64
volumes:
- ./data/db:/var/lib/postgresql/data
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
ports:
- "5432:5432"
web:
build:
context: .
dockerfile: Dockerfile-prod
platform: linux/amd64
volumes:
- .:/edrop
- ./data/files:/data/files
ports:
- "8000:8000"
environment:
- POSTGRES_NAME=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- DATA_PATH=/data/files/
- MEDIA_URL_PATH=/dashboard/files/
- MEDIA_ROOT_PATH=files
depends_on:
- db
2 changes: 1 addition & 1 deletion docker-compose.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's create a separate docker compose file for production and leave this the way it was

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.9"

services:
db:
image: postgres
image: postgres:16
platform: linux/amd64
volumes:
- ./data/db:/var/lib/postgresql/data
Expand Down
28 changes: 28 additions & 0 deletions edrop-gunicorn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

NAME="edrop" # Name of the application
DJANGODIR=/edrop # Django project directory
NUM_WORKERS=3 # Number of Gunicorn workers
DJANGO_SETTINGS_MODULE=edrop.settings # Django settings module
DJANGO_WSGI_MODULE=edrop.wsgi # WSGI module name

echo "Starting $NAME as `whoami`"

# Activate the virtual environment
cd $DJANGODIR
source .env_app
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
mkdir -p /edrop/logs
python -m pip install -r requirements.txt
python manage.py migrate
python manage.py collectstatic --noinput

# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
exec gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--bind=0.0.0.0:8000 \
--log-level=info \
--log-file /edrop/logs/edrop_supervisor.log
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
django==5.1
gunicorn==22.0.0
psycopg2==2.9.10
dj-static==0.0.6
14 changes: 14 additions & 0 deletions supervisor.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# /etc/systemd/system/supervisor.service

[Unit]
Description=Supervisor
After=syslog.target network.target

[Service]
ExecStart=/usr/bin/supervisord --configuration=/etc/supervisor/conf.d/supervisord.conf --logfile=/edrop/logs/edrop_supervisor.log
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload all
Restart=always

[Install]
WantedBy=multi-user.target
24 changes: 24 additions & 0 deletions supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[supervisord]
nodaemon=true

[program:edrop]
command=/edrop/edrop-gunicorn.sh
directory=/edrop
autostart=true
autorestart=true
stdout_logfile=/edrop/logs/edrop_supervisor.log
stderr_logfile=/edrop/logs/edrop_supervisor.log
environment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8

; Need to wait for currently executing tasks to finish at shutdown.
; Increase this if you have very long running tasks.
stopwaitsecs = 600

; When resorting to send SIGKILL to the program to terminate it
; send SIGKILL to its whole process group instead,
; taking care of its children as well.
killasgroup=true

; if rabbitmq is supervised, set its priority higher
; so it starts first
priority=998