# 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/ stages: - build - test - deploy build-job: stage: build image: python:latest script: - python -V - pip install virtualenv - virtualenv venv - source venv/bin/activate - pwd - ls -lisah - git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@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:latest script: - source venv/bin/activate - flake8 --config .flake8 test-job2: stage: test image: python:latest script: - source venv/bin/activate - mypy --config-file=pyproject.toml server deploy-to-production: stage: deploy tags: - bare-metal script: # - echo "Run as nacsos user" # - sudo -u nacsos bash ./deploy.sh $CI_JOB_TOKEN - echo "Current working directory and user" - pwd - whoami - groups # - echo "Becoming 'nacsos' user" # - sudo -u nacsos -s - echo "Go to deployment location" - cd /home/nacsos/nacsos-core - ls -lisah - sudo chown -R gitlab-runner /home/nacsos/nacsos-core - sudo chgrp -R gitlab-runner /home/nacsos/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" - echo "Token: ${CI_JOB_TOKEN}" - git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.pik-potsdam.de/".insteadOf "ssh://git@gitlab.pik-potsdam.de/" - 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 - echo "Installing requirements" - pip install -r requirements.txt - echo "Handling migrations" - pip install alembic - cd /home/nacsos/nacsos-core/venv/src/nacsos-data/ - alembic upgrade head - sudo chown -R nacsos /home/nacsos/nacsos-core - sudo chgrp -R nacsos /home/nacsos/nacsos-core - echo "Starting NACSOS-core service" - sudo systemctl start nacsos-core.service when: manual only: - production