diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 7ad3104..faf6a04 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -37,7 +37,8 @@ services: - MYSQL_TCP_PORT=3306 # environment variables available for both Docker usage and non Docker usage - "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-root}" - + - "MYSQL_PYROS_LOGIN=${MYSQL_PYROS_LOGIN:-pyros}" + - "MYSQL_PYROS_PWD=${MYSQL_PYROS_PWD:-DjangoPyros}" #- "IP_PYROS_USER=${IP_PYROS_USER:-172.28.1.5}" volumes: - ..:/home/pyros_user/app diff --git a/src/core/pyros_django/pyros/settings.py b/src/core/pyros_django/pyros/settings.py index 2902095..96cf9a8 100644 --- a/src/core/pyros_django/pyros/settings.py +++ b/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 env_path (str): path to .env file env_sample_path (str): path to .env-sample file """ - is_environment_variables_not_defined = os.environ.get("MYSQL_ROOT_PASSWORD") == None or os.environ.get("MYSQL_ROOT_LOGIN") == None + 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 if(is_environment_variables_not_defined): print("Some environment variables are not configured...") try: with open(env_path,"r") as env_file: print("Reading env file") for line in env_file: - if(line.startswith("#") and not env_sample_line.strip()): + if(line.startswith("#") and not line.strip()): continue else: key,value = line.split("=") @@ -81,7 +81,7 @@ def set_environment_variables_if_not_configured(env_path: str,env_sample_path: s os.environ[key] = value env_file.write(env_sample_line) else: - print("The environment variables are already configured, skipping...") + print("The environment variables are already configured, skipping this step...") # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -116,19 +116,19 @@ ENV_SAMPLE_PATH="../../../../docker/.env-sample" # default value of mysql port MYSQL_PORT = "3306" SQL_USER = "" -SQL_PSWD = "" +SQL_PWD = "" ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'pyros.irap.omp.eu'] # defining variables when using Docker if WITH_DOCKER: ALLOWED_HOSTS.append('0.0.0.0') HTTP_PORT = ":8000" -else: - try: - MYSQL_PORT = os.environ['MYSQL_TCP_PORT'] - SQL_USER = os.environ.get("MYSQL_PYROS_LOGIN").strip() - SQL_PSWD = os.environ.get("MYSQL_PYROS_PWD").strip() - except: - set_environment_variables_if_not_configured(ENV_PATH,ENV_SAMPLE_PATH) + +try: + MYSQL_PORT = os.environ['MYSQL_TCP_PORT'].strip() + SQL_USER = os.environ["MYSQL_PYROS_LOGIN"].strip() + SQL_PWD = os.environ["MYSQL_PYROS_PWD"].strip() +except: + set_environment_variables_if_not_configured(ENV_PATH,ENV_SAMPLE_PATH) # 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". DEFAULT_DOMAIN = f'{ALLOWED_HOSTS[0]}{HTTP_PORT}' # Application definition @@ -226,8 +226,8 @@ if MYSQL: 'OPTIONS': mysql_options, 'ENGINE': 'django.db.backends.mysql', 'NAME': 'pyros', - 'USER': 'pyros', - 'PASSWORD': 'DjangoPyros', + 'USER': SQL_USER, + 'PASSWORD': SQL_PWD, 'PORT': MYSQL_PORT, ''' (See https://docs.djangoproject.com/fr/2.1/topics/testing/overview/#the-test-database) -- libgit2 0.21.2