.gitlab-ci.yml 4.99 KB
Newer Older
Markus Scheidgen's avatar
Markus Scheidgen committed
1
# default installed image for docker executor is: python:3.6
2
# using an image that can do git, docker, docker-compose
3
image: youpy/docker-compose-git
4
5
6
7
8

# Uncomment the next lines, to run each pipline/job in its own docker environment.
# Otherwise, it will use the docker of the gitlab runner host (e.g. enc-preprocessing...).
# This will give it access to a persitent layer cache, which will not be available
# with the docker service.
9
10
# services:
#   - docker:dind
Markus Scheidgen's avatar
Markus Scheidgen committed
11
12

stages:
Markus Scheidgen's avatar
Markus Scheidgen committed
13
  - build
14
  - test
15
  - integration
16
  - release
17
  - deploy
18

19
variables:
Markus Scheidgen's avatar
Markus Scheidgen committed
20
21
22
23
24
25
  TEST_IMAGE: gitlab-registry.mpcdf.mpg.de/nomad-lab/nomad-fair:test_${CI_COMMIT_REF_NAME}
  RELEASE_IMAGE: gitlab-registry.mpcdf.mpg.de/nomad-lab/nomad-fair:${CI_COMMIT_REF_NAME}
  LATEST_IMAGE: gitlab-registry.mpcdf.mpg.de/nomad-lab/nomad-fair:latest
  FRONTEND_TEST_IMAGE: gitlab-registry.mpcdf.mpg.de/nomad-lab/nomad-fair/frontend:test_${CI_COMMIT_REF_NAME}
  FRONTEND_RELEASE_IMAGE: gitlab-registry.mpcdf.mpg.de/nomad-lab/nomad-fair/frontend:${CI_COMMIT_REF_NAME}
  FRONTEND_LATEST_IMAGE: gitlab-registry.mpcdf.mpg.de/nomad-lab/nomad-fair/frontend:latest
26
27
  KUBECONFIG: /etc/deploy/config

Markus Scheidgen's avatar
Markus Scheidgen committed
28
29
build:
  stage: build
30
31
  before_script:
    - git submodule sync
32
    - git submodule update --init
33
    - ./gitinfo.sh
Markus Scheidgen's avatar
Markus Scheidgen committed
34
  script:
35
36
    # ignore test directories of dependencies, there is a lot of data that we not use
    # in the context of the docker image
37
    - find dependencies -name "*test*" -type d -exec echo "{}/" \;  >> .dockerignore
38
    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN gitlab-registry.mpcdf.mpg.de
39
    - docker build -t $TEST_IMAGE .
Markus Scheidgen's avatar
Markus Scheidgen committed
40
    - docker push $TEST_IMAGE
41
42
  except:
    - /^dev-.*$/
Markus Scheidgen's avatar
Markus Scheidgen committed
43
    - tags
44

Markus Scheidgen's avatar
Markus Scheidgen committed
45
46
47
48
49

buildgui:
  stage: build
  script:
    - cd gui
50
    - ./version.sh
Markus Scheidgen's avatar
Markus Scheidgen committed
51
    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN gitlab-registry.mpcdf.mpg.de
52
    - docker build -t $FRONTEND_TEST_IMAGE .
Markus Scheidgen's avatar
Markus Scheidgen committed
53
    - docker push $FRONTEND_TEST_IMAGE
54
55
  except:
    - /^dev-.*$/
Markus Scheidgen's avatar
Markus Scheidgen committed
56
    - tags
57

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
linting:
  stage: test
  image: $TEST_IMAGE
  script:
    - cd /app
    - python -m pycodestyle --ignore=E501,E701 nomad tests
    - python -m pylint --load-plugins=pylint_mongoengine nomad tests
    - python -m mypy --ignore-missing-imports --follow-imports=silent --no-strict-optional nomad tests
  except:
    refs:
      - tags
    variables:
      - $CI_COMMIT_REF_NAME =~ /^dev-.*$/
      - $CI_COMMIT_MESSAGE =~ /\[skip[ _-]tests?\]/i

73
tests:
Markus Scheidgen's avatar
Markus Scheidgen committed
74
  stage: test
Markus Scheidgen's avatar
Markus Scheidgen committed
75
  image: $TEST_IMAGE
76
  services:
77
    - postgres:latest
