Skip to content
Snippets Groups Projects
.gitlab-ci.yml 3.22 KiB
# 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

image: python:3.12

build-job:
  stage: build
  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 setuptools
    - pip install -r requirements.txt
    - pip install -r requirements_dev.txt

test-job1:
  stage: test
  script:
    - source venv/bin/activate
    - flake8 --config .flake8

test-job2:
  stage: test
  script:
    - source venv/bin/activate
    - which python
    - pip freeze
    - python -m mypy --config-file=pyproject.toml server --show-traceback --no-incremental

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 -f /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