[DEV] update config methodologie

This commit is contained in:
Edouard DUPIN 2020-03-10 22:32:47 +01:00
parent b8e80bbf1f
commit ceccd15519
5 changed files with 35 additions and 12 deletions

9
back/config_sample.env Normal file
View File

@ -0,0 +1,9 @@
# sample value with default config:
#DB_HOSTNAME="localhost"
#DB_PORT=15032
#DB_NAME="karideo"
#DB_USER="root"
#DB_PASSWORD="postgress_password"

View File

@ -4,15 +4,16 @@ services:
REST_video_service:
build: src
restart: always
environment:
SANIC_DB_ADDRESS: postgres
SANIC_DB_NAME: karideo
SANIC_DB_USER: postgres
SANIC_DB_PASSWORD: postgres
image: yui.heero/video_rest_api
container_name: video_rest_api
ports:
- "15080:80"
volumes:
- ./data/data_karideo:/application/data
- ./default_images:/default_images:ro
env_file:
- ./config.env

View File

@ -21,6 +21,13 @@ cd rest_video
Run the application
===================
Create configuration:
```
cp config_sample.env config.env
# set your server IP in the hostname
vim config.env
```
Start the application:
```
docker-compose up -d

View File

@ -13,11 +13,15 @@ import os
def get_rest_config():
variable = {
"tmp_data": "tmp",
"data": "data",
"data_media": "data/media",
"host": os.getenv('REST_HOSTNAME', "0.0.0.0"),
"port": int(os.getenv('REST_PORT', 80)),
#"tmp_data": "tmp",
#"data": "data",
#"data_media": "data/media",
#"host": os.getenv('REST_HOSTNAME', "0.0.0.0"),
#"port": int(os.getenv('REST_PORT', 80)),
"db_host": os.getenv('DB_HOSTNAME', "localhost"),
"db_port": int(os.getenv('DB_PORT', 15032)),
"db_name": os.getenv('DB_NAME', "karideo"),
"db_user": os.getenv('DB_USER', "root"),
"db_password": os.getenv('DB_PASSWORD', "postgress_password"),
}
return variable

View File

@ -1,6 +1,7 @@
from realog import debug
import psycopg2
import config
connection = None
connection_count = 0
@ -9,7 +10,8 @@ def connect_bdd():
global connection_count
if connection == None:
debug.info("connect BDD: ")
connection = psycopg2.connect(dbname="karideo", user="root", password="postgress_password", host="localhost", port="15032")
conf = config.get_rest_config()
connection = psycopg2.connect(dbname=conf["db_name"], user=conf["db_user"], password=conf["db_password"], host=conf["db_host"], port=conf["db_port"])
connection_count += 1
return connection