.gitlab-ci.yml 6.47 KB
Newer Older
1

2
3
4
5
6
stages:
  - test
  - test_build_static
  - build_docker_images
  - deploy
Andrey Azov's avatar
Andrey Azov committed
7

8
9
variables:
  CONTAINER_IMAGE: $GITLAB_REGISTRY_URL/$GITLAB_REGISTRY_NAMESPACE/ensembl-client:${CI_COMMIT_SHORT_SHA}
10
  CONTAINER_INTERNAL_IMAGE: $GITLAB_REGISTRY_URL/$GITLAB_REGISTRY_NAMESPACE/ensembl-client:${CI_COMMIT_SHORT_SHA}-internal
11
12
13
  KUBECONFIG: /etc/deploy/config
  KUBECONTEXT: ens-dev-ctx
  DEPLOYENV: dev
14
  ENVIRONMENT: production
Andrey Azov's avatar
Andrey Azov committed
15

16
Test:
17
  image: node:10.16.0
18
  stage: test
Andrey Azov's avatar
Andrey Azov committed
19

20
21
22
23
24
25
26
27
28
29
30
  before_script:
  - cd src/ensembl
  - npm ci

  script:
  - npm run test

  except:
  - dev
  - master

31
Test_N_Build:
32
  image: node:10.16.0
33
34
35
36
37
38
39
40
41
  stage: test_build_static

  before_script:
  - cd src/ensembl
  - npm ci

  script:
  - npm run test
  - export NODE_ENV=production
42
43
44
  - export GOOGLE_ANALYTICS_KEY=${GA_KEY}
  - export ENVIRONMENT=production
  - export API_HOST=""
45
46
47
48
49
50
51
52
53
54
55
  - npm run build

  artifacts:
    name: static_assets
    paths:
    - src/ensembl/dist/

  only:
  - dev
  - master

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
Test_N_Build:internal:
  image: node:10.16.0
  stage: test_build_static

  before_script:
  - cd src/ensembl
  - npm ci

  script:
  - npm run test
  - export NODE_ENV=development
  - export GOOGLE_ANALYTICS_KEY=${GA_KEY}
  - export ENVIRONMENT=internal
  - export API_HOST=""
  - npm run build

  artifacts:
    name: static_assets_internal
    paths:
    - src/ensembl/dist/

  only:
  - master

80
81
Nginx:
  image: docker
82

83
84
  services:
    - docker:dind
85

86
87
88
  stage: build_docker_images

  before_script:
89
  - case "${CI_COMMIT_REF_NAME}" in dev) DEPLOYENV="staging" ;; master) DEPLOYENV="prod" ;; cicd-test) DEPLOYENV="staging" ;; *) DEPLOYENV="dev" ;; esac
90
91
92
93

  script:
  - apk update && apk add git
  - git clone --depth 1 https://github.com/Ensembl/ensembl-2020-static-assests.git
94
  - git clone https://gitlab.ebi.ac.uk/kamal/ensembl-client-nginx.git
95
96
97
  - cd ensembl-client-nginx
  - git checkout june-release
  - cd ..
98
  - sed -i "s/<DEPLOYMENT_ENV>/${DEPLOYENV}/g" ensembl-client-nginx/config/conf.d/local.conf
99
100
101
102
103
104
105
106
107
108
  - docker build -t ${CONTAINER_IMAGE} -f ensembl-client-nginx/Dockerfile --no-cache .
  - echo "$GITLAB_REGISTRY_TOKEN" | docker login -u "$GITLAB_REGISTRY_USER" --password-stdin https://"$GITLAB_REGISTRY_URL"
  - docker push ${CONTAINER_IMAGE}
  - docker rmi ${CONTAINER_IMAGE}
  - docker logout "$GITLAB_REGISTRY_URL"

  only:
  - dev
  - master

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
  dependencies:
  - Test_N_Build

