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

Merged
merged 4 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions Dockerfile-prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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 supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY supervisor.service /etc/systemd/system/supervisor.service

COPY edrop-gunicorn.sh /edrop/edrop-gunicorn.sh

RUN ["chmod", "+x", "/edrop/edrop-gunicorn.sh"]
Copy link
Member

Choose a reason for hiding this comment

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

we want supervisor to manage gunicorn, so this should not be necessary. instead just make sure supervisor is running.


ENTRYPOINT ["./edrop-gunicorn.sh"]
Copy link
Member

Choose a reason for hiding this comment

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

neither should this

6 changes: 4 additions & 2 deletions 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:14
Copy link
Member

Choose a reason for hiding this comment

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

while we should have a postgres version here, let's use the latest (16 I believe)

platform: linux/amd64
volumes:
- ./data/db:/var/lib/postgresql/data
Expand All @@ -13,7 +13,9 @@ services:
ports:
- "5432:5432"
web:
build: .
build:
context: .
dockerfile: Dockerfile-prod
platform: linux/amd64
command: tail -f /dev/null
volumes:
Expand Down
29 changes: 29 additions & 0 deletions edrop-gunicorn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/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
service supervisor start
Copy link
Member

Choose a reason for hiding this comment

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

this should not be needed here (and would actually lead to an infinite loop of starting supervisor (or error out maybe), since this is the script that supervisor runs to start gunicorn.


# 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=-
Copy link
Member

Choose a reason for hiding this comment

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

needs to log to files not stdout

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