# Change pip's cache directory to be inside the project directory since we can # only cache local items. variables: PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" # Pip's cache doesn't store the python packages # https://pip.pypa.io/en/stable/reference/pip_install/#caching # # If you want to also cache the installed packages, you have to install # them in a virtualenv and cache it as well. cache: paths: - .cache/pip - venv/ before_script: # Provides credentials to pip to access private GitLab PyPi index. - echo "machine gitlab.pik-potsdam.de" > ~/.netrc - echo "login gitlab-ci-token" >> ~/.netrc - echo "password ${CI_JOB_TOKEN}" >> ~/.netrc stages: - build - test - deploy build-job: stage: build image: python:3.10.6 script: - python -V - pip install virtualenv - virtualenv venv - source venv/bin/activate - pwd - ls -lisah - git config --global url."https://gitlab.pik-potsdam.de/".insteadOf "ssh://git@gitlab.pik-potsdam.de/" - pip install -r requirements.txt - pip install -r requirements_dev.txt test-job1: stage: test image: python:3.10.6 script: - source venv/bin/activate - flake8 --config .flake8 test-job2: stage: test image: python:3.10.6 script: - source venv/bin/activate - which python - pip freeze - python -m mypy --config-file=pyproject.toml server deploy-to-production: stage: deploy tags: - vm,bare-metal script: - echo "Current working directory and user" - pwd - whoami - groups - echo $HOME - echo "Reset git config" - rm /home/gitlab-runner/.gitconfig - git config --global url."https://gitlab.pik-potsdam.de/".insteadOf "ssh://git@gitlab.pik-potsdam.de/" - git config --global user.name gitlab-runner - git config --global user.email gitlab-runner@gitlab.pik-potsdam.de - git config --global -l --show-origin - echo "Go to deployment location" - cd /var/www/nacsos2/nacsos-core - ls -lisah - sudo chown -R gitlab-runner:gitlab-runner /var/www/nacsos2/nacsos-core - ls -lisah - echo "Stopping NACSOS-core service" - sudo systemctl stop nacsos-core.service - echo "Dropping virtual environment" - rm -rf venv - echo "Fetching updated source" - git stash # "reset" softly by stashing (in case files changed) - git pull origin production # pull from origin (production branch) - echo "Creating new virtual environment" - python3.10 -m venv venv - source venv/bin/activate - which python - python -V - echo "Installing requirements" - pip install -r requirements.txt - echo "Handling migrations" - nacsos_migrate upgrade --revision head --root-path=/var/www/nacsos2/nacsos-core/venv/lib/python3.10/site-packages/nacsos_data --ini-file=/var/www/nacsos2/nacsos-core/config/alembic.ini - sudo chown -R nacsos:nacsos /var/www/nacsos2/nacsos-core - echo "Starting NACSOS-core service" - sudo systemctl start nacsos-core.service when: manual only: - production