From 95e0b0ad66f6576de1182a7d5d4d694521f998e5 Mon Sep 17 00:00:00 2001 From: jaguarondi Date: Mon, 25 Apr 2016 13:12:39 +0200 Subject: [PATCH 1/6] Change views to mvc in index --- source/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/index.rst b/source/index.rst index 9242bce..45be885 100644 --- a/source/index.rst +++ b/source/index.rst @@ -15,7 +15,7 @@ Contents: intro specs models - views + mvc forms admin docs From c93e1f6becb89d194a8b23eb506bd6766ec29c33 Mon Sep 17 00:00:00 2001 From: jaguarondi Date: Tue, 26 Apr 2016 16:24:34 +0200 Subject: [PATCH 2/6] Add postgresql and environment installation in production --- source/production.rst | 183 ++++++++++++++++++++- source/production/admin_without_static.png | Bin 0 -> 7539 bytes 2 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 source/production/admin_without_static.png diff --git a/source/production.rst b/source/production.rst index 7b0dbf2..0fa47ec 100644 --- a/source/production.rst +++ b/source/production.rst @@ -9,12 +9,193 @@ Pour une mise ne production, il nous faut donc quelque chose de plus solide: * Nginx comme serveur principal * Gunicorn comme serveur d'application * PostgreSQL comme base de données + * supervisor pour lancer notre application + +Les points suivants décrivent les étapes nécessaires à la mise en place de ces outils. + +***Remarque***: dans ce qui suit, les commandes exécutées en root seront précédées de $$$. + +********** +PostgreSQL +********** + +On commence par installer PostgreSQL. + +Par exemple, dans le cas de debian, on exécute la commande suivante: + +.. code-block:: shell + + $$$ aptitude install postgresql postgresql-contrib + +Ensuite, on crée un utilisateur pour la DB: + +.. code-block:: shell + + $$$ su - postgres + postgres@gwift:~$ createuser --interactive -P + Enter name of role to add: gwift_user + Enter password for new role: + Enter it again: + Shall the new role be a superuser? (y/n) n + Shall the new role be allowed to create databases? (y/n) n + Shall the new role be allowed to create more new roles? (y/n) n + postgres@gwift:~$ + +Finalement, on peut créer la DB: + +.. code-block:: shell + + postgres@gwift:~$ createdb --owner gwift_user gwift + postgres@gwift:~$ exit + logout + $$$ + +************ +environement +************ + +Préparation +=========== + +On prépare l'environement pour accueillir notre application django. + +Il faut d'abords rajouter certains packets qui seront nécessaires pour compiler certains module python: + +.. code-block:: shell + + $$$ aptitude install libpq-dev python3-dev + +On créé un utilisateur dédié, pour limiter les accès au serveur dans le cas où notre application serait piratée. + +.. code-block:: shell + + $$$ groupadd --system webapps + $$$ useradd --system --gid webapps --shell /bin/bash --home /webapps/gwift gwift + +Ensuite, on crée le repertoire où se trouvera notre application et on lui attribue le bon utilisatuer: + +.. code-block:: shell + + $$$ mkdir -p /webapps/gwift + $$$ chown gwift:webapps /webapps/gwift + +Puis on crée notre environement virtuel: + +.. code-block:: shell + + $$$ su - gwift + gwift@gwift:~$ mkvirtualenv -p /usr/bin/python3 gwift + Already using interpreter /usr/bin/python3 + Using base prefix '/usr' + New python executable in gwift/bin/python3 + Also creating executable in gwift/bin/python + Installing setuptools, pip...done. + (gwift)gwift@gwift:~$ + + +On peut maintenant cloner notre projet: + +.. code-block:: shell + + (gwift)gwift@gwift:~$ git clone git@framagit.org:Grimbox/gwift.git + +Et installer les dépendances: + +.. code-block:: shell + + (gwift)gwift@gwift:~$ pip install -r requirements/production.txt + + +Le fichier production.txt contient les librairies pour gunicorn et PostgreSQL: + +.. code-block:: txt + + -r base.txt + + gunicorn + psycopg2 + +Configuration +============= + +Il ne nous reste plus qu'à mettre à jour la DB. On commance par créer le fichier de configuration de l'application en production: + +.. code-block:: shell + + (gwift)gwift@gwift:~$ touch gwift/gwift/settings/local.py + +Et le contenu de local.py, avec la clé secrète et les paramètres pour se connecter à la DB: + +.. code-block:: python + + from .production import * + + # SECURITY WARNING: don't run with debug turned on in production! + DEBUG = False + + # SECURITY WARNING: keep the secret key used in production secret! + SECRET_KEY = 'strong_secret_key' + + # Password validation + # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators + AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, + ] + + # DB + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'gwift', + 'USER': 'gwift_user', + 'PASSWORD': 'gwift user password', + 'HOST': 'localhost', + 'PORT': '', # Set to empty string for default. + } + } + +Finalement, on peut mettre à jour la DB et créer un super utilisateur: + +.. code-block:: shell + + (gwift)gwift@gwift:~$ python manage.py migrate + (gwift)gwift@gwift:~$ python manage.py createsuperutilisater + +Test +==== + +On peut tester si tout fonctionne bien en lancant le server avec django + +.. code-block:: shell + + (gwift)gwift@gwift:~$ python manage.py runserver sever_name.com:8000 + +Et en se rendant sur server_name.com:8000/admin, on obtient: + +.. image:: production/admin_without_static.png + :align: center + +Comme on peut le voir, il n'y a pas de mise en forme de la page car les fichiers statics ne sont pas encore servis. Il le seront pas nginx + Voir http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/ Et http://tutos.readthedocs.org/en/latest/source/ndg.html -.. include:: production/environment.rst +Ne pas oublier la génération des fichiers statics ! + .. include:: production/postgresql.rst +.. include:: production/environment.rst .. include:: production/gunicorn.rst .. include:: production/nginx.rst diff --git a/source/production/admin_without_static.png b/source/production/admin_without_static.png new file mode 100644 index 0000000000000000000000000000000000000000..aa6b25ce0799c4f67953115a835463d43d66eb6c GIT binary patch literal 7539 zcmZu$1yodB*B(#-kx(3@Lpmg-8|m(n?id<`p%Fwxq!~aOW$2-Y4r%F<8X6IhE~z2@ z>-&A{|JVB0d)JzC@7iGa-W<4jIYekga$-p-g1WCGHxy|wyxeF z8BbeFZ(AE$Uq^2TS_LIFO@p@tBp?vwo|3GzE)=zwsdh<`c}IT>(v5EzOQT&~FHQAKO-=jicM#jaH1>8`er3|*TbCHoOJo`~n3fNkWZ}An!Ja2GNe{@uS=_$eYie5h z-mi1o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*)IMzVBzTt}=Maa3x0>zJ3hFfAzf0 z7Y`Uka1w_+MxH4tj~u_GYQa}l6AbIOA&m{ zw=`6ANGj@QII~SEV)fi@$j*K+fCWsYRRAolnbj(wYW+zgM(W$>(7>*vZmu(6gk3z{ zqI!NOwlP4B;*OKziWTDyiWuqX={~`2HMzMU>G+lL4mW3L_~1`EoJ1Jx&z|72zOJst zDi_?8Zr^BXVIh;7gBUGQ< zA4iRP?@S|1s0IH(w-df9B;)=X;qtM{P`N>Og%q~HjtBpk$5M)a38J$zwvr^LAh#b% z^VsT>0m?!1{VSs7%i5FsK;%g2T*%c7LU078<=wT|!1bQ4h^s+!791gS7}8Aq4FZGOA9e_KrAh!D%9#1Q~7+UZ_z6q_kil# zt^FpX*(azGI!?p}Zz0yqA^;PV z%e)v!y}Yz^i*{>|c=t}%KrijAQ@hxEV`$FNktD`EaemlqEF68V@Zdqm_7V`%vKc!R z7at>0|Lx6k`{@LZNEX3zFeYehegasJz{#|lS`3oErq$H-`VUY(qak($s%(!42(J1h zmjoqVL6~X^HiTiy5yUaTJ=_efUg?xA9BvC|eDagd7P02jxbQ{WZP>=6;W|UG<~<(S zwkVW4Mn0SfxY8T9hb?Yw6tuLolnfMd#o)Mm`6@hq7e-t3;9B8v{?+Bl^|ct6+rhVQ zQWO-%Eb4%%Fo76(dN3})K7)hG3aY7{Q)PqUX7K|%&qSc632npl_5*<9 f2y9=r9$ia9G0LC{uF}VV2&5#ZE?fS}BJ6(vhHPqU literal 0 HcmV?d00001 From 6ac8edea4f22c2f63ba227a382137820920147c4 Mon Sep 17 00:00:00 2001 From: jaguarondi Date: Tue, 26 Apr 2016 16:26:56 +0200 Subject: [PATCH 3/6] create separated files for production --- source/production.rst | 174 ------------------------------ source/production/environment.rst | 138 ++++++++++++++++++++++++ source/production/postgresql.rst | 35 ++++++ 3 files changed, 173 insertions(+), 174 deletions(-) diff --git a/source/production.rst b/source/production.rst index 0fa47ec..cd88e91 100644 --- a/source/production.rst +++ b/source/production.rst @@ -14,180 +14,6 @@ Pour une mise ne production, il nous faut donc quelque chose de plus solide: Les points suivants décrivent les étapes nécessaires à la mise en place de ces outils. ***Remarque***: dans ce qui suit, les commandes exécutées en root seront précédées de $$$. - -********** -PostgreSQL -********** - -On commence par installer PostgreSQL. - -Par exemple, dans le cas de debian, on exécute la commande suivante: - -.. code-block:: shell - - $$$ aptitude install postgresql postgresql-contrib - -Ensuite, on crée un utilisateur pour la DB: - -.. code-block:: shell - - $$$ su - postgres - postgres@gwift:~$ createuser --interactive -P - Enter name of role to add: gwift_user - Enter password for new role: - Enter it again: - Shall the new role be a superuser? (y/n) n - Shall the new role be allowed to create databases? (y/n) n - Shall the new role be allowed to create more new roles? (y/n) n - postgres@gwift:~$ - -Finalement, on peut créer la DB: - -.. code-block:: shell - - postgres@gwift:~$ createdb --owner gwift_user gwift - postgres@gwift:~$ exit - logout - $$$ - -************ -environement -************ - -Préparation -=========== - -On prépare l'environement pour accueillir notre application django. - -Il faut d'abords rajouter certains packets qui seront nécessaires pour compiler certains module python: - -.. code-block:: shell - - $$$ aptitude install libpq-dev python3-dev - -On créé un utilisateur dédié, pour limiter les accès au serveur dans le cas où notre application serait piratée. - -.. code-block:: shell - - $$$ groupadd --system webapps - $$$ useradd --system --gid webapps --shell /bin/bash --home /webapps/gwift gwift - -Ensuite, on crée le repertoire où se trouvera notre application et on lui attribue le bon utilisatuer: - -.. code-block:: shell - - $$$ mkdir -p /webapps/gwift - $$$ chown gwift:webapps /webapps/gwift - -Puis on crée notre environement virtuel: - -.. code-block:: shell - - $$$ su - gwift - gwift@gwift:~$ mkvirtualenv -p /usr/bin/python3 gwift - Already using interpreter /usr/bin/python3 - Using base prefix '/usr' - New python executable in gwift/bin/python3 - Also creating executable in gwift/bin/python - Installing setuptools, pip...done. - (gwift)gwift@gwift:~$ - - -On peut maintenant cloner notre projet: - -.. code-block:: shell - - (gwift)gwift@gwift:~$ git clone git@framagit.org:Grimbox/gwift.git - -Et installer les dépendances: - -.. code-block:: shell - - (gwift)gwift@gwift:~$ pip install -r requirements/production.txt - - -Le fichier production.txt contient les librairies pour gunicorn et PostgreSQL: - -.. code-block:: txt - - -r base.txt - - gunicorn - psycopg2 - -Configuration -============= - -Il ne nous reste plus qu'à mettre à jour la DB. On commance par créer le fichier de configuration de l'application en production: - -.. code-block:: shell - - (gwift)gwift@gwift:~$ touch gwift/gwift/settings/local.py - -Et le contenu de local.py, avec la clé secrète et les paramètres pour se connecter à la DB: - -.. code-block:: python - - from .production import * - - # SECURITY WARNING: don't run with debug turned on in production! - DEBUG = False - - # SECURITY WARNING: keep the secret key used in production secret! - SECRET_KEY = 'strong_secret_key' - - # Password validation - # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators - AUTH_PASSWORD_VALIDATORS = [ - { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', - }, - ] - - # DB - DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'gwift', - 'USER': 'gwift_user', - 'PASSWORD': 'gwift user password', - 'HOST': 'localhost', - 'PORT': '', # Set to empty string for default. - } - } - -Finalement, on peut mettre à jour la DB et créer un super utilisateur: - -.. code-block:: shell - - (gwift)gwift@gwift:~$ python manage.py migrate - (gwift)gwift@gwift:~$ python manage.py createsuperutilisater - -Test -==== - -On peut tester si tout fonctionne bien en lancant le server avec django - -.. code-block:: shell - - (gwift)gwift@gwift:~$ python manage.py runserver sever_name.com:8000 - -Et en se rendant sur server_name.com:8000/admin, on obtient: - -.. image:: production/admin_without_static.png - :align: center - -Comme on peut le voir, il n'y a pas de mise en forme de la page car les fichiers statics ne sont pas encore servis. Il le seront pas nginx - Voir http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/ Et http://tutos.readthedocs.org/en/latest/source/ndg.html diff --git a/source/production/environment.rst b/source/production/environment.rst index e69de29..c7922d0 100644 --- a/source/production/environment.rst +++ b/source/production/environment.rst @@ -0,0 +1,138 @@ + +************ +environement +************ + +Préparation +=========== + +On prépare l'environement pour accueillir notre application django. + +Il faut d'abords rajouter certains packets qui seront nécessaires pour compiler certains module python: + +.. code-block:: shell + + $$$ aptitude install libpq-dev python3-dev + +On créé un utilisateur dédié, pour limiter les accès au serveur dans le cas où notre application serait piratée. + +.. code-block:: shell + + $$$ groupadd --system webapps + $$$ useradd --system --gid webapps --shell /bin/bash --home /webapps/gwift gwift + +Ensuite, on crée le repertoire où se trouvera notre application et on lui attribue le bon utilisatuer: + +.. code-block:: shell + + $$$ mkdir -p /webapps/gwift + $$$ chown gwift:webapps /webapps/gwift + +Puis on crée notre environement virtuel: + +.. code-block:: shell + + $$$ su - gwift + gwift@gwift:~$ mkvirtualenv -p /usr/bin/python3 gwift + Already using interpreter /usr/bin/python3 + Using base prefix '/usr' + New python executable in gwift/bin/python3 + Also creating executable in gwift/bin/python + Installing setuptools, pip...done. + (gwift)gwift@gwift:~$ + + +On peut maintenant cloner notre projet: + +.. code-block:: shell + + (gwift)gwift@gwift:~$ git clone git@framagit.org:Grimbox/gwift.git + +Et installer les dépendances: + +.. code-block:: shell + + (gwift)gwift@gwift:~$ pip install -r requirements/production.txt + + +Le fichier production.txt contient les librairies pour gunicorn et PostgreSQL: + +.. code-block:: txt + + -r base.txt + + gunicorn + psycopg2 + +Configuration +============= + +Il ne nous reste plus qu'à mettre à jour la DB. On commance par créer le fichier de configuration de l'application en production: + +.. code-block:: shell + + (gwift)gwift@gwift:~$ touch gwift/gwift/settings/local.py + +Et le contenu de local.py, avec la clé secrète et les paramètres pour se connecter à la DB: + +.. code-block:: python + + from .production import * + + # SECURITY WARNING: don't run with debug turned on in production! + DEBUG = False + + # SECURITY WARNING: keep the secret key used in production secret! + SECRET_KEY = 'strong_secret_key' + + # Password validation + # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators + AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, + ] + + # DB + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'gwift', + 'USER': 'gwift_user', + 'PASSWORD': 'gwift user password', + 'HOST': 'localhost', + 'PORT': '', # Set to empty string for default. + } + } + +Finalement, on peut mettre à jour la DB et créer un super utilisateur: + +.. code-block:: shell + + (gwift)gwift@gwift:~$ python manage.py migrate + (gwift)gwift@gwift:~$ python manage.py createsuperutilisater + +Test +==== + +On peut tester si tout fonctionne bien en lancant le server avec django + +.. code-block:: shell + + (gwift)gwift@gwift:~$ python manage.py runserver sever_name.com:8000 + +Et en se rendant sur server_name.com:8000/admin, on obtient: + +.. image:: admin_without_static.png + :align: center + +Comme on peut le voir, il n'y a pas de mise en forme de la page car les fichiers statics ne sont pas encore servis. Il le seront pas nginx. \ No newline at end of file diff --git a/source/production/postgresql.rst b/source/production/postgresql.rst index e69de29..8c499a9 100644 --- a/source/production/postgresql.rst +++ b/source/production/postgresql.rst @@ -0,0 +1,35 @@ + +********** +PostgreSQL +********** + +On commence par installer PostgreSQL. + +Par exemple, dans le cas de debian, on exécute la commande suivante: + +.. code-block:: shell + + $$$ aptitude install postgresql postgresql-contrib + +Ensuite, on crée un utilisateur pour la DB: + +.. code-block:: shell + + $$$ su - postgres + postgres@gwift:~$ createuser --interactive -P + Enter name of role to add: gwift_user + Enter password for new role: + Enter it again: + Shall the new role be a superuser? (y/n) n + Shall the new role be allowed to create databases? (y/n) n + Shall the new role be allowed to create more new roles? (y/n) n + postgres@gwift:~$ + +Finalement, on peut créer la DB: + +.. code-block:: shell + + postgres@gwift:~$ createdb --owner gwift_user gwift + postgres@gwift:~$ exit + logout + $$$ From 2fbfc1b45a71f32e20dca41b25f5b5c0f2c4fc03 Mon Sep 17 00:00:00 2001 From: jaguarondi Date: Tue, 26 Apr 2016 16:31:50 +0200 Subject: [PATCH 4/6] Change folder to the image admin_without_static --- source/production/environment.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/production/environment.rst b/source/production/environment.rst index c7922d0..af3b8b4 100644 --- a/source/production/environment.rst +++ b/source/production/environment.rst @@ -132,7 +132,7 @@ On peut tester si tout fonctionne bien en lancant le server avec django Et en se rendant sur server_name.com:8000/admin, on obtient: -.. image:: admin_without_static.png +.. image:: production/admin_without_static.png :align: center Comme on peut le voir, il n'y a pas de mise en forme de la page car les fichiers statics ne sont pas encore servis. Il le seront pas nginx. \ No newline at end of file From b292f81e38a8a066be9c7b67bd3af27e0456e02e Mon Sep 17 00:00:00 2001 From: jaguarondi Date: Tue, 26 Apr 2016 16:34:55 +0200 Subject: [PATCH 5/6] misspelling --- source/production/environment.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/production/environment.rst b/source/production/environment.rst index af3b8b4..03b3278 100644 --- a/source/production/environment.rst +++ b/source/production/environment.rst @@ -135,4 +135,4 @@ Et en se rendant sur server_name.com:8000/admin, on obtient: .. image:: production/admin_without_static.png :align: center -Comme on peut le voir, il n'y a pas de mise en forme de la page car les fichiers statics ne sont pas encore servis. Il le seront pas nginx. \ No newline at end of file +Comme on peut le voir, il n'y a pas de mise en forme de la page car les fichiers statics ne sont pas encore servis. Il le seront par nginx. \ No newline at end of file From 8861010f02960b2f68d635999727bdd1b292b002 Mon Sep 17 00:00:00 2001 From: jaguarondi Date: Tue, 26 Apr 2016 21:09:52 +0200 Subject: [PATCH 6/6] Add allowed host for production in local.py and remove password policy that is defined in production.py --- source/production/environment.rst | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/source/production/environment.rst b/source/production/environment.rst index 03b3278..9656397 100644 --- a/source/production/environment.rst +++ b/source/production/environment.rst @@ -85,23 +85,9 @@ Et le contenu de local.py, avec la clé secrète et les paramètres pour se conn # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'strong_secret_key' - # Password validation - # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators - AUTH_PASSWORD_VALIDATORS = [ - { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', - }, - ] - + # Allowed host needed to be defined in production + ALLOWED_HOSTS = ["sever_name.com", "www.sever_name.com"] + # DB DATABASES = { 'default': { @@ -124,7 +110,7 @@ Finalement, on peut mettre à jour la DB et créer un super utilisateur: Test ==== -On peut tester si tout fonctionne bien en lancant le server avec django +On peut tester si tout fonctionne bien en lançant le server avec django .. code-block:: shell