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

Add docker deployment #1064

Merged
merged 14 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 13 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
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# not docker execution related files
.github
.pytest_cache
data
docs
tests
dist
build
.env
.idea
.env.example

11 changes: 2 additions & 9 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
SECRET_KEY=b0jbk58)l&^hy5cht+j$n9!laoke5ivdc+3&@qf2yrt1udvb85
DEBUG=True
DEBUG_TOOLBAR=False
DATABASE_URL=sqlite:///data/db.sqlite3
ALLOWED_HOSTS="*"
STATIC_URL=/static/
STATIC_ROOT=data/static/
LOGGING_FILE=data/logs/ephios.log
INTERNAL_IPS="127.0.0.1"
SITE_URL=http://localhost:8000
EMAIL_URL=dummymail://
EMAIL_URL=consolemail://
DEFAULT_FROM_EMAIL=webmaster@localhost
SERVER_EMAIL=root@localhost
ADMINS=Root User <[email protected]>
# VAPID_PRIVATE_KEY_PATH=data/private_key.pem # push notifications, create in `data/` with `vapid --gen`
ADMINS="Root User <[email protected]>"
40 changes: 40 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

name: docker
on:
workflow_dispatch:
push:
branches:
- 'main'
tags:
- 'v*'
felixrindt marked this conversation as resolved.
Show resolved Hide resolved

jobs:
docker:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/ephios-dev/ephios

- name: Login to Github Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true #${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Publish to pypi
name: Publish to PyPI
on:
push:
tags:
- 'v*.*.*'
jobs:
build:
pypi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
42 changes: 42 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# syntax=docker/dockerfile:1
FROM python:3.11-bookworm

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV POETRY_VIRTUALENVS_CREATE=false
ENV POETRY_VERSION=1.6.1

WORKDIR /usr/src/ephios

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

RUN dpkg-reconfigure locales && \
locale-gen C.UTF-8 && \
/usr/sbin/update-locale LANG=C.UTF-8

RUN pip install "poetry==$POETRY_VERSION" gunicorn
RUN poetry self add "poetry-dynamic-versioning[plugin]"

RUN mkdir -p /var/ephios/data/ && \
mkdir -p /var/log/supervisord/ && \
mkdir -p /var/run/supervisord/

COPY . /usr/src/ephios
RUN poetry install --all-extras --without=dev

COPY deployment/docker/entrypoint.sh /usr/local/bin/ephios
RUN chmod +x /usr/local/bin/ephios

COPY deployment/docker/supervisord.conf /etc/supervisord.conf
COPY deployment/docker/cron.sh /usr/local/bin/cron.sh
RUN chmod +x /usr/local/bin/cron.sh

ENTRYPOINT ["ephios"]
CMD ["run"]
HEALTHCHECK CMD curl -f http://localhost:80/healthcheck || exit 1
49 changes: 49 additions & 0 deletions deployment/compose/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
services:
ephios:
build: ../../
felixrindt marked this conversation as resolved.
Show resolved Hide resolved
restart: unless-stopped
environment:
DEBUG: "False"
TRUST_X_FORWARDED_PROTO: "True"
DATA_DIR: "/var/ephios/data/"
DATABASE_URL: "postgres://ephios:ephios@ephios_postgres/ephios"
CACHE_URL: "redis://ephios_redis/0"
ALLOWED_HOSTS: "*"
# change the following to your needs
EMAIL_URL: "consolemail://"
SITE_URL: "http://localhost"
DEFAULT_FROM_EMAIL: "webmaster@localhost"
SERVER_EMAIL: "root@localhost"
ADMINS: "Root User <[email protected]>"
volumes:
- ephios_django_data:/var/ephios/data/

ephios_redis:
image: redis:7-alpine
command: redis-server
restart: unless-stopped

ephios_postgres:
image: postgres:12
restart: unless-stopped
environment:
POSTGRES_DB: ephios
POSTGRES_USER: ephios
POSTGRES_PASSWORD: ephios
volumes:
- ephios_postgres_data:/var/lib/postgresql/data

ephios_nginx:
image: nginx:1.19
restart: unless-stopped
ports:
- 80:80
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- ephios_django_data:/var/ephios/data/
depends_on:
- ephios

volumes:
ephios_django_data: { }
ephios_postgres_data: { }
19 changes: 19 additions & 0 deletions deployment/compose/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
server {
listen 80 default_server;
listen [::]:80 ipv6only=on default_server;

location / {
proxy_pass http://ephios:80;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $http_host;
proxy_redirect off;
}

location /static/ {
alias /var/ephios/data/public/static/;
access_log off;
expires 1d;
add_header Cache-Control "public";
}
}
7 changes: 7 additions & 0 deletions deployment/docker/cron.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

while [ true ]; do
echo "Running cron job"
/usr/local/bin/python3 -m ephios run_periodic
sleep 60
done
13 changes: 13 additions & 0 deletions deployment/docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -e

if [ "$1" == "run" ]; then
python manage.py migrate
python manage.py collectstatic --no-input
python manage.py compilemessages
python manage.py compilejsi18n
exec supervisord -n -c /etc/supervisord.conf
fi

exec python manage.py "$@"
23 changes: 23 additions & 0 deletions deployment/docker/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[supervisord]
nodaemon=true
user=root
logfile=/var/log/supervisord/supervisord.log
pidfile=/var/run/supervisord/supervisord.pid
childlogdir=/var/log/supervisord/
logfile_maxbytes=50MB
logfile_backups=10
loglevel=error

[program:gunicorn]
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
command=gunicorn ephios.wsgi --bind 0.0.0.0:80 --name ephios --workers 5 --max-requests 1000 --max-requests-jitter 100

[program:cronscript]
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
command=/usr/local/bin/cron.sh
Loading