Commit a6ce0e13e27998b4cf2d511e6ca147a963ea4a0b

Authored by Alexis Koralewski
2 parents b878d67a 8ca1d24c
Exists in dev

Merge branch 'dev' of https://gitlab.irap.omp.eu/pyros-irap/pyros into dev

docker/Dockerfile
... ... @@ -171,6 +171,8 @@ RUN useradd -m -s /bin/bash pyros_user --uid $uid
171 171  
172 172 # Create the work dir and set permissions as pyros_user
173 173 RUN mkdir -p /home/pyros_user/app/ && chown -R pyros_user:pyros_user /home/pyros_user/app
  174 +
  175 +# cd /home/pyros_user/app
174 176 WORKDIR /home/pyros_user/app
175 177  
176 178 # Switch from root to pyros_user
... ... @@ -184,6 +186,8 @@ RUN mkdir -p ./vendor/guitastro/install/
184 186 RUN mkdir -p ./install/
185 187  
186 188 # Copy local host machine files to image
  189 +# Dockerfile contains this volume => ../..:/home/pyros_user/app
  190 +# Thus, this will copy PYROS_SOFT/* ==TO==> /home/pyros_user/app/ (the WORKDIR)
187 191 COPY ./vendor/guitastro/install/requirements.in ./vendor/guitastro/install/requirements.in
188 192 COPY ./install/requirements.txt ./install/requirements.txt
189 193 COPY ./install/requirements_dev.txt ./install/requirements_dev.txt
... ... @@ -193,9 +197,9 @@ ENV PATH "$PATH:/home/pyros_user/.local/bin"
193 197  
194 198  
195 199 # Installing click on the image to prevent error on the first execution of the installation script
196   -RUN python3 -m pip install --user click
  200 +RUN python3 -m pip install --user click
197 201  
198   -RUN python3 -m pip install --user setuptools==58
  202 +RUN python3 -m pip install --user setuptools==58
199 203  
200 204 # (EP 23/3/2022) Installing pip-tools for the management of all the requirements*.txt files (python dependencies packages)
201 205 # NB :
... ... @@ -204,14 +208,14 @@ RUN python3 -m pip install --user setuptools==58
204 208 # - Unfortunatly, it is difficult to use with several requirements*.txt files as it is the case for this software : pyros + sphinx + guitastro...
205 209 # - So we cannot yet use it completely and still have to use the traditional "pip install -r" anyway ...
206 210 # - But we can at least use it to generate all the requirements*.txt files in a far better format
207   -RUN python3 -m pip install --user pip-tools
  211 +RUN python3 -m pip install --user pip-tools
208 212  
209 213 # Installing packages required for Guitastro
210 214 RUN pip-compile ./vendor/guitastro/install/requirements.in
211   -RUN python3 -m pip install --user -r ./vendor/guitastro/install/requirements.txt
  215 +RUN python3 -m pip install --user -r ./vendor/guitastro/install/requirements.txt
212 216 # Maybe unnecessary because same requirements as for pyros requirements_dev (?)
213 217 #RUN pip install --user -r ./vendor/guitastro/install/requirements_dev.txt
214 218  
215 219 # Installing packages required for PyROS
216   -RUN python3 -m pip install --user -r ./install/requirements.txt
217   -RUN python3 -m pip install --user -r ./install/requirements_dev.txt
  220 +RUN python3 -m pip install --user -r ./install/requirements.txt
  221 +RUN python3 -m pip install --user -r ./install/requirements_dev.txt
... ...
docker/PYROS_DOCKER_BUILD
1 1 #!/usr/bin/env bash
2 2  
  3 +# Git clone guitastro
  4 +#
  5 +# This could be done directly in the Dockerfile
  6 +# but it is better to do it here because if it failed during the build
  7 +# we would have to do all the build again...
3 8 [ ! -d "../vendor/guitastro/" ] && git clone https://gitlab.irap.omp.eu/guitastrolib/guitastro.git ../vendor/guitastro/
  9 +[ ! -d "../vendor/guitastro/" ] && echo "Error : git clone of GuitAstro failed => cannot go on with the build" && exit 1
