Skip to content

Commit cccf129

Browse files
authored
Merge pull request #162 from ternera/master
Implemented Docker for Local Deployments
2 parents b53e848 + ea6cefc commit cccf129

File tree

7 files changed

+218
-1
lines changed

7 files changed

+218
-1
lines changed

.dockerignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
__pycache__
2+
*.pyc
3+
*.pyo
4+
*.pyd
5+
.Python
6+
*.so
7+
*.egg
8+
*.egg-info
9+
dist
10+
build
11+
.git
12+
.gitignore
13+
.vscode
14+
.idea
15+
*.swp
16+
*.swo
17+
*~
18+
.DS_Store
19+
db.sqlite3
20+
*.sqlite3
21+
.env
22+
venv
23+
env
24+
ENV
25+
.venv
26+
staticfiles
27+
media
28+
*.log
29+
.coverage
30+
htmlcov
31+
.pytest_cache
32+
.mypy_cache
33+
node_modules
34+
postgres_data

Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM python:3.11-slim
2+
3+
ENV PYTHONUNBUFFERED=1
4+
5+
WORKDIR /app
6+
7+
RUN apt-get update && apt-get install -y \
8+
postgresql-client \
9+
libpq-dev \
10+
gcc \
11+
libxml2-dev \
12+
libxslt1-dev \
13+
zlib1g-dev \
14+
git \
15+
netcat-openbsd \
16+
&& rm -rf /var/lib/apt/lists/*
17+
18+
COPY requirements.txt .
19+
RUN pip install --no-cache-dir -r requirements.txt
20+
RUN pip install --no-cache-dir psycopg2-binary
21+
22+
COPY . .
23+
24+
RUN mkdir -p /app/static
25+
26+
EXPOSE 8000
27+
28+
COPY docker-entrypoint.sh /docker-entrypoint.sh
29+
RUN chmod +x /docker-entrypoint.sh
30+
31+
ENTRYPOINT ["/docker-entrypoint.sh"]
32+
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

celerybeat-schedule

16 KB
Binary file not shown.

docker-compose.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
version: '3.8'
2+
3+
services:
4+
db:
5+
image: postgres:15
6+
environment:
7+
POSTGRES_DB: editgroups
8+
POSTGRES_USER: postgres
9+
POSTGRES_PASSWORD: postgres
10+
volumes:
11+
- postgres_data:/var/lib/postgresql/data
12+
ports:
13+
- "5432:5432"
14+
healthcheck:
15+
test: ["CMD-SHELL", "pg_isready -U postgres"]
16+
interval: 5s
17+
timeout: 5s
18+
retries: 5
19+
20+
redis:
21+
image: redis:7-alpine
22+
ports:
23+
- "6379:6379"
24+
healthcheck:
25+
test: ["CMD", "redis-cli", "ping"]
26+
interval: 5s
27+
timeout: 3s
28+
retries: 5
29+
30+
web:
31+
build: .
32+
command: python manage.py runserver 0.0.0.0:8000
33+
volumes:
34+
- .:/app
35+
ports:
36+
- "8000:8000"
37+
environment:
38+
- DJANGO_SETTINGS_MODULE=editgroups.settings.docker
39+
- RUN_MIGRATIONS=true
40+
depends_on:
41+
db:
42+
condition: service_healthy
43+
redis:
44+
condition: service_healthy
45+
46+
celery:
47+
build: .
48+
command: celery -A editgroups worker -l info
49+
volumes:
50+
- .:/app
51+
environment:
52+
- DJANGO_SETTINGS_MODULE=editgroups.settings.docker
53+
- C_FORCE_ROOT=true
54+
depends_on:
55+
- db
56+
- redis
57+
- web
58+
59+
celery-beat:
60+
build: .
61+
command: celery -A editgroups beat -l info
62+
volumes:
63+
- .:/app
64+
environment:
65+
- DJANGO_SETTINGS_MODULE=editgroups.settings.docker
66+
depends_on:
67+
- db
68+
- redis
69+
- web
70+
71+
volumes:
72+
postgres_data:

docker-entrypoint.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
echo "Waiting for PostgreSQL"
6+
while ! nc -z db 5432; do
7+
sleep 0.1
8+
done
9+
echo "PostgreSQL started"
10+
11+
if [ "$RUN_MIGRATIONS" = "true" ]; then
12+
echo "Running migrations"
13+
python manage.py migrate --noinput
14+
15+
echo "Collecting static files"
16+
python manage.py collectstatic --noinput
17+
18+
echo "Creating superuser if it doesn't exist"
19+
python manage.py shell -c "
20+
from django.contrib.auth import get_user_model
21+
User = get_user_model()
22+
if not User.objects.filter(username='admin').exists():
23+
User.objects.create_superuser('admin', '[email protected]', 'admin')
24+
print('Superuser created: admin/admin')
25+
else:
26+
print('Superuser already exists')
27+
" || true
28+
fi
29+
30+
exec "$@"

editgroups/settings/docker.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os
2+
import sys
3+
from types import ModuleType
4+
5+
secret = ModuleType('editgroups.settings.secret')
6+
secret.SECRET_KEY = '20oj&tj8uaruseitlrise,tries,uirsetur36746209etus7e'
7+
secret.DATABASES = {
8+
'default': {
9+
'ENGINE': 'django.db.backends.postgresql_psycopg2',
10+
'NAME': 'editgroups',
11+
'USER': 'postgres',
12+
'PASSWORD': 'postgres',
13+
'HOST': 'db',
14+
'PORT': '5432',
15+
'DISABLE_SERVER_SIDE_CURSORS': False,
16+
}
17+
}
18+
secret.SOCIAL_AUTH_MEDIAWIKI_KEY = 'your_mediawiki_key'
19+
secret.SOCIAL_AUTH_MEDIAWIKI_SECRET = 'your_mediawiki_secret'
20+
secret.SOCIAL_AUTH_MEDIAWIKI_URL = 'https://www.wikidata.org/w/index.php'
21+
secret.SOCIAL_AUTH_MEDIAWIKI_CALLBACK = 'http://localhost:8000/oauth/complete/mediawiki/'
22+
secret.REDIS_HOST = 'redis'
23+
secret.REDIS_PORT = 6379
24+
secret.REDIS_DB = 0
25+
secret.REDIS_PASSWORD = ''
26+
secret.REDIS_KEY_PREFIX = 'editgroups_'
27+
28+
sys.modules['editgroups.settings.secret'] = secret
29+
30+
from .common import *
31+
32+
DEBUG = True
33+
ALLOWED_HOSTS = ['*']
34+
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

editgroups/wsgi.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
../app.py
1+
"""
2+
WSGI config for editgroups project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "editgroups.settings")
15+
16+
application = app = get_wsgi_application()

0 commit comments

Comments
 (0)