Commit 8d8d4b5082f620c02611e4eb9a2aef8cf3a56548
1 parent
da7c081d
Exists in
dev
adding mysql user and password to environment variables
Showing
3 changed files
with
17 additions
and
5 deletions
Show diff stats
docker/.env-sample
... | ... | @@ -13,4 +13,8 @@ MYSQL_ROOT_PASSWORD=root |
13 | 13 | # define the name of the root account (when not using Docker) |
14 | 14 | MYSQL_ROOT_LOGIN=root |
15 | 15 | # define mysql tcp port (default is 3306) |
16 | -MYSQL_TCP_PORT=3306 | |
17 | 16 | \ No newline at end of file |
17 | +MYSQL_TCP_PORT=3306 | |
18 | +# define login for superadmin user | |
19 | +MYSQL_PYROS_LOGIN=pyros | |
20 | +# define password for superadmin user | |
21 | +MYSQL_PYROS_PWD=DjangoPyros | |
18 | 22 | \ No newline at end of file | ... | ... |
pyros.py
... | ... | @@ -133,8 +133,8 @@ SQL_DATABASE = "pyros" |
133 | 133 | SQL_DATABASE_TEST = "test_pyros" |
134 | 134 | # Specific database that we need(ed?) for some simulations |
135 | 135 | SQL_DATABASE_SIMU = "pyros_test" |
136 | -SQL_USER = "pyros" | |
137 | -SQL_PSWD = "DjangoPyros" | |
136 | +SQL_USER = "" | |
137 | +SQL_PSWD = "" | |
138 | 138 | MYSQL_EXE_PATH = "" |
139 | 139 | |
140 | 140 | ENV_PATH = "docker/.env" |
... | ... | @@ -298,14 +298,14 @@ def set_environment_variables_if_not_configured(env_path: str,env_sample_path: s |
298 | 298 | env_path (str): path to .env file |
299 | 299 | env_sample_path (str): path to .env-sample file |
300 | 300 | """ |
301 | - is_environment_variables_not_defined = os.environ.get("MYSQL_ROOT_PASSWORD") == None or os.environ.get("MYSQL_ROOT_LOGIN") == None | |
301 | + is_environment_variables_not_defined = os.environ.get("MYSQL_ROOT_PASSWORD") == None or os.environ.get("MYSQL_ROOT_LOGIN") == None or os.environ.get("MYSQL_PYROS_LOGIN") == None or os.environ.get("MYSQL_PYROS_PWD") == None | |
302 | 302 | if(is_environment_variables_not_defined): |
303 | 303 | print("Some environment variables are not configured...") |
304 | 304 | try: |
305 | 305 | with open(env_path,"r") as env_file: |
306 | 306 | print("Reading env file") |
307 | 307 | for line in env_file: |
308 | - if(line.startswith("#") and not env_sample_line.strip()): | |
308 | + if(line.startswith("#") and not line.strip()): | |
309 | 309 | continue |
310 | 310 | else: |
311 | 311 | key,value = line.split("=") |
... | ... | @@ -439,6 +439,8 @@ def install(packages_only, database_only): |
439 | 439 | install_or_update(UPDATE=False, packages_only=packages_only, database_only=database_only) |
440 | 440 | |
441 | 441 | def install_or_update(UPDATE:bool=False, packages_only:bool=False, database_only:bool=False): |
442 | + SQL_USER = os.environ.get("MYSQL_PYROS_LOGIN").strip() | |
443 | + SQL_PSWD = os.environ.get("MYSQL_PYROS_PWD").strip() | |
442 | 444 | ACTION = "UPDATING" if UPDATE else "INSTALLING" |
443 | 445 | if WITH_DOCKER: |
444 | 446 | database_only = True |
... | ... | @@ -1012,6 +1014,8 @@ def install_packages(): |
1012 | 1014 | |
1013 | 1015 | def install_database(venv): |
1014 | 1016 | |
1017 | + SQL_USER = os.environ.get("MYSQL_PYROS_LOGIN").strip() | |
1018 | + SQL_PSWD = os.environ.get("MYSQL_PYROS_PWD").strip() | |
1015 | 1019 | print(Colors.LOG_BLUE + END_OF_LINE+"-----------------------------Launching mysql to create database and create and grant user pyros-----------------------------" + Colors.END) |
1016 | 1020 | |
1017 | 1021 | # -------------------------------------------- | ... | ... |
src/core/pyros_django/pyros/settings.py
... | ... | @@ -113,6 +113,8 @@ ENV_PATH="../../../../docker/.env" |
113 | 113 | ENV_SAMPLE_PATH="../../../../docker/.env-sample" |
114 | 114 | # default value of mysql port |
115 | 115 | MYSQL_PORT = "3306" |
116 | +SQL_USER = "" | |
117 | +SQL_PSWD = "" | |
116 | 118 | ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'pyros.irap.omp.eu'] |
117 | 119 | # defining variables when using Docker |
118 | 120 | if WITH_DOCKER: |
... | ... | @@ -120,6 +122,8 @@ if WITH_DOCKER: |
120 | 122 | else: |
121 | 123 | try: |
122 | 124 | MYSQL_PORT = os.environ['MYSQL_TCP_PORT'] |
125 | + SQL_USER = os.environ.get("MYSQL_PYROS_LOGIN").strip() | |
126 | + SQL_PSWD = os.environ.get("MYSQL_PYROS_PWD").strip() | |
123 | 127 | except: |
124 | 128 | set_environment_variables_if_not_configured(ENV_PATH,ENV_SAMPLE_PATH) |
125 | 129 | ... | ... |