4 10  
5 11 export CURRENT_UID=$(id -u)
6 12 export COMPUTER_HOSTNAME=$HOSTNAME
... ...
docker/PYROS_DOCKER_INSTALL_DB
1 1 #!/usr/bin/env bash
2 2  
3   -export CURRENT_UID=$(id -u)
4   -export COMPUTER_HOSTNAME=$HOSTNAME
  3 +# PRE-CONDITION : pyros container must be running
5 4  
6 5 # if no container is running
7 6 if ! [ $(docker ps | grep 'pyros' | wc -l) -eq 4 ] ; then
... ...
docker/PYROS_DOCKER_UPDATE
1 1 #!/usr/bin/env bash
2 2  
3   -export CURRENT_UID=$(id -u)
4   -export COMPUTER_HOSTNAME=$HOSTNAME
  3 +# PRE-CONDITION : pyros container must be running
5 4  
6 5 # If no container is running Start it
7 6 if ! [ $(docker ps | grep 'pyros' | wc -l) -eq 4 ]
... ... @@ -19,10 +18,12 @@ echo "Updating Guitastro source code"
19 18 echo "Updating PyROS source code"
20 19 git pull
21 20  
22   -echo "Updating observatory source code"
23   -for dir in ../../PYROS_OBSERVATORY/*
24   -do
25   - git pull
  21 +# 3) Update all observatories with git repo
  22 +for dir in ../../PYROS_OBSERVATORY/* ; do
  23 + if [ -d .git ] ; then
  24 + echo "Updating observatory $dir source code"
  25 + git pull
  26 + fi
26 27 done
27 28  
28 29 # 3) pyros.py update => update BD + doc + Guitastro requirements
... ...
docker/docker-compose.yml
... ... @@ -111,6 +111,7 @@ services:
111 111 tty: true
112 112 # stdin_open is the -i option in docker exec
113 113 stdin_open: true
  114 + # Local PYROS_SOFT/ folder is linked to container /home/pyros_user/app folder
114 115 volumes:
115 116 - ../..:/home/pyros_user/app
116 117 # tells which port of local machine can communicate with the docker image (host:container), host is your local machine
... ...
pyros.py
... ... @@ -534,7 +534,7 @@ def dbshell():
534 534  
535 535 @pyros_launcher.command(help="Update (only if necessary) the python packages AND the source code AND the DB structure")
536 536 def update():
537   - install_or_update(UPDATE=True)
  537 + _install_or_update(UPDATE=True)
538 538 '''
539 539 print("Running update command")
540 540 # 1) Update source code (git pull)
... ... @@ -568,13 +568,14 @@ def update():
568 568 def install(packages_only, database_only):
569 569 with_packages = not database_only
570 570 with_database = not packages_only
571   - install_or_update(UPDATE=False, with_packages=with_packages,
  571 + _install_or_update(UPDATE=False, with_packages=with_packages,
572 572 with_database=with_database)
573 573 # install_or_update(UPDATE=False, with_packages=packages_only, with_database=database_only)
574 574 # install_or_update(UPDATE=False, packages_only=packages_only, database_only=database_only)
575 575  
  576 +
576 577 # def install_or_update(UPDATE: bool = False, with_packages: bool = False, with_database: bool = False):
577   -def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_database: bool = True):
  578 +def _install_or_update(UPDATE: bool = False, with_packages: bool = True, with_database: bool = True):
578 579 SQL_USER = os.environ.get("MYSQL_PYROS_LOGIN").strip()
579 580 SQL_PSWD = os.environ.get("MYSQL_PYROS_PWD").strip()
580 581 os.environ["PATH_TO_OBSCONF_FOLDER"] = os.path.join(os.path.abspath(
... ... @@ -583,7 +584,7 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat
583 584 PYROS_DJANGO_BASE_DIR), os.environ["PATH_TO_OBSCONF_FOLDER"] + "observatory.yml")
584 585 ACTION = "UPDATING" if UPDATE else "INSTALLING"
585 586  
586   - # if WITH_DOCKER: with_database = True
  587 + # if WITH_DOCKER: only install the DB (with_database = True)
587 588 if WITH_DOCKER:
588 589 with_packages = False
589 590  
... ... @@ -597,21 +598,22 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat
597 598 # if (os.path.basename(os.getcwd()) != "private"):
598 599  
599 600 num = 0
600   - # 1) Update source code (git pull)
  601 +
601 602 if UPDATE:
  603 + # Update source code (git pull)
602 604 num += 1
603   - printFullTerm(
604   - Colors.BLUE, f"{num}) UPDATING SOURCE CODE: Running git pull")
  605 + printFullTerm(Colors.BLUE, f"{num}) UPDATING SOURCE CODE: Running git pull")
605 606 if not WITH_DOCKER:
606 607 _gitpull() or die()
607 608  
608   - # 2) Update python packages (pip upgrade AND pip install requirements)
609 609 if with_packages:
  610 + # Update python packages (pip upgrade AND pip install requirements)
610 611 num += 1
611 612 printFullTerm(Colors.BLUE, f"{num}) {ACTION} PYTHON PACKAGES")
612 613 # (UPDATE) Re-install VENV if disappeared
613 614 install_venv(EVEN_IF_ALREADY_EXISTS=not UPDATE)
614 615 install_packages()
  616 +
615 617 if UPDATE:
616 618 print("Running UPDATE command")
617 619 else:
... ... @@ -621,13 +623,10 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat
621 623 from git import Repo
622 624 except:
623 625 pip = "pip" if IS_WINDOWS else "pip3"
624   - if WITH_DOCKER:
625   - process = subprocess.Popen(
626   - pip + " install --user --upgrade GitPython", shell=True)
627   - else:
628   - process = subprocess.Popen(
629   - pip + " install --upgrade GitPython", shell=True)
  626 + usermode = '--user' if WITH_DOCKER else ''
  627 + process = subprocess.Popen(pip + f" install {usermode} --upgrade GitPython", shell=True)
630 628 process.wait()
  629 + # if run ok
631 630 if process.returncode == 0:
632 631 # self.addExecuted(self.current_command, command)
633 632 from git import Repo
... ... @@ -645,14 +644,16 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat
645 644 change_dir("PREVIOUS")
646 645 '''
647 646  
  647 + #
648 648 # Guitastro
  649 + #
649 650 GUITASTRO_PATH = os.path.join(os.getcwd(), "./vendor/guitastro")
650   - if with_packages and not WITH_DOCKER :
  651 + if with_packages: # and not WITH_DOCKER:
651 652 #GUITASTRO_PATH = os.path.join(os.getcwd(), "../vendor/guitastro")
652 653 change_dir("..")
653 654 print(os.getcwd())
654 655 # 1) clone repo if not yet done
655   - if not os.path.exists(GUITASTRO_PATH) and not WITH_DOCKER :
  656 + if not WITH_DOCKER and not os.path.exists(GUITASTRO_PATH):
656 657 print("Guitastro : Cloning repository")
657 658 cloned_repo = Repo.clone_from(
658 659 "https://gitlab.irap.omp.eu/guitastrolib/guitastro.git", GUITASTRO_PATH)
... ... @@ -661,7 +662,7 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat
661 662 gitpull_guitastro()
662 663 change_dir("PREVIOUS")
663 664 # 2) install/update requirements & generate API doc
664   - if os.path.exists(GUITASTRO_PATH) and not WITH_DOCKER:
  665 + if not WITH_DOCKER and os.path.exists(GUITASTRO_PATH):
665 666 # TODO: update guitastro (git pull from vendor/guitastro/)
666 667 print("\nGuitastro : Installing/Updating python package dependencies\n")
667 668 # Upgrade pip if new version available
... ... @@ -703,9 +704,8 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat
703 704 _updatedb() or die()
704 705 else:
705 706 res = install_database(VENV)
706   - if(res == 0):
707   - print(
708   - f"You can connect to PyROS as '{SQL_USER}' user with the password '{SQL_PSWD}' ")
  707 + if (res == 0):
  708 + print(f"You can connect to PyROS as '{SQL_USER}' user with the password '{SQL_PSWD}' ")
709 709 return True
710 710  
711 711  
... ... @@ -789,8 +789,7 @@ def gitpull_guitastro():
789 789 change_dir("./vendor/guitastro/")
790 790 GIT = "git.exe" if IS_WINDOWS else "git"
791 791 if not test_mode():
792   - return execProcess(f"{GIT} pull",foreground=True)
793   -
  792 + return execProcess(f"{GIT} pull", foreground=True)
794 793 return True
795 794  
796 795  
... ... @@ -816,21 +815,24 @@ def initdb():
816 815 return True
817 816  
818 817  
819   -
820   -@pyros_launcher.command(help="Install dependencies")
  818 +@pyros_launcher.command(help="Install dependencies from Observatory config DEPENDENCY section")
821 819 # @global_test_options
822   -@click.option('--observatory', '-o', help='the observatory name to be used')
823   -@click.option('--unit', '-u', help='the unit name to be used')
  820 +@click.option('--observatory', '-o', help='the Observatory name to be used')
  821 +@click.option('--unit', '-u', help='the Unit name to be used')
824 822 @click.option("--foreground","-fg", is_flag=True, help="Print stdout and error in terminal")
825 823 def install_dependencies(observatory: str, unit: str, foreground: bool):
826   - if observatory == None or len(observatory) == 0:
  824 + if (observatory is None) or (len(observatory) == 0):
827 825 observatory = "default"
828 826 default_obsconfig_folder = os.path.join(
829   - os.path.abspath(PYROS_DJANGO_BASE_DIR), "../../../config/pyros_observatory/")
  827 + os.path.abspath(PYROS_DJANGO_BASE_DIR),
  828 + "../../../config/pyros_observatory/"
  829 + )
830 830 path_to_obs_config_folder = default_obsconfig_folder+"pyros_observatory_"+observatory+"/"
831 831 else:
832 832 observatories_configuration_folder = os.path.join(
833   - os.path.abspath(PYROS_DJANGO_BASE_DIR), "../../../../PYROS_OBSERVATORY/")
  833 + os.path.abspath(PYROS_DJANGO_BASE_DIR),
  834 + "../../../../PYROS_OBSERVATORY/"
  835 + )
834 836 if len(glob.glob(observatories_configuration_folder+"pyros_observatory_"+observatory+"/")) != 1:
835 837 # Observatory configuration folder not found
836 838 print(
... ... @@ -845,15 +847,14 @@ def install_dependencies(observatory: str, unit: str, foreground: bool):
845 847 # Search for observatory config file
846 848 obs_config_file_name = glob.glob(os.path.join(path_to_obs_config_folder, "observatory.yml"))[0]
847 849  
848   - obs_config_file_path = os.path.join(
849   - path_to_obs_config_folder, obs_config_file_name)
  850 + obs_config_file_path = os.path.join(path_to_obs_config_folder, obs_config_file_name)
850 851 os.environ["PATH_TO_OBSCONF_FILE"] = obs_config_file_path
851 852 os.environ["PATH_TO_OBSCONF_FOLDER"] = path_to_obs_config_folder
852 853 os.environ["unit_name"] = unit if unit else ''
853 854  
854 855 # add path to pyros_django folder as the config class is supposed to work within this folder
855 856 cmd_test_obs_config = f"-c \"from src.core.pyros_django.obs_config.obsconfig_class import OBSConfig\nOBSConfig('{obs_config_file_path}')\""
856   - if not execProcessFromVenv(cmd_test_obs_config,foreground=True):
  857 + if not execProcessFromVenv(cmd_test_obs_config, foreground=True):
857 858 # Observatory configuration has an issue
858 859 exit(1)
859 860 else:
... ... @@ -862,12 +863,8 @@ def install_dependencies(observatory: str, unit: str, foreground: bool):
862 863 from git import Repo, GitError
863 864 except:
864 865 pip = "pip" if IS_WINDOWS else "pip3"
865   - if WITH_DOCKER:
866   - process = subprocess.Popen(
867   - pip + " install --user --upgrade GitPython", shell=True)
868   - else:
869   - process = subprocess.Popen(
870   - pip + " install --upgrade GitPython", shell=True)
  866 + usermode = '--user' if WITH_DOCKER else ''
  867 + process = subprocess.Popen(pip + f" install {usermode} --upgrade GitPython", shell=True)
871 868 process.wait()
872 869 if process.returncode == 0:
873 870 # self.addExecuted(self.current_command, command)
... ...