Commit e4c37a1aecdea2e501a71e78a170b2254bc5110f

Authored by Alexis Koralewski
1 parent 46b415a3
Exists in dev

Upgrading mysql version and fixing sql queries

  1 +18-02-2022 (AKo): v0.3.7.0
  2 + - Upgrade Mysql version
  3 + - Fix sql queries for mysql 8.0
  4 + - Add pyros_user in sequence list and detail
  5 + - Add description field in observatories configuration
  6 + - Add those description as tooltips when they are displayed sequence fields
  7 + - Add local fontawesome css
  8 + - Rename configpyros properly (ConfigPyros)
  9 + - Fix dockerfile issue with permission (uid needs to be the same as the host)
  10 +
1 08-02-2022 (AKo) : v0.3.6.0 11 08-02-2022 (AKo) : v0.3.6.0
2 - Add DRF (Django Rest Framework) to requirements 12 - Add DRF (Django Rest Framework) to requirements
3 - Add Pyros API (User and sequences with sequence submission) 13 - Add Pyros API (User and sequences with sequence submission)
1 FROM python:3.8 1 FROM python:3.8
  2 +ARG uid
2 3
3 RUN apt-get update && apt-get install -y \ 4 RUN apt-get update && apt-get install -y \
4 default-mysql-client \ 5 default-mysql-client \
@@ -9,9 +10,9 @@ RUN apt-get update && apt-get install -y \ @@ -9,9 +10,9 @@ RUN apt-get update && apt-get install -y \
9 # Get IRAP self signed certificate 10 # Get IRAP self signed certificate
10 RUN echo | openssl s_client -connect gitlab.irap.omp.eu:443 -servername gitlab.irap.omp.eu 2>/dev/null | openssl x509 > /etc/ssl/certs/gitlab.irap.omp.eu.crt 11 RUN echo | openssl s_client -connect gitlab.irap.omp.eu:443 -servername gitlab.irap.omp.eu 2>/dev/null | openssl x509 > /etc/ssl/certs/gitlab.irap.omp.eu.crt
11 12
12 - 13 +RUN echo "$uid" > test.txt
13 # adding new user (pyros_user) and creating his home folder 14 # adding new user (pyros_user) and creating his home folder
14 -RUN useradd --create-home --shell /bin/bash pyros_user 15 +RUN useradd --create-home --shell /bin/bash pyros_user --uid $uid
15 16
16 # Create the work dir and set permissions as pyros_user 17 # Create the work dir and set permissions as pyros_user
17 RUN mkdir -p /home/pyros_user/app/ && chown -R pyros_user:pyros_user /home/pyros_user/app 18 RUN mkdir -p /home/pyros_user/app/ && chown -R pyros_user:pyros_user /home/pyros_user/app
1 -0.3.6.0  
2 \ No newline at end of file 1 \ No newline at end of file
  2 +0.3.7.0
3 \ No newline at end of file 3 \ No newline at end of file
docker/PYROS_DOCKER_BUILD.bat
1 -docker-compose build 1 +CURRENT_UID=$(id -u) docker-compose build
2 2
docker/PYROS_DOCKER_INSTALL
@@ -15,6 +15,8 @@ fi @@ -15,6 +15,8 @@ fi
15 while ! docker inspect db_pyros --format='{{.State.Health.Status}}' | grep -q 'healthy' 15 while ! docker inspect db_pyros --format='{{.State.Health.Status}}' | grep -q 'healthy'
16 do 16 do
17 sleep 5 17 sleep 5
  18 + heal_status=$(docker inspect db_pyros --format='{{.State.Health.Status}}')
  19 + echo "Current status : $heal_status"
18 done 20 done
19 21
20 # db container is ready to execture queries, we can start the installation 22 # db container is ready to execture queries, we can start the installation
docker/PYROS_DOCKER_START.bat
1 docker-compose down --remove-orphans 1 docker-compose down --remove-orphans
2 2
3 -docker-compose up -d 3 +CURRENT_UID=$(id -u) docker-compose up -d
4 4
docker/docker-compose.yml
@@ -3,7 +3,8 @@ version: "3.9" @@ -3,7 +3,8 @@ version: "3.9"
3 services: 3 services:
4 db: 4 db:
5 # if we're using mysql >= 8, some of sql queries aren't valid anymore, like for creating and grant an user at the same time 5 # if we're using mysql >= 8, some of sql queries aren't valid anymore, like for creating and grant an user at the same time
6 - image: mysql:5.7.22 6 + # This is fixed in pyros.py
  7 + image: mysql:8.0.28
