Skip to content
Merged
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
34 changes: 34 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
__pycache__
*.pyc
*.pyo
*.pyd
.Python
*.so
*.egg
*.egg-info
dist
build
.git
.gitignore
.vscode
.idea
*.swp
*.swo
*~
.DS_Store
db.sqlite3
*.sqlite3
.env
venv
env
ENV
.venv
staticfiles
media
*.log
.coverage
htmlcov
.pytest_cache
.mypy_cache
node_modules
postgres_data
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ editgroups/settings/secret.py
editgroups/settings/__init__.py
static/
celerybeat-schedule.db
celerybeat-schedule
docs/_build/

.project
Expand Down
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM docker-registry.tools.wmflabs.org/toolforge-python311-sssd-web:latest

WORKDIR /root/www/python/

RUN apt-get update && apt-get install -y \
gcc \
libxml2-dev \
libxslt1-dev \
zlib1g-dev \
git \
netcat-openbsd \
curl \
&& rm -rf /var/lib/apt/lists/*

# Necessary flags for mysqlclient driver
ENV MYSQLCLIENT_CFLAGS="-I/usr/include/mariadb/"
ENV MYSQLCLIENT_LDFLAGS="-L/usr/lib/x86_64-linux-gnu/ -lmariadb"
ENV VIRTUAL_ENV /root/www/python/venv
ENV PATH="/root/www/python/venv/bin:${PATH}"
ENV DJANGO_SETTINGS_MODULE=editgroups.settings
ENV PYTHONPATH="/root/www/python/src:${PYTHONPATH}"
COPY requirements.txt ./src/requirements.txt
RUN echo "mysqlclient==2.2.7" >> /root/www/python/src/requirements.txt
RUN webservice-python-bootstrap

COPY . ./src
WORKDIR /root/www/python/src/

RUN echo "from .dev import *" > /root/www/python/src/editgroups/settings/__init__.py
COPY editgroups/settings/docker.py /root/www/python/src/editgroups/settings/secret.py
RUN echo "source /root/www/python/venv/bin/activate" >> /root/.bashrc # useful when entering the shell

# Just to make sure virtual environment is working properly
RUN ["/bin/bash", "-c", "source ../venv/bin/activate && python3 manage.py collectstatic --no-input"]

EXPOSE 8000
77 changes: 77 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
services:
mariadb:
image: mariadb:11.7.2
environment:
MARIADB_DATABASE: ${DB_NAME:-editgroups}
MARIADB_ROOT_PASSWORD: ${DB_PASSWORD:-editgroups}
volumes:
- mariadb:/var/lib/mysql
healthcheck:
test: healthcheck.sh --connect --innodb_initialized
start_period: 10s
interval: 10s
timeout: 5s
retries: 3
expose:
- 3306

redis:
image: redis:7.4
expose:
- 6379
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 5

app:
ports:
- 8000:8000
healthcheck:
test: curl --fail http://localhost:8000/ || exit 1
start_period: 10s
interval: 10s
command: >
/bin/bash -c "
django-admin collectstatic --no-input &&
django-admin migrate &&
django-admin runserver 0.0.0.0:8000
"
<<: &app
build:
context: .
dockerfile: Dockerfile
depends_on:
mariadb:
condition: service_healthy
redis:
condition: service_healthy
environment:
- SECRET_KEY=${DJANGO_SECRET_KEY:-}
- DB_NAME=${DB_NAME:-editgroups}
- DB_PASSWORD=${DB_NAME:-editgroups}

celery:
<<: *app
command: >
/bin/bash -c "
source ../venv/bin/activate
C_FORCE_ROOT=1 python3 ../venv/bin/celery --app=editgroups.celery:app worker -l INFO -B --concurrency=3 --max-memory-per-child=50000
"
depends_on:
app:
condition: service_healthy
listener:
<<: *app
command: >
/bin/bash -c "
source ../venv/bin/activate
django-admin listener
"
depends_on:
app:
condition: service_healthy

volumes:
mariadb:
26 changes: 26 additions & 0 deletions editgroups/settings/docker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os

SECRET_KEY = 'django-insecure-0ldt)=t=w(%l)7b28n=x!#9ciei^yuox3204(#(r!-fh^59+a-'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': 'mariadb',
'NAME': os.getenv("DB_NAME"),
'PASSWORD': os.getenv("DB_PASSWORD"),
'OPTIONS': {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
'charset': 'utf8mb4',
},
}
}

SOCIAL_AUTH_MEDIAWIKI_KEY = 'your_mediawiki_key'
SOCIAL_AUTH_MEDIAWIKI_SECRET = 'your_mediawiki_secret'
SOCIAL_AUTH_MEDIAWIKI_URL = 'https://www.wikidata.org/w/index.php'
SOCIAL_AUTH_MEDIAWIKI_CALLBACK = 'http://localhost:8000/oauth/complete/mediawiki/'

REDIS_HOST = 'redis'
REDIS_PORT = 6379
REDIS_DB = 0
REDIS_PASSWORD = ''
REDIS_KEY_PREFIX = 'editgroups_'
1 change: 0 additions & 1 deletion editgroups/wsgi.py

This file was deleted.

8 changes: 8 additions & 0 deletions editgroups/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "editgroups.settings")

application = get_wsgi_application()