Browse Source
Vyrobeno nové `mamweb/settings_docker.py` jako kříženec mezi `_local` a `_test`. Úměrně tomu upraveno `mamweb/settings.py`, aby ho používalo při volání z kontejneru.`docker_entrypoint.sh` počká na start konejneru s Postgresem, zkontroluje existenci testdat (případně je vygeneruje) a spustí command specifikovaný v compose, tedy spustí webserver.dockerizace
Borek Požár
1 year ago
5 changed files with 162 additions and 25 deletions
@ -1,25 +1,23 @@ |
|||
|
|||
# TODO: |
|||
# - [ ] Pořídit vhodný django settings.py pro docker, aby to používalo postgress |
|||
services: |
|||
web: |
|||
build: . |
|||
command: python manage.py runserver 0.0.0.0:8000 |
|||
volumes: |
|||
- .:/usr/src |
|||
- .:/usr/mamweb-docker |
|||
ports: |
|||
- 8000:8000 |
|||
# env_file: |
|||
# - ./.env.dev |
|||
depends_on: |
|||
- db |
|||
|
|||
# db: |
|||
# image: postgres:13-bullseye |
|||
# volumes: |
|||
# - postgres_data:/var/lib/postgresql/data/ |
|||
# environment: |
|||
# - POSTGRES_USER=hello_django |
|||
# - POSTGRES_PASSWORD=hello_django |
|||
# - POSTGRES_DB=hello_django_dev |
|||
db: |
|||
image: postgres:13-bullseye |
|||
volumes: |
|||
- postgres_data:/var/lib/postgresql/data/ |
|||
environment: |
|||
- POSTGRES_USER=mam-web |
|||
- POSTGRES_PASSWORD=RoEGG5g7&b # Random generated string corresponding with Django settings |
|||
- POSTGRES_DB=mam_docker |
|||
|
|||
# volumes: |
|||
# postgres_data: |
|||
volumes: |
|||
postgres_data: |
@ -0,0 +1,19 @@ |
|||
#!/bin/sh |
|||
|
|||
echo "Waiting for Postgres..." |
|||
|
|||
while ! nc -z "db" "5432"; do |
|||
sleep 0.1 |
|||
done |
|||
|
|||
echo "PostgreSQL started" |
|||
|
|||
PGPASSWORD="RoEGG5g7&b" # Random generated, corresponds to the one in docker-compose.yml |
|||
if psql "postgresql://mam-web:$PGPASSWORD@db:5432/mam_docker" -t -c '\dt' | cut -d \| -f 2 | grep -qw "seminar_cisla"; then |
|||
echo "\nExistuje tabulka 'seminar_cisla' v db, testdata pravděpodobně byla vygenerována.\n" |
|||
else |
|||
python ./manage.py testdata |
|||
python ./manage.py loaddata data/* |
|||
fi |
|||
|
|||
exec "$@" |
@ -0,0 +1,117 @@ |
|||
# -*- coding: utf-8 -*- |
|||
|
|||
import os.path |
|||
|
|||
# |
|||
# Docker nastaveni settings.py |
|||
# |
|||
# Pro vyber tohoto nastaveni muzete pouzit tez: |
|||
# DJANGO_SETTINGS_MODULE=mamweb.settings_docker ./manage.py ... |
|||
# |
|||
|
|||
# Import common settings |
|||
from .settings_common import * # zatim nutne, casem snad vyresime # noqa |
|||
|
|||
MIDDLEWARE += ( |
|||
'debug_toolbar.middleware.DebugToolbarMiddleware', |
|||
) |
|||
|
|||
# Quick-start development settings - unsuitable for production |
|||
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ |
|||
|
|||
INSTALLED_APPS += ( |
|||
'debug_toolbar', |
|||
'django_extensions', |
|||
) |
|||
|
|||
# SECURITY WARNING: keep the secret key used in production secret! |
|||
SECRET_KEY = 'EZfSzeuDCycKr5ZjiCQ^45ZqFU@8Ke#YDwn9ThqerfEpu^yV#p' |
|||
|
|||
# SECURITY WARNING: don't run with debug turned on in production! |
|||
DEBUG = True |
|||
INTERNAL_IPS = ['127.0.0.1'] |
|||
|
|||
TEMPLATES[0]['OPTIONS']['debug'] = True |
|||
|
|||
from ipaddress import ip_network |
|||
ALLOWED_HOSTS = [str(ip) for ip in ip_network('192.168.0.0/16')] |
|||
ALLOWED_HOSTS.append('127.0.0.1') |
|||
ALLOWED_HOSTS.append('localhost') |
|||
|
|||
# Database |
|||
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases |
|||
|
|||
DATABASES = { |
|||
'default': { |
|||
'ENGINE': 'django.db.backends.postgresql_psycopg2', |
|||
'NAME': 'mam_docker', |
|||
'USER': 'mam-web', |
|||
'PASSWORD': 'RoEGG5g7&b', # Random generated string corresponding with docker-compose |
|||
'TEST': { |
|||
'NAME': 'mam-docker-testdb', |
|||
}, |
|||
"HOST": "db", |
|||
"PORT": "5432", |
|||
}, |
|||
} |
|||
|
|||
# import os |
|||
# SERVER_EMAIL = 'mamweb-test-errors@mam.mff.cuni.cz' |
|||
# ADMINS = [ |
|||
# ('M&M ERRORs', 'mam-errors@mam.mff.cuni.cz'), |
|||
# ] |
|||
|
|||
# SECURITY: only send sensitive cookies via HTTPS |
|||
# SESSION_COOKIE_SECURE = True |
|||
# CSRF_COOKIE_SECURE = True |
|||
|
|||
# LOGGING |
|||
LOGGING = { |
|||
'version': 1, |
|||
'disable_existing_loggers': True, |
|||
'filters': { |
|||
'require_debug_false': { |
|||
'()': 'django.utils.log.RequireDebugFalse' |
|||
} |
|||
}, |
|||
'formatters': { |
|||
'simple': { |
|||
'format': '%(asctime)s - %(name)s - %(levelname)-8s - %(message)s', |
|||
}, |
|||
}, |
|||
'handlers': { |
|||
'dummy': { |
|||
'class': 'logging.NullHandler', |
|||
}, |
|||
'console': { |
|||
'level': 'DEBUG', |
|||
'class': 'logging.StreamHandler', |
|||
'formatter': 'simple', |
|||
}, |
|||
}, |
|||
'loggers': { |
|||
# Vypisovani databazovych dotazu do konzole |
|||
#'django.db.backends': { |
|||
# 'level': 'DEBUG', |
|||
# 'handlers': ['console'], |
|||
# 'propagate': False, |
|||
#}, |
|||
'werkzeug': { |
|||
'handlers': ['console'], |
|||
'level': 'DEBUG', |
|||
'propagate': True, |
|||
}, |
|||
'': { |
|||
'handlers': ['console'], |
|||
'level': 'DEBUG', |
|||
'propagate': False, |
|||
}, |
|||
}, |
|||
} |
|||
|
|||
# FILE_UPLOAD_PERMISSIONS = 0o440 |
|||
|
|||
# Testování e-mailů |
|||
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' |
|||
SEND_EMAIL_NOTIFICATIONS = True |
|||
LOCAL_TEST_PROD = "local" |
Loading…
Reference in new issue