78
79
80
81
82
83
84
85
86
87
      # this will cause a warning, as the gitlab ci runner health check will test the wrong
      # port on rabbitmq container:
      # https://gitlab.com/gitlab-org/gitlab-runner/issues/3163
    - rabbitmq
    - name: docker.elastic.co/elasticsearch/elasticsearch:6.3.2
      alias: elastic
      # fix issue with running elastic in gitlab ci runner:
      # https://gitlab.com/gitlab-org/gitlab-ce/issues/42214
      command: [ "bin/elasticsearch", "-Ediscovery.type=single-node" ]
  variables:
88
89
90
    POSTGRES_DB: nomad
    POSTGRES_USER: postgres
    POSTGRES_PASSWORD: nomad
91
92
93
94
    RABBITMQ_ERLANG_COOKIE: SWQOKODSQALRPCLNMEQG
    RABBITMQ_DEFAULT_USER: rabbitmq
    RABBITMQ_DEFAULT_PASS: rabbitmq
    RABBITMQ_DEFAULT_VHOST: /
95
    NOMAD_REPOSITORY_DB_HOST: postgres
96
97
98
    NOMAD_RABBITMQ_HOST: rabbitmq
    NOMAD_ELASTIC_HOST: elastic
    NOMAD_MONGO_HOST: mongo
Markus Scheidgen's avatar
Markus Scheidgen committed
99
  script:
100
    - cd /app
Markus Scheidgen's avatar
Markus Scheidgen committed
101
    - python -m pytest --cov=nomad -sv tests
102
  except:
Markus Scheidgen's avatar
Markus Scheidgen committed
103
104
    refs:
      - tags
105
106
    variables:
      - $CI_COMMIT_REF_NAME =~ /^dev-.*$/
107
      - $CI_COMMIT_MESSAGE =~ /\[skip[ _-]tests?\]/i
108

109
110
111
112
release:
  stage: release
  script:
    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN gitlab-registry.mpcdf.mpg.de
Markus Scheidgen's avatar
Markus Scheidgen committed
113
    - docker pull $TEST_IMAGE
Markus Scheidgen's avatar
Markus Scheidgen committed
114
115
116
117
118
119
120
121
122
123
124
125
126
    - docker tag $TEST_IMAGE $LATEST_IMAGE
    - docker push $LATEST_IMAGE
    - docker pull $FRONTEND_TEST_IMAGE
    - docker tag $FRONTEND_TEST_IMAGE $FRONTEND_LATEST_IMAGE
    - docker push $FRONTEND_LATEST_IMAGE
  except:
    - /^dev-.*$/
  when: manual

release_version:
  stage: release
  script:
    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN gitlab-registry.mpcdf.mpg.de
Markus Scheidgen's avatar
Markus Scheidgen committed
127
128
    - docker pull $LATEST_IMAGE
    - docker tag $LATEST_IMAGE $RELEASE_IMAGE
Markus Scheidgen's avatar
Markus Scheidgen committed
129
    - docker push $RELEASE_IMAGE
Markus Scheidgen's avatar
Markus Scheidgen committed
130
131
    - docker pull $FRONTEND_LATEST_IMAGE
    - docker tag $FRONTEND_LATEST_IMAGE $FRONTEND_RELEASE_IMAGE
Markus Scheidgen's avatar
Markus Scheidgen committed
132
    - docker push $FRONTEND_RELEASE_IMAGE
Markus Scheidgen's avatar
Markus Scheidgen committed
133
134
  only:
    - tags
135

136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
## TODO This has to be fixed, we need one for testing, staging, production
# deploy_coe_staging:
#   stage: deploy
#   image: dtzar/helm-kubectl
#   before_script:
#     - mkdir -p /etc/deploy
#     # kube_config is a CI/CD variable set in GitLab GUI
#     - echo $CI_KUBE_CONFIG | base64 -d > /etc/deploy/config
#     - helm init --upgrade
#     - helm repo add stable https://kubernetes-charts.storage.googleapis.com/
#     - helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
#     - helm repo update
#   script:
#     - cd ops/helm/nomad
#     - export KUBECONFIG=/etc/deploy/config
#     - helm dep build
#     - helm upgrade nomad-coe-staging . --recreate-pods;
#   except:
#     - /^dev-.*$/
#   when: manual