.gitlab-ci.yml 2.77 KB
Newer Older
1 2 3 4
---
image: docker:latest

variables:
Duncan Macleod's avatar
Duncan Macleod committed
5
  APT_CACHE_DIR: "${CI_PROJECT_DIR}/.cache/apt"
6 7 8
  DOCKER_DRIVER: overlay
  DOCKER_BRANCH: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
  DOCKER_LATEST: $CI_REGISTRY_IMAGE:latest
Duncan Macleod's avatar
Duncan Macleod committed
9
  PIP_CACHE_DIR: "${CI_PROJECT_DIR}/.cache/pip"
10 11

stages:
12
  - test
13 14 15
  - branch
  - latest

16 17 18
before_script:
  - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
.test: &test
  image: ligo/base:stretch
  services:
    - mysql:5.5
  variables:
    AWS_SES_ACCESS_KEY_ID: "fake_aws_id"
    AWS_SES_SECRET_ACCESS_KEY: "fake_aws_key"
    DJANGO_ALERT_EMAIL_FROM: "fake_email"
    DJANGO_DB_HOST: "mysql"
    DJANGO_DB_PORT: "3306"
    DJANGO_DB_NAME: "fake_name"
    DJANGO_DB_USER: "root"
    DJANGO_DB_PASSWORD: "fake_password"
    DJANGO_PRIMARY_FQDN: "fake_fqdn"
    DJANGO_SECRET_KEY: "fake_key"
    DJANGO_SETTINGS_MODULE: "config.settings.container.dev"
    DJANGO_TWILIO_ACCOUNT_SID: "fake_sid"
    DJANGO_TWILIO_AUTH_TOKEN: "fake_token"
    LVALERT_OVERSEER_PORT: "2"
    LVALERT_SERVER: "fake_server"
    LVALERT_USER: "fake_user"
    LVALERT_PASSWORD: "fake_password"
    MYSQL_DB: "${DJANGO_DB_NAME}"
    MYSQL_ROOT_PASSWORD: "${DJANGO_DB_PASSWORD}"
  before_script:
Duncan Macleod's avatar
Duncan Macleod committed
44 45
    # create apt cache directory
    - mkdir -pv ${APT_CACHE_DIR}
46 47 48 49 50 51
    # set python version
    - PYTHON_VERSION="${CI_JOB_NAME##*:}"
    - PYTHON_MAJOR="${PYTHON_VERSION:0:1}"
    - if [[ "${PYTHON_MAJOR}" -eq 2 ]]; then PYTHON="python"; else PYTHON="python3"; fi
    # install build requirements
    - apt-get -yqq update
Duncan Macleod's avatar
Duncan Macleod committed
52
    - apt-get -o dir::cache::archives="${APT_CACHE_DIR}" install -yqq
53 54 55 56 57 58 59 60 61
          git
          libmariadbclient-dev
          libldap2-dev
          libsasl2-dev
          libssl-dev
          libxml2-dev
          swig
          ${PYTHON}-pip
    # install voeventlib for python2
Duncan Macleod's avatar
Duncan Macleod committed
62
    - if [[ "${PYTHON_MAJOR}" -eq 2 ]]; then apt-get -o dir::cache::archives="${APT_CACHE_DIR}" install -yqq python-voeventlib; fi
63 64 65 66 67 68 69
    # install everything else from pip
    - ${PYTHON} -m pip install -r requirements.txt
    # create logs path required for tests
    - mkdir -pv ../logs/
    # list packages
    - ${PYTHON} -m pip list installed
  script:
70
    - PYTHONPATH=${PYTHONPATH}:${PWD}/gracedb ${PYTHON} -m pytest --cov ./gracedb --junitxml=${CI_PROJECT_DIR}/junit.xml
71 72 73 74 75 76
  after_script:
    - rm -fvr ${PIP_CACHE_DIR}/log
  artifacts:
    reports:
      junit: junit.xml
  cache:
Duncan Macleod's avatar
Duncan Macleod committed
77
    key: "${CI_JOB_NAME}"
78 79
    paths:
      - .cache/pip
Duncan Macleod's avatar
Duncan Macleod committed
80
      - .cache/apt
81 82 83 84 85 86 87 88

test:2.7:
  <<: *test

test:3.7:
  <<: *test
  allow_failure: true

89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
branch_image:
  stage: branch
  script:
    - docker build --pull -t $DOCKER_BRANCH .
    - docker push $DOCKER_BRANCH

latest_image:
  stage: latest
  dependencies:
    - branch_image
  only:
    refs:
      - master
  script:
    - docker tag $DOCKER_BRANCH $DOCKER_LATEST
    - docker push $DOCKER_LATEST