mirror of
				https://gitlab.crans.org/bde/nk20
				synced 2025-10-31 15:50:03 +01:00 
			
		
		
		
	More envs
This commit is contained in:
		
							
								
								
									
										13
									
								
								.env_example
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								.env_example
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| DJANGO_APP_STAGE=dev | ||||
| # Only used in dev mode, change to "postgresql" if you want to use PostgreSQL in dev | ||||
| DJANGO_DEV_STORE_METHOD=sqllite | ||||
| DJANGO_DB_HOST=localhost | ||||
| DJANGO_DB_NAME=note_db | ||||
| DJANGO_DB_USER=note | ||||
| DJANGO_DB_PASSWORD=CHANGE_ME | ||||
| DJANGO_DB_PORT= | ||||
| DJANGO_SECRET_KEY=CHANGE_ME | ||||
| DJANGO_SETTINGS_MODULE=note_kfet.settings | ||||
| DOMAIN=localhost | ||||
| MAILING_LIST_DOMAIN=localhost | ||||
| NOTE_URL=localhost | ||||
							
								
								
									
										57
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										57
									
								
								README.md
									
									
									
									
									
								
							| @@ -40,14 +40,13 @@ On supposera pour la suite que vous utiliser debian/ubuntu sur un serveur tout n | ||||
