.gitlab-ci.yml 6.45 KB
Newer Older
1
2
3
4
5
stages:
  - test
  - test_build_static
  - build_docker_images
  - deploy
Andrey Azov's avatar
Andrey Azov committed
6

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

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

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

  script:
  - npm run test

  except:
  - dev
  - master

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

  before_script:
  - cd src/ensembl
  - npm ci

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

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

  only:
  - dev
  - master

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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

79
80
Nginx:
  image: docker
81

82
83
  services:
    - docker:dind
84

85
86
87
  stage: build_docker_images

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

  script:
  - apk update && apk add git
  - git clone --depth 1 https://github.com/Ensembl/ensembl-2020-static-assests.git
93
  - git clone https://gitlab.ebi.ac.uk/kamal/ensembl-client-nginx.git
94
95
96
  - cd ensembl-client-nginx
  - git checkout june-release
  - cd ..
97
  - sed -i "s/<DEPLOYMENT_ENV>/${DEPLOYENV}/g" ensembl-client-nginx/config/conf.d/local.conf
98
99
100
101
102
103
104
105
106
107
  - 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

108
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
134
135
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
  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"
  - docker push ${CONTAINER_IMAGE}
  - docker rmi ${CONTAINER_IMAGE}
  - 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

172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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
193

194
195
196
  only:
  - dev

197
198
199
  dependencies:
  - Nginx

200
201
202
203
204
205
Live:
  stage: deploy
  image: alpine
  before_script:
  - mkdir -p /etc/deploy
  - echo ${EMBASSY_KUBECONFIG} | base64 -d > ${KUBECONFIG}
Andrey Azov's avatar
Andrey Azov committed
206
  script:
207
208
209
210
211
212
213
214
215
216
217
218
219
220
  - 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
221

222
223
  only:
  - master
224
225
226

  dependencies:
  - Nginx