From 9b352582a315dce61734b0b72e9238d00ee5a31a Mon Sep 17 00:00:00 2001 From: Yohann D'anello Date: Sun, 2 Feb 2020 18:22:28 +0100 Subject: [PATCH 1/6] Docker --- Dockerfile | 18 ++++++++++++++++++ entrypoint.sh | 7 +++++++ 2 files changed, 25 insertions(+) create mode 100644 Dockerfile create mode 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2c84082 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM python:3-buster + +ENV PYTHONUNBUFFERED 1 + +RUN mkdir /code +WORKDIR /code + +RUN apt update && \ + apt install -y gettext nginx uwsgi uwsgi-plugin-python3 && \ + rm -rf /var/lib/apt/lists/* + +COPY requirements.txt /code/ +RUN pip install -r requirements.txt + +COPY . /code/ + +ENTRYPOINT ["/code/entrypoint.sh"] +EXPOSE 8000 diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..b9fb7ae --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/bash +python manage.py compilemessages +python manage.py makemigrations +python manage.py migrate + +# TODO: use uwsgi in production +python manage.py runserver 0.0.0.0:8000 From eb198f7c4f933760fb5e053a6d5d3f4f6815d433 Mon Sep 17 00:00:00 2001 From: Yohann D'anello Date: Sun, 2 Feb 2020 19:36:09 +0100 Subject: [PATCH 2/6] Test DB is SQLite3 --- med/settings_local.example.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/med/settings_local.example.py b/med/settings_local.example.py index 214c600..8b2e503 100644 --- a/med/settings_local.example.py +++ b/med/settings_local.example.py @@ -2,6 +2,8 @@ # Copyright (C) 2017-2019 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later +import os + # Needed to filter which host are trusted ALLOWED_HOSTS = ['med.crans.org'] @@ -30,12 +32,11 @@ SECRET_KEY = 'CHANGE ME !!!' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True +BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.mysql', - 'NAME': 'club-med', - 'USER': 'club-med', - 'PASSWORD': 'CHANGE ME !!!', - 'HOST': 'localhost', - }, + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } } From 6fd83e7398d98850e0554984e4cd051b9f8816ba Mon Sep 17 00:00:00 2001 From: Yohann D'anello Date: Sun, 2 Feb 2020 22:45:05 +0100 Subject: [PATCH 3/6] sleep before migration --- entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/entrypoint.sh b/entrypoint.sh index b9fb7ae..da32571 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,7 @@ #!/bin/bash python manage.py compilemessages python manage.py makemigrations +sleep 5 python manage.py migrate # TODO: use uwsgi in production From cf0ced6021237e62119db5036a07fd4c0ceec49f Mon Sep 17 00:00:00 2001 From: Yohann D'anello Date: Sun, 2 Feb 2020 23:13:39 +0100 Subject: [PATCH 4/6] 2 seconds are enough --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index da32571..3af5810 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/bash python manage.py compilemessages python manage.py makemigrations -sleep 5 +sleep 2 python manage.py migrate # TODO: use uwsgi in production From 978dc1de6c3c510054b9cc1659fab031438f0102 Mon Sep 17 00:00:00 2001 From: Yohann D'anello Date: Sun, 2 Feb 2020 23:55:35 +0100 Subject: [PATCH 5/6] postgresql by default --- README.md | 14 +++++++++++--- med/settings_local.example.py | 13 +++++++------ requirements.txt | 3 ++- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 37e3086..c398e50 100644 --- a/README.md +++ b/README.md @@ -29,12 +29,20 @@ ainsi qu'un user med et un mot de passe associé. Voici les étapes à éxecuter pour mysql : ```SQL -CREATE DATABASE club-med; -CREATE USER 'club-med'@'localhost' IDENTIFIED BY 'password'; -GRANT ALL PRIVILEGES ON club-med.* TO 'club-med'@'localhost'; +CREATE DATABASE med; +CREATE USER 'med'@'localhost' IDENTIFIED BY 'password'; +GRANT ALL PRIVILEGES ON med.* TO 'med'@'localhost'; FLUSH PRIVILEGES; ``` +Et pour postgresql : + +```SQL +CREATE DATABASE med; +CREATE USER med WITH PASSWORD 'password'; +GRANT ALL PRIVILEGES ON DATABASE med TO med; +``` + ## Exemple de groupes de droits ``` diff --git a/med/settings_local.example.py b/med/settings_local.example.py index 8b2e503..0270880 100644 --- a/med/settings_local.example.py +++ b/med/settings_local.example.py @@ -2,8 +2,6 @@ # Copyright (C) 2017-2019 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later -import os - # Needed to filter which host are trusted ALLOWED_HOSTS = ['med.crans.org'] @@ -32,11 +30,14 @@ SECRET_KEY = 'CHANGE ME !!!' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'med', + 'USER': 'med', + 'PASSWORD': 'password_to_store_in_env', + 'HOST': 'db', + 'PORT': '', } } + diff --git a/requirements.txt b/requirements.txt index c30b5b1..651bd3a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,5 @@ django-reversion==3.0.3 python-stdnum==1.10 djangorestframework==3.9.2 pyyaml==3.13 -coreapi==2.3.3 \ No newline at end of file +coreapi==2.3.3 +psycopg2 From ee16111766c494a598fbd64b344974f54b77124e Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Sun, 9 Feb 2020 13:31:31 +0100 Subject: [PATCH 6/6] Keep database settings for Zamok --- med/settings_local.example.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/med/settings_local.example.py b/med/settings_local.example.py index 0270880..f0d61c3 100644 --- a/med/settings_local.example.py +++ b/med/settings_local.example.py @@ -41,3 +41,13 @@ DATABASES = { } } +# or MySQL database for Zamok +# DATABASES = { +# 'default': { +# 'ENGINE': 'django.db.backends.mysql', +# 'NAME': 'club-med', +# 'USER': 'club-med', +# 'PASSWORD': 'CHANGE ME !!!', +# 'HOST': 'localhost', +# }, +# } \ No newline at end of file