Commit 8348453ebc987a576f11c7e5fdb626f7824e0e25
1 parent
754bee06
Exists in
dev
Updating environment variables (add PYROS_LOGIN and PYROS_PWD) in docker-compose and settings.py
Showing
2 changed files
with
15 additions
and
14 deletions
Show diff stats
docker/docker-compose.yml
@@ -37,7 +37,8 @@ services: | @@ -37,7 +37,8 @@ services: | ||
37 | - MYSQL_TCP_PORT=3306 | 37 | - MYSQL_TCP_PORT=3306 |
38 | # environment variables available for both Docker usage and non Docker usage | 38 | # environment variables available for both Docker usage and non Docker usage |
39 | - "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-root}" | 39 | - "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-root}" |
40 | - | 40 | + - "MYSQL_PYROS_LOGIN=${MYSQL_PYROS_LOGIN:-pyros}" |
41 | + - "MYSQL_PYROS_PWD=${MYSQL_PYROS_PWD:-DjangoPyros}" | ||
41 | #- "IP_PYROS_USER=${IP_PYROS_USER:-172.28.1.5}" | 42 | #- "IP_PYROS_USER=${IP_PYROS_USER:-172.28.1.5}" |
42 | volumes: | 43 | volumes: |
43 | - ..:/home/pyros_user/app | 44 | - ..:/home/pyros_user/app |
src/core/pyros_django/pyros/settings.py
@@ -56,14 +56,14 @@ def set_environment_variables_if_not_configured(env_path: str,env_sample_path: s | @@ -56,14 +56,14 @@ def set_environment_variables_if_not_configured(env_path: str,env_sample_path: s | ||
56 | env_path (str): path to .env file | 56 | env_path (str): path to .env file |
57 | env_sample_path (str): path to .env-sample file | 57 | env_sample_path (str): path to .env-sample file |
58 | """ | 58 | """ |
59 | - is_environment_variables_not_defined = os.environ.get("MYSQL_ROOT_PASSWORD") == None or os.environ.get("MYSQL_ROOT_LOGIN") == None | 59 | + is_environment_variables_not_defined = os.environ.get("MYSQL_PYROS_LOGIN") == None or os.environ.get("MYSQL_PYROS_PWD") == None or os.environ.get("MYSQL_TCP_PORT") == None |
60 | if(is_environment_variables_not_defined): | 60 | if(is_environment_variables_not_defined): |
61 | print("Some environment variables are not configured...") | 61 | print("Some environment variables are not configured...") |
62 | try: | 62 | try: |
63 | with open(env_path,"r") as env_file: | 63 | with open(env_path,"r") as env_file: |
64 | print("Reading env file") | 64 | print("Reading env file") |
65 | for line in env_file: | 65 | for line in env_file: |
66 | - if(line.startswith("#") and not env_sample_line.strip()): | 66 | + if(line.startswith("#") and not line.strip()): |
67 | continue | 67 | continue |
68 | else: | 68 | else: |
69 | key,value = line.split("=") | 69 | key,value = line.split("=") |
@@ -81,7 +81,7 @@ def set_environment_variables_if_not_configured(env_path: str,env_sample_path: s | @@ -81,7 +81,7 @@ def set_environment_variables_if_not_configured(env_path: str,env_sample_path: s | ||
81 | os.environ[key] = value | 81 | os.environ[key] = value |
82 | env_file.write(env_sample_line) | 82 | env_file.write(env_sample_line) |
83 | else: | 83 | else: |
84 | - print("The environment variables are already configured, skipping...") | 84 | + print("The environment variables are already configured, skipping this step...") |
85 | 85 | ||
86 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) | 86 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) |
87 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 87 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
@@ -116,19 +116,19 @@ ENV_SAMPLE_PATH="../../../../docker/.env-sample" | @@ -116,19 +116,19 @@ ENV_SAMPLE_PATH="../../../../docker/.env-sample" | ||
116 | # default value of mysql port | 116 | # default value of mysql port |
117 | MYSQL_PORT = "3306" | 117 | MYSQL_PORT = "3306" |
118 | SQL_USER = "" | 118 | SQL_USER = "" |
119 | -SQL_PSWD = "" | 119 | +SQL_PWD = "" |
120 | ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'pyros.irap.omp.eu'] | 120 | ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'pyros.irap.omp.eu'] |
121 | # defining variables when using Docker | 121 | # defining variables when using Docker |
122 | if WITH_DOCKER: | 122 | if WITH_DOCKER: |
123 | ALLOWED_HOSTS.append('0.0.0.0') | 123 | ALLOWED_HOSTS.append('0.0.0.0') |
124 | HTTP_PORT = ":8000" | 124 | HTTP_PORT = ":8000" |
125 | -else: | ||
126 | - try: | ||
127 | - MYSQL_PORT = os.environ['MYSQL_TCP_PORT'] | ||
128 | - SQL_USER = os.environ.get("MYSQL_PYROS_LOGIN").strip() | ||
129 | - SQL_PSWD = os.environ.get("MYSQL_PYROS_PWD").strip() | ||
130 | - except: | ||
131 | - set_environment_variables_if_not_configured(ENV_PATH,ENV_SAMPLE_PATH) | 125 | + |
126 | +try: | ||
127 | + MYSQL_PORT = os.environ['MYSQL_TCP_PORT'].strip() | ||
128 | + SQL_USER = os.environ["MYSQL_PYROS_LOGIN"].strip() | ||
129 | + SQL_PWD = os.environ["MYSQL_PYROS_PWD"].strip() | ||
130 | +except: | ||
131 | + set_environment_variables_if_not_configured(ENV_PATH,ENV_SAMPLE_PATH) | ||
132 | # TODO : Change ALLOWED_HOSTS depending if you are using docker with windows (the domain is "localhost") or docker with another OS (the domain is "0.0.0.0"). If you are running PyROS without Docker, the domain is "localhost". | 132 | # TODO : Change ALLOWED_HOSTS depending if you are using docker with windows (the domain is "localhost") or docker with another OS (the domain is "0.0.0.0"). If you are running PyROS without Docker, the domain is "localhost". |
133 | DEFAULT_DOMAIN = f'{ALLOWED_HOSTS[0]}{HTTP_PORT}' | 133 | DEFAULT_DOMAIN = f'{ALLOWED_HOSTS[0]}{HTTP_PORT}' |
134 | # Application definition | 134 | # Application definition |
@@ -226,8 +226,8 @@ if MYSQL: | @@ -226,8 +226,8 @@ if MYSQL: | ||
226 | 'OPTIONS': mysql_options, | 226 | 'OPTIONS': mysql_options, |
227 | 'ENGINE': 'django.db.backends.mysql', | 227 | 'ENGINE': 'django.db.backends.mysql', |
228 | 'NAME': 'pyros', | 228 | 'NAME': 'pyros', |
229 | - 'USER': 'pyros', | ||
230 | - 'PASSWORD': 'DjangoPyros', | 229 | + 'USER': SQL_USER, |
230 | + 'PASSWORD': SQL_PWD, | ||
231 | 'PORT': MYSQL_PORT, | 231 | 'PORT': MYSQL_PORT, |
232 | ''' | 232 | ''' |
233 | (See https://docs.djangoproject.com/fr/2.1/topics/testing/overview/#the-test-database) | 233 | (See https://docs.djangoproject.com/fr/2.1/topics/testing/overview/#the-test-database) |