7 command: --default-authentication-plugin=mysql_native_password 8 command: --default-authentication-plugin=mysql_native_password
8 restart: always 9 restart: always
9 container_name: db_pyros 10 container_name: db_pyros
@@ -24,12 +25,6 @@ services: @@ -24,12 +25,6 @@ services:
24 # service image of python, that let users to interact with python scripts such as pyros. 25 # service image of python, that let users to interact with python scripts such as pyros.
25 pyros: 26 pyros:
26 # path to the Dockerfile of this image 27 # path to the Dockerfile of this image
27 - build: ..  
28 - container_name: pyros  
29 - # tty is the -t option in docker exec  
30 - tty: true  
31 - # stdin_open is the -i option in docker exec  
32 - stdin_open: true  
33 env_file: 28 env_file:
34 - variables.env 29 - variables.env
35 environment: 30 environment:
@@ -42,6 +37,15 @@ services: @@ -42,6 +37,15 @@ services:
42 - "MYSQL_PYROS_LOGIN=${MYSQL_PYROS_LOGIN:-pyros}" 37 - "MYSQL_PYROS_LOGIN=${MYSQL_PYROS_LOGIN:-pyros}"
43 - "MYSQL_PYROS_PWD=${MYSQL_PYROS_PWD:-DjangoPyros}" 38 - "MYSQL_PYROS_PWD=${MYSQL_PYROS_PWD:-DjangoPyros}"
44 #- "IP_PYROS_USER=${IP_PYROS_USER:-172.28.1.5}" 39 #- "IP_PYROS_USER=${IP_PYROS_USER:-172.28.1.5}"
  40 + build:
  41 + args:
  42 + uid: ${CURRENT_UID}
  43 + context: ..
  44 + container_name: pyros
  45 + # tty is the -t option in docker exec
  46 + tty: true
  47 + # stdin_open is the -i option in docker exec
  48 + stdin_open: true