|  | ||||
|         $ cp nginx_note.conf_example nginx_note.conf | ||||
|  | ||||
| ***Modifier le fichier pour être en accord avec le reste de votre config*** | ||||
|     ***Modifier le fichier pour être en accord avec le reste de votre config*** | ||||
|  | ||||
|     On utilise uwsgi et Nginx pour gérer le coté serveur : | ||||
|  | ||||
|         $ sudo ln -sf /var/www/note_kfet/nginx_note.conf /etc/nginx/sites-enabled/ | ||||
|        $ sudo ln -sf /var/www/note_kfet/nginx_note.conf /etc/nginx/sites-enabled/ | ||||
|  | ||||
|  | ||||
|     Si l'on a un emperor (plusieurs instance uwsgi): | ||||
|    Si l'on a un emperor (plusieurs instance uwsgi): | ||||
|  | ||||
|         $ sudo ln -sf /var/www/note_kfet/uwsgi_note.ini /etc/uwsgi/sites/ | ||||
|  | ||||
| @@ -85,7 +84,7 @@ On supposera pour la suite que vous utiliser debian/ubuntu sur un serveur tout n | ||||
|         postgres=# CREATE DATABASE note_db OWNER note; | ||||
|         CREATE DATABASE | ||||
|  | ||||
|     Si tout va bien: | ||||
|     Si tout va bien : | ||||
|          | ||||
|         postgres=#\list | ||||
|         List of databases | ||||
| @@ -96,22 +95,29 @@ On supposera pour la suite que vous utiliser debian/ubuntu sur un serveur tout n | ||||
|          template0 | postgres | UTF8     | fr_FR.UTF-8 | fr_FR.UTF-8 | =c/postgres+postgres=CTc/postgres | ||||
|          template1 | postgres | UTF8     | fr_FR.UTF-8 | fr_FR.UTF-8 | =c/postgres  +postgres=CTc/postgres | ||||
|         (4 rows) | ||||
|  | ||||
|     Dans un fichier `.env` à la racine du projet on renseigne des secrets: | ||||
|      | ||||
|         DJANGO_APP_STAGE='prod' | ||||
|         DJANGO_DB_PASSWORD='le_mot_de_passe_de_la_bdd' | ||||
|         DJANGO_SECRET_KEY='une_secret_key_longue_et_compliquee' | ||||
|         ALLOWED_HOSTS='le_ndd_de_votre_instance' | ||||
|      | ||||
|  | ||||
| 6. Variable d'environnement et Migrations | ||||
|          | ||||
|     On copie le fichier `.env_example` vers le fichier `.env` à la racine du projet  | ||||
|     et on renseigne des secrets et des paramètres : | ||||
|      | ||||
|         DJANGO_APP_STAGE=dev | ||||
|         DJANGO_DEV_STORE_METHOD=sqllite | ||||
|         DJANGO_DB_HOST=localhost | ||||
|         DJANGO_DB_NAME=note_db | ||||
|         DJANGO_DB_USER=note | ||||
|         DJANGO_DB_PASSWORD=CHANGE_ME | ||||
|         DJANGO_DB_PORT= | ||||
|         DJANGO_SECRET_KEY=CHANGE_ME | ||||
|         DJANGO_SETTINGS_MODULE=note_kfet.settings | ||||
|         DOMAIN=localhost | ||||
|         MAILING_LIST_DOMAIN=localhost | ||||
|         NOTE_URL=localhost | ||||
|  | ||||
| Ensuite on (re)bascule dans l'environement virtuel et on lance les migrations | ||||
|     Ensuite on (re)bascule dans l'environement virtuel et on lance les migrations | ||||
|  | ||||
|         $ source /env/bin/activate | ||||
|         (env)$ ./manage.py check # pas de bétise qui traine | ||||
|         (env)$ ./manage.py check # pas de bêtise qui traine | ||||
|         (env)$ ./manage.py makemigrations | ||||
|         (env)$ ./manage.py migrate | ||||
|  | ||||
| @@ -126,17 +132,17 @@ Il est possible de travailler sur une instance Docker. | ||||
|      | ||||
|         $ git clone git@gitlab.crans.org:bde/nk20.git | ||||
|  | ||||
| 2. Dans le fichier `docker_compose.yml`, qu'on suppose déjà configuré, | ||||
| 2. Copiez le fichier `.env_example` à la racine du projet vers le fichier `.env`, | ||||
| et  mettez à jour vos variables d'environnement | ||||
|  | ||||
| 3. Dans le fichier `docker_compose.yml`, qu'on suppose déjà configuré, | ||||
|    ajouter les lignes suivantes, en les adaptant à la configuration voulue : | ||||
|  | ||||
|         nk20: | ||||
|           build: /chemin/vers/nk20 | ||||
|           volumes: | ||||
|             - /chemin/vers/nk20:/code/ | ||||
|           environment: | ||||
|             MAILING_LIST_DOMAIN: lists.example.com | ||||
|             NOTE_URL: nk20.example.com | ||||
|             DOMAIN: example.com | ||||
|           env_file: /chemin/vers/nk20/.env | ||||
|           restart: always | ||||
|           labels: | ||||
|             - traefik.domain=ndd.example.com | ||||
| @@ -163,17 +169,20 @@ un serveur de développement par exemple sur son ordinateur. | ||||
|         $ source venv/bin/activate | ||||
|         (env)$ pip install -r requirements.txt | ||||
|  | ||||
| 3. Migrations et chargement des données initiales : | ||||
| 3. Copier le fichier `.env_example` vers `.env` à la racine du projet et mettre à jour | ||||
| ce qu'il faut | ||||
|  | ||||
| 4. Migrations et chargement des données initiales : | ||||
|  | ||||
|         (env)$ ./manage.py makemigrations | ||||
|         (env)$ ./manage.py migrate | ||||
|         (env)$ ./manage.py loaddata initial | ||||
|  | ||||
| 4. Créer un super-utilisateur : | ||||
| 5. Créer un super-utilisateur : | ||||
|  | ||||
|         (env)$ ./manage.py createsuperuser | ||||
|  | ||||
| 5. Enjoy : | ||||
| 6. Enjoy : | ||||
|  | ||||
|         (env)$ ./manage.py runserver 0.0.0.0:8000 | ||||
|  | ||||
| @@ -188,4 +197,4 @@ Il est disponible [ici](https://wiki.crans.org/NoteKfet/NoteKfet2018/CdC). | ||||
| ## Documentation | ||||
|  | ||||
| La documentation est générée par django et son module admindocs. | ||||
| **Commenter votre code !** | ||||
| **Commentez votre code !** | ||||
|   | ||||
| @@ -35,10 +35,6 @@ read_env() | ||||
| app_stage = os.environ.get('DJANGO_APP_STAGE', 'dev') | ||||
| if app_stage == 'prod': | ||||
|     from .production import * | ||||
|  | ||||
|     DATABASES["default"]["PASSWORD"] = os.environ.get('DJANGO_DB_PASSWORD', 'CHANGE_ME_IN_ENV_SETTINGS') | ||||
|     SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'CHANGE_ME_IN_ENV_SETTINGS') | ||||
|     ALLOWED_HOSTS = [os.environ.get('ALLOWED_HOSTS', 'localhost')] | ||||
| else: | ||||
|     from .development import * | ||||
|  | ||||
|   | ||||
| @@ -17,12 +17,24 @@ import os | ||||
| # https://docs.djangoproject.com/en/2.2/ref/settings/#databases | ||||
| from . import * | ||||
|  | ||||
| DATABASES = { | ||||
|     'default': { | ||||
|         'ENGINE': 'django.db.backends.sqlite3', | ||||
|         'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), | ||||
| if os.getenv("DJANGO_DEV_STORE_METHOD", "sqllite") == "postgresql": | ||||
|     DATABASES = { | ||||
|         'default': { | ||||
|             'ENGINE': 'django.db.backends.postgresql_psycopg2', | ||||
|             'NAME': os.environ.get('DJANGO_DB_NAME', 'note_db'), | ||||
|             'USER': os.environ.get('DJANGO_DB_USER', 'note'), | ||||
|             'PASSWORD': os.environ.get('DJANGO_DB_PASSWORD', 'CHANGE_ME_IN_ENV_SETTINGS'), | ||||
|             'HOST': os.environ.get('DJANGO_DB_HOST', 'localhost'), | ||||
|             'PORT': os.environ.get('DJANGO_DB_PORT', ''),  # Use default port | ||||
|         } | ||||
|     } | ||||
| else: | ||||
|     DATABASES = { | ||||
|         'default': { | ||||
|             'ENGINE': 'django.db.backends.sqlite3', | ||||
|             'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| # Break it, fix it! | ||||
| DEBUG = True | ||||
|   | ||||
| @@ -16,11 +16,11 @@ import os | ||||
| DATABASES = { | ||||
|     'default': { | ||||
|         'ENGINE': 'django.db.backends.postgresql_psycopg2', | ||||
|         'NAME': 'note_db', | ||||
|         'USER': 'note', | ||||
|         'PASSWORD': 'update_in_env_variable', | ||||
|         'HOST': '127.0.0.1', | ||||
|         'PORT': '', | ||||
|         'NAME': os.environ.get('DJANGO_DB_NAME', 'note_db'), | ||||
|         'USER': os.environ.get('DJANGO_DB_USER', 'note'), | ||||
|         'PASSWORD': os.environ.get('DJANGO_DB_PASSWORD', 'CHANGE_ME_IN_ENV_SETTINGS'), | ||||
|         'HOST': os.environ.get('DJANGO_DB_HOST', 'localhost'), | ||||
|         'PORT': os.environ.get('DJANGO_DB_PORT', ''),  # Use default port | ||||
|     } | ||||
| } | ||||
|  | ||||
| @@ -28,7 +28,9 @@ DATABASES = { | ||||
| DEBUG = True | ||||
|  | ||||
| # Mandatory ! | ||||
| ALLOWED_HOSTS = [] | ||||
| ALLOWED_HOSTS = [os.environ.get('NOTE_URL', 'localhost')] | ||||
|  | ||||
| SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'CHANGE_ME_IN_ENV_SETTINGS') | ||||
|  | ||||
| # Emails | ||||
| EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' | ||||
|   | ||||
		Reference in New Issue
	
	Block a user