-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
153 lines (135 loc) · 4.16 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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
# Stages for the CI/CD job
stages:
- test
- build
- deploy
# GitLab Dependency Proxy to get rid of Docker hub pull limit issue
# https://docs.gitlab.com/ee/user/packages/dependency_proxy/#authenticate-within-cicd
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/python:3.10.14
# This fixes "error during connect: Post http://docker:2375/v1.40/auth: dial tcp: lookup docker on 192.168.65.5:53: no such host"
variables:
# Environment Variable for docker:dind service explaining to use overlay2 as supporting driver for docker
# https://docs.docker.com/storage/storagedriver/overlayfs-driver/
DOCKER_DRIVER: overlay2
# We need to disable TLS (https://about.gitlab.com/blog/2019/07/31/docker-in-docker-with-docker-19-dot-03/#disable-tls)
# to fix the error "docker: Cannot connect to the Docker daemon at tcp://docker:2375. Is the docker daemon running?"
DOCKER_TLS_CERTDIR: ""
DOCKER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}
BASE: k8s/web-prod/base
# Template to build docker image
.build:
stage: build
image: docker
services:
- docker:dind
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker build -t ${DOCKER_IMAGE} --no-cache -f Dockerfile .
- docker push ${DOCKER_IMAGE}
# remove local image from shared runner
- docker rmi ${DOCKER_IMAGE}
- docker logout $CI_REGISTRY
# Template to deploy application to k8s cluster
# At the moment, possible values for ${CI_PROJECT_NAMESPACE} are 'ensembl-apps' or 'ensembl-web'
.deploy:
stage: deploy
image: dockerhub.ebi.ac.uk/${CI_PROJECT_NAMESPACE}/deploy-tools:latest
script:
- cd ${BASE}
- kustomize edit set image DOCKER_IMAGE=${DOCKER_IMAGE}
- kustomize build . | kubectl apply -f -
# Run a suite of unit and integration tests
test:
stage: test
before_script:
- pip3 install -r requirements-dev.txt
- export META_CLASSIFIER_PATH=$PWD/docs/metadata_classifiers/
script:
- pylint $(git ls-files '*.py') --fail-under=9.5
- mypy graphql_service
- pytest
# Build docker image for k8s-deploy branch
build:
extends: .build
rules:
- if: '$CI_COMMIT_BRANCH == "develop" || $CI_COMMIT_BRANCH == "main"'
# Template to deploy application to web's k8s cluster
.deploy-web:
extends: .deploy
before_script:
- kubectl config use-context ${AGENT}
- kubectl config set-context --current --namespace=${NAMESPACE}
rules:
- if: '$CI_DEPLOY_FREEZE == null && $CI_COMMIT_BRANCH == "main" && $CI_PROJECT_NAMESPACE== "ensembl-web"'
# Template to deploy application to apps k8s cluster
.deploy-apps:
extends: .deploy
variables:
BASE: k8s/web-prod/overlays/apps
rules:
- if: '$CI_DEPLOY_FREEZE == null && $CI_COMMIT_BRANCH == "develop" && $CI_PROJECT_NAMESPACE== "ensembl-apps"'
# deploy to staging at WP-HH
Staging:
extends: .deploy-web
variables:
BASE: k8s/web-prod/overlays/staging
AGENT: ${STAGING_AGENT}
NAMESPACE: ${STAGING_NS}
environment:
name: staging
# deploy to internal at WP-HH
Internal:
extends: .deploy-web
variables:
BASE: k8s/web-prod/overlays/internal
AGENT: ${INTERNAL_AGENT}
NAMESPACE: ${INTERNAL_NS}
environment:
name: internal
# deploy to live at WP-HX
Live:Fallback:
extends: .deploy-web
variables:
BASE: k8s/web-prod/overlays/prod
AGENT: ${FALLBACK_AGENT}
NAMESPACE: ${FALLBACK_NS}
environment:
name : fallback
# deploy to live at WP-HL
Live:
extends: .deploy-web
variables:
BASE: k8s/web-prod/overlays/prod
AGENT: ${PROD_AGENT}
NAMESPACE: ${PROD_NS}
environment:
name : production
# deploy to live at WP-HL
dev:wp-hl:
extends: .deploy-web
variables:
BASE: k8s/web-prod/overlays/dev
environment:
name : development
Public:
extends: .deploy-web
variables:
BASE: k8s/web-prod/overlays/public-graphql
AGENT: ${PUBLIC_AGENT}
NAMESPACE: ${PUBLIC_NS}
environment:
name: public
Dev:
extends: .deploy-web
variables:
BASE: k8s/web-prod/overlays/dev
AGENT: ${DEV_AGENT}
NAMESPACE: ${DEV_NS}
environment:
name: development
# deploy application to k8s cluster for k8s-deploy branch
deploy:apps:
extends: .deploy-apps
environment:
name: thoas-graphql