45 volumes: 49 volumes:
46 - ..:/home/pyros_user/app 50 - ..:/home/pyros_user/app
47 # tells which port of local machine can communicate with the docker image (host:container), host is your local machine 51 # tells which port of local machine can communicate with the docker image (host:container), host is your local machine
@@ -21,8 +21,6 @@ import sys @@ -21,8 +21,6 @@ import sys
21 import time 21 import time
22 import re 22 import re
23 import glob 23 import glob
24 -from config.pyros.config_pyros import configpyros  
25 -from git import Repo  
26 #import logging 24 #import logging
27 25
28 26
@@ -345,9 +343,9 @@ def set_environment_variables_if_not_configured(env_path:str, env_sample_path:st @@ -345,9 +343,9 @@ def set_environment_variables_if_not_configured(env_path:str, env_sample_path:st
345 if WITH_DOCKER and os.environ.get(key) != value: 343 if WITH_DOCKER and os.environ.get(key) != value:
346 log.warning(f"WARNING: Environment value for '{key}' needs to be uptaded (To remove this message : restart docker container to update them).'") 344 log.warning(f"WARNING: Environment value for '{key}' needs to be uptaded (To remove this message : restart docker container to update them).'")
347 else: 345 else:
348 - if not WITH_DOCKER and os.environ.get(key) is None:  
349 - log.error(f"ERROR: Error while reading value for '{key}'.Please fix the '{env_file}' file. For this run, PyROS will take the values from '{env_path}'")  
350 - raise BaseException() 346 + # if not WITH_DOCKER and os.environ.get(key) is None:
  347 + # log.error(f"ERROR: Error while reading value for '{key}'.Please fix the '{env_file}' file. For this run, PyROS will take the values from '{env_path}'")
  348 + # raise BaseException()
351 if WITH_DOCKER and os.environ.get(key) is None: 349 if WITH_DOCKER and os.environ.get(key) is None:
352 log.warning(f"WARNING: Environment value for '{key}' isn't defined within the container (To remove this message : restart docker container to update environment values). PyROS will take the values from '{env_path}'") 350 log.warning(f"WARNING: Environment value for '{key}' isn't defined within the container (To remove this message : restart docker container to update environment values). PyROS will take the values from '{env_path}'")
353 raise BaseException() 351 raise BaseException()
@@ -519,6 +517,18 @@ def install_or_update(UPDATE:bool=False, packages_only:bool=False, database_only @@ -519,6 +517,18 @@ def install_or_update(UPDATE:bool=False, packages_only:bool=False, database_only
519 print("- packages_only:", packages_only) 517 print("- packages_only:", packages_only)
520 print("- database_only:", database_only) 518 print("- database_only:", database_only)
521 # Git clone Guitastro if not already cloned: 519 # Git clone Guitastro if not already cloned:
  520 + try:
  521 + from git import Repo
  522 + except:
  523 + pip = "pip" if IS_WINDOWS else "pip3"
  524 + process = subprocess.Popen(pip + " install --upgrade GitPython", shell=True)
  525 + process.wait()
  526 + if process.returncode == 0:
  527 + # self.addExecuted(self.current_command, command)
  528 + from git import Repo
  529 + else:
  530 + log.error("GitPython package (required for obsconfig class) installation failed")
  531 +
522 if not os.path.exists( os.path.join(os.getcwd(),"./vendor/guitastro")): 532 if not os.path.exists( os.path.join(os.getcwd(),"./vendor/guitastro")):
523 print("Cloning Guiastro repository") 533 print("Cloning Guiastro repository")
524 cloned_repo = Repo.clone_from("https://gitlab.irap.omp.eu/aklotz/guitastro.git", os.path.join(os.getcwd(),"./vendor/guitastro")) 534 cloned_repo = Repo.clone_from("https://gitlab.irap.omp.eu/aklotz/guitastro.git", os.path.join(os.getcwd(),"./vendor/guitastro"))
@@ -677,6 +687,19 @@ def initdb(): @@ -677,6 +687,19 @@ def initdb():
677 #def start(agent:str, configfile:str, test, verbosity): 687 #def start(agent:str, configfile:str, test, verbosity):
678 def start(agent:str, configfile:str, observatory:str, unit:str): 688 def start(agent:str, configfile:str, observatory:str, unit:str):
679 log.debug("Running start command") 689 log.debug("Running start command")
  690 + try:
  691 + from config.pyros.config_pyros import ConfigPyros
  692 + except:
  693 + #pip = "pip" if platform.system() == "Windows" else "pip3"
  694 + # TODO: "python -m pip" au lieu de "pip"
  695 + pip = "pip" if IS_WINDOWS else "pip3"
  696 + process = subprocess.Popen(pip + " install --upgrade pykwalify", shell=True)
  697 + process.wait()
  698 + if process.returncode == 0:
  699 + # self.addExecuted(self.current_command, command)
  700 + from config.pyros.config_pyros import configpyros
  701 + else:
  702 + log.error("pykwalify package (required for obsconfig class) installation failed")
680 if configfile: 703 if configfile:
681 log.debug("With config file"+ configfile) 704 log.debug("With config file"+ configfile)
682 os.environ["pyros_config_file"] = os.path.join(os.path.abspath(PYROS_DJANGO_BASE_DIR),"../../../config/pyros/", configfile) 705 os.environ["pyros_config_file"] = os.path.join(os.path.abspath(PYROS_DJANGO_BASE_DIR),"../../../config/pyros/", configfile)
@@ -684,7 +707,7 @@ def start(agent:str, configfile:str, observatory:str, unit:str): @@ -684,7 +707,7 @@ def start(agent:str, configfile:str, observatory:str, unit:str):
684 configfile = 'config_pyros.yml' 707 configfile = 'config_pyros.yml'
685 os.environ["pyros_config_file"] = os.path.join(os.path.abspath(PYROS_DJANGO_BASE_DIR),"../../../config/pyros/", configfile) 708 os.environ["pyros_config_file"] = os.path.join(os.path.abspath(PYROS_DJANGO_BASE_DIR),"../../../config/pyros/", configfile)
686 709
687 - logo_name = configpyros(os.environ["pyros_config_file"]).pyros_config["general"]["logo"] 710 + logo_name = ConfigPyros(os.environ["pyros_config_file"]).pyros_config["general"]["logo"]
688 logo_path = os.path.join(os.path.abspath(PYROS_DJANGO_BASE_DIR),"../../../config/pyros/", logo_name) 711 logo_path = os.path.join(os.path.abspath(PYROS_DJANGO_BASE_DIR),"../../../config/pyros/", logo_name)
689 media_path = os.path.join(os.path.abspath(PYROS_DJANGO_BASE_DIR),"misc/static/media",logo_name) 712 media_path = os.path.join(os.path.abspath(PYROS_DJANGO_BASE_DIR),"misc/static/media",logo_name)
690 shutil.copy(logo_path,media_path) 713 shutil.copy(logo_path,media_path)
@@ -1103,9 +1126,10 @@ def install_packages(): @@ -1103,9 +1126,10 @@ def install_packages():
1103 # Pip upgrade wheel and setuptools 1126 # Pip upgrade wheel and setuptools
1104 venv_pip_install('wheel', '--upgrade') 1127 venv_pip_install('wheel', '--upgrade')
1105 #os.system(VENV_PIP+' install --upgrade wheel') 1128 #os.system(VENV_PIP+' install --upgrade wheel')
1106 - venv_pip_install('setuptools', '--upgrade')  
1107 - #os.system(VENV_PIP+' install --upgrade setuptools')  
1108 - 1129 + # Not working with python 3.8 (on 17/02/2022)
  1130 + # venv_pip_install('setuptools', '--upgrade')
  1131 + os.system(VENV_PIP+' install setuptools==58')
  1132 +
1109 # Pip install required packages from REQUIREMENTS file 1133 # Pip install required packages from REQUIREMENTS file
1110 print() 1134 print()
1111 print(Colors.LOG_BLUE + "-----------------------------Installing python packages via pip-----------------------------" + Colors.END) 1135 print(Colors.LOG_BLUE + "-----------------------------Installing python packages via pip-----------------------------" + Colors.END)
@@ -1156,7 +1180,7 @@ def install_database(venv): @@ -1156,7 +1180,7 @@ def install_database(venv):
1156 # -------------------------------------------- 1180 # --------------------------------------------
1157 output = subprocess.check_output("mysql --version", shell=True) 1181 output = subprocess.check_output("mysql --version", shell=True)
1158 # output is something like: "mysql Ver 15.1 Distrib 10.0.20-MariaDB, for Linux (x86_64) using EditLine wrapper" 1182 # output is something like: "mysql Ver 15.1 Distrib 10.0.20-MariaDB, for Linux (x86_64) using EditLine wrapper"
1159 - tmp = (str(output).split()[4]).split('.') 1183 + tmp = (str(output).split()[2]).split('.')
1160 sql_version = float(tmp[0]+'.'+tmp[1]) 1184 sql_version = float(tmp[0]+'.'+tmp[1])
1161 print(Colors.LOG_BLUE + "MySQL version is " + str(sql_version) + Colors.END) 1185 print(Colors.LOG_BLUE + "MySQL version is " + str(sql_version) + Colors.END)
1162 1186
@@ -1184,7 +1208,8 @@ def install_database(venv): @@ -1184,7 +1208,8 @@ def install_database(venv):
1184 IF_EXISTS = '' if sql_version < 5.5 else 'IF EXISTS' 1208 IF_EXISTS = '' if sql_version < 5.5 else 'IF EXISTS'
1185 sql_query = \ 1209 sql_query = \
1186 f"DROP DATABASE {IF_EXISTS} {SQL_DATABASE}; CREATE DATABASE {SQL_DATABASE}; " +\ 1210 f"DROP DATABASE {IF_EXISTS} {SQL_DATABASE}; CREATE DATABASE {SQL_DATABASE}; " +\
1187 - f"DROP DATABASE {IF_EXISTS} {SQL_DATABASE_SIMU}; CREATE DATABASE {SQL_DATABASE_SIMU}; " 1211 + f"DROP DATABASE {IF_EXISTS} {SQL_DATABASE_SIMU}; CREATE DATABASE {SQL_DATABASE_SIMU}; " +\
  1212 + f"DROP DATABASE {IF_EXISTS} {SQL_DATABASE_TEST}; CREATE DATABASE {SQL_DATABASE_TEST}; "
1188 1213
1189 # 2) Create user pyros and give it all rights on 3 databases 1214 # 2) Create user pyros and give it all rights on 3 databases
1190 # Ne marche pas si l'utilisateur existe déjà => erreur 1215 # Ne marche pas si l'utilisateur existe déjà => erreur
@@ -1201,11 +1226,22 @@ def install_database(venv): @@ -1201,11 +1226,22 @@ def install_database(venv):
1201 host = "%" 1226 host = "%"
1202 else: 1227 else:
1203 host = "localhost" 1228 host = "localhost"
1204 -  
1205 - sql_query += f"GRANT ALL ON {SQL_DATABASE}.* TO '{SQL_USER}'@'{host}' IDENTIFIED BY '{SQL_PSWD}'; "  
1206 - sql_query += f"GRANT ALL ON {SQL_DATABASE_SIMU}.* TO '{SQL_USER}'@'{host}' IDENTIFIED BY '{SQL_PSWD}'; "  
1207 - # This database does not yet exists and will be automatically created by Django, but we already give access rights to it for pyros user  
1208 - sql_query += f"GRANT ALL ON {SQL_DATABASE_TEST}.* TO '{SQL_USER}'@'{host}' IDENTIFIED BY '{SQL_PSWD}'; " 1229 + # FOR MYSQL 8:
  1230 + if sql_version >=8:
  1231 + # We remove identified by because grant was creating the pyros user, wasn't working on version 8 so we separated the steps :
  1232 + # first we create the user then we grant him rights
  1233 + sql_query += f"CREATE USER IF NOT EXISTS '{SQL_USER}'@'{host}' IDENTIFIED BY '{SQL_PSWD}'; "
  1234 + sql_query += f"GRANT ALL ON {SQL_DATABASE}.* TO '{SQL_USER}'@'{host}'; "
  1235 + sql_query += f"GRANT ALL ON {SQL_DATABASE_SIMU}.* TO '{SQL_USER}'@'{host}'; "
  1236 + sql_query += f"GRANT ALL ON {SQL_DATABASE_TEST}.* TO '{SQL_USER}'@'{host}'; "
  1237 + else:
  1238 + sql_query += f"GRANT ALL ON {SQL_DATABASE}.* TO '{SQL_USER}'@'{host}' IDENTIFIED BY '{SQL_PSWD}'; "
  1239 + sql_query += f"GRANT ALL ON {SQL_DATABASE_SIMU}.* TO '{SQL_USER}'@'{host}' IDENTIFIED BY '{SQL_PSWD}'; "
  1240 + # This database does not yet exists and will be automatically created by Django, but we already give access rights to it for pyros user
  1241 + sql_query += f"GRANT ALL ON {SQL_DATABASE_TEST}.* TO '{SQL_USER}'@'{host}' IDENTIFIED BY '{SQL_PSWD}'; "
  1242 + # FOR MYSQL 8:
  1243 + if sql_version >= 8:
  1244 + sql_query += "FLUSH PRIVILEGES; "
1209 #"GRANT USAGE ON *.* TO '"+SQL_USER+"'@localhost ; " 1245 #"GRANT USAGE ON *.* TO '"+SQL_USER+"'@localhost ; "
1210 1246
1211 ''' 1247 '''
@@ -1247,7 +1283,7 @@ def install_database(venv): @@ -1247,7 +1283,7 @@ def install_database(venv):
1247 mysql_host = "localhost" 1283 mysql_host = "localhost"
1248 1284
1249 # when using -p option, there is no space between the option and the password value 1285 # when using -p option, there is no space between the option and the password value
1250 - mysql_call_root = f'mysql -h {mysql_host} -u {mysql_login} -p{mysql_root_password}' 1286 + mysql_call_root = f"mysql -h {mysql_host} -u '{mysql_login}' -p'{mysql_root_password}'"
1251 mysql_call_pyros = "\"" + MYSQL_EXE_PATH+ "mysql\" -u "+SQL_USER+" -p" 1287 mysql_call_pyros = "\"" + MYSQL_EXE_PATH+ "mysql\" -u "+SQL_USER+" -p"
1252 1288
1253 # -------------------------------------------- 1289 # --------------------------------------------