Nginx:internal:
  image: docker

  services:
    - docker:dind

  stage: build_docker_images

  before_script:
  - case "${CI_COMMIT_REF_NAME}" in dev) DEPLOYENV="staging" ;; master) DEPLOYENV="prod" ;; cicd-test) DEPLOYENV="staging" ;; *) DEPLOYENV="dev" ;; esac

  script:
  - apk update && apk add git
  - git clone --depth 1 https://github.com/Ensembl/ensembl-2020-static-assests.git
  - git clone https://gitlab.ebi.ac.uk/kamal/ensembl-client-nginx.git
  - cd ensembl-client-nginx
  - git checkout june-release
  - cd ..
  - sed -i "s/<DEPLOYMENT_ENV>/internal/g" ensembl-client-nginx/config/conf.d/local.conf
  - cat ensembl-client-nginx/config/conf.d/local.conf
  - docker build -t ${CONTAINER_INTERNAL_IMAGE} -f ensembl-client-nginx/Dockerfile --no-cache .
  - echo "$GITLAB_REGISTRY_TOKEN" | docker login -u "$GITLAB_REGISTRY_USER" --password-stdin https://"$GITLAB_REGISTRY_URL"
134
135
  - docker push ${CONTAINER_IMAGE}-internal
  - docker rmi ${CONTAINER_IMAGE}-internal
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
  - docker logout "$GITLAB_REGISTRY_URL"

  only:
  - master

  dependencies:
  - Test_N_Build:internal

Deploy:internal:
  stage: deploy
  image: alpine
  before_script:
  - mkdir -p /etc/deploy
  - echo ${EMBASSY_KUBECONFIG} | base64 -d > ${KUBECONFIG}

  script:
  - apk update && apk add --no-cache curl git
  - curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
  - chmod +x ./kubectl
  - mv ./kubectl /usr/local/bin/kubectl
  - git clone https://gitlab.ebi.ac.uk/kamal/ensembl-client-caas-deploy.git
  - cd ensembl-client-caas-deploy
  - git checkout refactor-manifest
  - cd ..
  - sed -i "s/<VERSION>/${CI_COMMIT_SHORT_SHA}-internal/g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml
  - sed -i "s/<DEPLOYMNET_ENV>/internal/g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml
  - cat ensembl-client-caas-deploy/ensembl_client_deployment.yaml
  - kubectl config view
  - kubectl config use-context ens-dev-ctx
  - kubectl apply -f ensembl-client-caas-deploy/ensembl_client_deployment.yaml

  only:
  - master

  dependencies:
  - Nginx:internal

173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
Staging:
  stage: deploy
  image: alpine
  before_script:
  - mkdir -p /etc/deploy
  - echo ${EMBASSY_KUBECONFIG} | base64 -d > ${KUBECONFIG}
  script:
  - apk update && apk add --no-cache curl git
  - curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
  - chmod +x ./kubectl
  - mv ./kubectl /usr/local/bin/kubectl
  - git clone https://gitlab.ebi.ac.uk/kamal/ensembl-client-caas-deploy.git
  - cd ensembl-client-caas-deploy
  - git checkout refactor-manifest
  - cd ..
  - sed -i "s/<VERSION>/${CI_COMMIT_SHORT_SHA}/g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml
  - sed -i "s/<DEPLOYMNET_ENV>/staging/g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml
  - cat ensembl-client-caas-deploy/ensembl_client_deployment.yaml
  - kubectl config view
  - kubectl config use-context ens-stage-ctx
  - kubectl apply -f ensembl-client-caas-deploy/ensembl_client_deployment.yaml
194

195
196
197
  only:
  - dev

198
199
200
  dependencies:
  - Nginx

201
202
203
204
205
206
Live:
  stage: deploy
  image: alpine
  before_script:
  - mkdir -p /etc/deploy
  - echo ${EMBASSY_KUBECONFIG} | base64 -d > ${KUBECONFIG}
Andrey Azov's avatar
Andrey Azov committed
207
  script:
208
209
210
211
212
213
214
215
216
217
218
219
220
221
  - apk update && apk add --no-cache curl git
  - curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
  - chmod +x ./kubectl
  - mv ./kubectl /usr/local/bin/kubectl
  - git clone https://gitlab.ebi.ac.uk/kamal/ensembl-client-caas-deploy.git
  - cd ensembl-client-caas-deploy
  - git checkout refactor-manifest
  - cd ..
  - sed -i "s/<VERSION>/${CI_COMMIT_SHORT_SHA}/g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml
  - sed -i "s/<DEPLOYMNET_ENV>/prod/g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml
  - cat ensembl-client-caas-deploy/ensembl_client_deployment.yaml
  - kubectl config view
  - kubectl config use-context ens-prod-ctx
  - kubectl apply -f ensembl-client-caas-deploy/ensembl_client_deployment.yaml
222

223
224
  only:
  - master
225
226
227

  dependencies:
  - Nginx