.gitlab-ci.yml 2.74 KB
Newer Older
1 2 3
variables:
  POSTGRES_DB: xsacdb
  POSTGRES_USER: runner
4
  POSTGRES_PASSWORD: "runner-password"
Will Pimblett's avatar
Will Pimblett committed
5
  BSAC_DATA: "https://s3.amazonaws.com/xsacdb-bsac-data/bsac_data.yaml"
6
  DOCKER_DRIVER: overlay2
7

Will Pimblett's avatar
Will Pimblett committed
8
stages:
9
  - build
Will Pimblett's avatar
Will Pimblett committed
10
  - test
11
  - release
Will Pimblett's avatar
Will Pimblett committed
12

13
build:
Will Pimblett's avatar
Will Pimblett committed
14
  stage: build
15
  image: docker:19.03.1
Will Pimblett's avatar
Will Pimblett committed
16
  before_script:
17
    - apk add git
18
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
19
    - docker pull $CI_REGISTRY_IMAGE/ci:$CI_COMMIT_REF_SLUG || docker pull wjdp/xsacdb:next || true
20
  script:
21
    - git describe
22
    - docker build
23
        --cache-from $CI_REGISTRY_IMAGE/ci:$CI_COMMIT_REF_SLUG
24 25 26 27
        --cache-from docker.io/wjdp/xsacdb:next
        -t $CI_REGISTRY_IMAGE/ci:$CI_COMMIT_REF_SLUG
        --build-arg VCS_REV=$(git describe)
        .
28
    - docker push $CI_REGISTRY_IMAGE/ci:$CI_COMMIT_REF_SLUG
29

30
django-test:
31
  stage: test
32 33 34
  image: $CI_REGISTRY_IMAGE/ci:$CI_COMMIT_REF_SLUG
  variables:
    GIT_STRATEGY: none
Will Pimblett's avatar
Will Pimblett committed
35
    XSACDB_ENVIRONMENT: TEST
36
    XSACDB_XMLTESTRUNNER: 1
37 38 39
  services:
    - postgres:latest
    - redis:latest
Will Pimblett's avatar
Will Pimblett committed
40
  before_script:
41
    - cd /app
Will Pimblett's avatar
Will Pimblett committed
42 43
    - mkdir tmp
    - curl $BSAC_DATA > tmp/bsac_data.yaml
Tom Price's avatar
Tom Price committed
44
    - pip3 install coverage
45
  script:
46
    - src/manage.py check
Tom Price's avatar
Tom Price committed
47 48
    - coverage run --source='src' src/manage.py test xSACdb xsd_about xsd_auth xsd_frontend xsd_help xsd_kit xsd_members xsd_sites xsd_training xsd_trips
    - coverage report
49 50
  after_script:
    - mv /app/junit-django.xml $CI_PROJECT_DIR
Tom Price's avatar
Tom Price committed
51
  coverage: '/^TOTAL.+?(\d+\%)$/'
52 53 54 55 56
  artifacts:
    paths:
      - junit-django.xml
    reports:
      junit: junit-django.xml
57

Will Pimblett's avatar
Will Pimblett committed
58 59 60 61 62 63 64 65 66
eslint:
  stage: test
  image: $CI_REGISTRY_IMAGE/ci:$CI_COMMIT_REF_SLUG
  variables:
    GIT_STRATEGY: none
  before_script:
    - cd /app
  script:
    - npm run lint:junit
67 68
  after_script:
    - mv /app/junit-eslint.xml $CI_PROJECT_DIR
Will Pimblett's avatar
Will Pimblett committed
69 70 71 72 73 74
  artifacts:
    paths:
      - junit-eslint.xml
    reports:
      junit: junit-eslint.xml

75 76
release-next:
  stage: release
77 78 79
  image: docker:19.03.1
  variables:
    GIT_STRATEGY: none
80
  before_script:
81
    - docker pull $CI_REGISTRY_IMAGE/ci:$CI_COMMIT_REF_SLUG
82 83
    - docker login -u $DOCKER_HUB_USER -p $DOCKER_HUB_TOKEN
  script:
84
    - docker tag $CI_REGISTRY_IMAGE/ci:$CI_COMMIT_REF_SLUG wjdp/xsacdb:next
85 86 87
    - docker push wjdp/xsacdb:next
  only:
    - master
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
  except:
    - tags

release-tag:
  stage: release
  image: docker:19.03.1
  variables:
    GIT_STRATEGY: none
  before_script:
    - docker pull $CI_REGISTRY_IMAGE/ci:$CI_COMMIT_REF_SLUG
    - docker login -u $DOCKER_HUB_USER -p $DOCKER_HUB_TOKEN
  script:
    - docker tag $CI_REGISTRY_IMAGE/ci:$CI_COMMIT_REF_SLUG wjdp/xsacdb:latest
    - docker tag $CI_REGISTRY_IMAGE/ci:$CI_COMMIT_REF_SLUG wjdp/xsacdb:$CI_COMMIT_TAG
    - docker push wjdp/xsacdb:latest
    - docker push wjdp/xsacdb:$CI_COMMIT_TAG
  only:
    - /^v\d+[0-9A-z.-]+$/