Add crude basis for docker

This commit is contained in:
Maxime Bloch 2020-07-23 14:07:31 +02:00
parent 01db89727e
commit 2cffca4023
4 changed files with 98 additions and 12 deletions

12
Dockerfile Normal file
View file

@ -0,0 +1,12 @@
FROM python:3.8-alpine
RUN mkdir code
WORKDIR code
RUN apk add --no-cache gcc musl-dev linux-headers mariadb-dev
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .

View file

@ -1,4 +1,5 @@
from __future__ import absolute_import, unicode_literals
from django.conf import settings
import os
@ -8,8 +9,8 @@ from celery import Celery
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'KeRS.settings')
app = Celery('KeRS',
broker='redis://localhost:6379/0',
backend='redis://localhost:6379/1'
broker=settings.CELERY_BROKER,
backend=settings.CELERY_BACKEND
)
# Using a string here means the worker doesn't have to serialize

View file

@ -12,6 +12,18 @@ https://docs.djangoproject.com/en/3.0/ref/settings/
import os
from django.core.exceptions import ImproperlyConfigured
def get_env_value(env_variable, default):
try:
return os.environ[env_variable]
except KeyError:
return default
# error_msg = 'Set the {} environment variable'.format(env_variable)
# raise ImproperlyConfigured(error_msg)
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@ -32,6 +44,7 @@ OWN_APPS = [
'events',
'users',
'oauth',
'core'
]
INSTALLED_APPS = [
@ -81,11 +94,11 @@ WSGI_APPLICATION = 'KeRS.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'kers',
'USER': 'kers',
'PASSWORD': 'kers',
'HOST': '127.0.0.1',
'PORT': '3306',
'NAME': get_env_value('DATABASE_NAME', 'kers'),
'USER': get_env_value('DATABASE_USER', 'kers'),
'PASSWORD': get_env_value('DATABASE_PASSWORD', 'kers'),
'HOST': get_env_value('DATABASE_HOST', '127.0.0.1'),
'PORT': get_env_value('DATABASE_PORT', '3306'),
}
}
@ -128,6 +141,10 @@ STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
# Celery
CELERY_BROKER = get_env_value('CELERY_BROKER', 'redis://localhost:6379/0')
CELERY_BACKEND = get_env_value('CELERY_BACKEND', 'redis://localhost:6379/1')
# Custom stuff
SERVER_URL = 'http://localhost:8000'
@ -137,10 +154,10 @@ AUTH_USER_MODEL = 'users.CustomUser'
_BASE_OAUTH_URL = 'https://adams.ugent.be/oauth'
OAUTH = {
'USER_API_URI': f'{_BASE_OAUTH_URL}/api/current_user/',
'USER_API_URI': f'{_BASE_OAUTH_URL}/api/current_user/',
'ACCESS_TOKEN_URI': f'{_BASE_OAUTH_URL}/oauth2/token/',
'AUTHORIZE_URI': f'{_BASE_OAUTH_URL}/oauth2/authorize/',
'REDIRECT_URI': f'{SERVER_URL}/login/zeus/authorized',
'CLIENT_ID': 'tomtest',
'CLIENT_SECRET': 'blargh',
'AUTHORIZE_URI': f'{_BASE_OAUTH_URL}/oauth2/authorize/',
'REDIRECT_URI': f'{SERVER_URL}/login/zeus/authorized',
'CLIENT_ID': 'tomtest',
'CLIENT_SECRET': 'blargh',
}

56
docker-compose.yml Normal file
View file

@ -0,0 +1,56 @@
version: '3'
services:
web:
build: .
ports:
- "8000:8000"
environment:
DATABASE_HOST: 'db'
CELERY_BROKER: 'redis://redis:6379/0'
CELERY_BACKEND: 'redis://redis:6379/1'
depends_on:
- db
command: >
sh -c "sleep 5 &&
python manage.py migrate &&
python manage.py runserver 0.0.0.0:8000"
celery-worker:
build: .
environment:
DATABASE_HOST: 'db'
CELERY_BROKER: 'redis://redis:6379/0'
CELERY_BACKEND: 'redis://redis:6379/1'
depends_on:
- web
- redis
command: >
sh -c "celery -A KeRS worker -l info"
celery-beat:
build: .
environment:
DATABASE_HOST: 'db'
CELERY_BROKER: 'redis://redis:6379/0'
CELERY_BACKEND: 'redis://redis:6379/1'
depends_on:
- web
- redis
command: >
sh -c "celery -A KeRS beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler"
redis:
image: redis
# Db stuff
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: example
MYSQL_DATABASE: kers
MYSQL_USER: kers
MYSQL_PASSWORD: kers
# DB visual panel
adminer:
image: adminer
depends_on:
- db
ports:
- 8080:8080