Skip to content

Commit

Permalink
Use Nginx & gunicorn to run Kipa in container
Browse files Browse the repository at this point in the history
  • Loading branch information
ilesoft committed Dec 5, 2024
1 parent 9a55b4c commit 8a22d16
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 29 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web/settings/local.py
29 changes: 21 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
FROM python:3.12
FROM ubuntu/nginx

WORKDIR /app/web
RUN apt-get update
RUN apt-get install -y python3.12 python3.12-venv

ENTRYPOINT ["/app/docker-entrypoint.sh"]
EXPOSE 3000
CMD ["python", "./manage.py", "runserver", "0.0.0.0:3000"]

COPY . /app/
COPY web/settings/docker.py.example /app/web/settings/docker.py
RUN pip install -r /app/requirements.txt
COPY web /app/
COPY --chown=nobody:nogroup web/media /media
COPY web/settings/docker.py.example /app/settings/docker.py
COPY requirements.txt /
COPY nginx.conf /etc/nginx/

RUN tr -dc A-Za-z0-9 < /dev/urandom | head -c 40 > /secret.txt
RUN python3.12 -m venv venv
ENV PATH="/venv/bin:$PATH"
RUN pip install -r requirements.txt
WORKDIR /app
RUN python manage.py makemigrations tupa
RUN python manage.py migrate

RUN nginx -t

RUN echo "gunicorn --daemon --bind unix:/tmp/kipa.sock wsgi" > /docker-entrypoint.d/gunicorn.sh
RUN chmod +x /docker-entrypoint.d/gunicorn.sh
6 changes: 0 additions & 6 deletions docker-compose.yml

This file was deleted.

10 changes: 0 additions & 10 deletions docker-entrypoint.sh

This file was deleted.

42 changes: 42 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
worker_processes 1;

user nobody nogroup;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
accept_mutex off; # set to 'on' if nginx worker_processes > 1
}

http {
include mime.types;
# fallback in case we can't determine a type
default_type application/octet-stream;
access_log /var/log/nginx/access.log combined;
sendfile on;

upstream app_server {
server unix:/tmp/kipa.sock fail_timeout=0;
}

server {
listen 80 deferred;
client_max_body_size 4G;
server_name kipa;
keepalive_timeout 5;

location /kipamedia {
alias /media;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
# we don't want nginx trying to do something clever with
# redirects, we set the Host: header above already.
proxy_redirect off;
proxy_pass http://app_server;
}
}
}
7 changes: 2 additions & 5 deletions web/settings/docker.py.example
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
with open("/app/db/secret.txt", "r") as f:
with open("/secret.txt", "r") as f:
SECRET_KEY = f.readline()

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "/app/db/kipa.db",
"NAME": "/tmp/kipa.db",
}
}

# Should we serve the media files through Python?
SERVE_MEDIA = True

0 comments on commit 8a22d16

Please sign in to comment.