-
Notifications
You must be signed in to change notification settings - Fork 9
/
.gitlab-ci.yml
94 lines (86 loc) · 3.36 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
services:
- docker:19.03.13-dind
variables:
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: /certs
DOCKER_TLS_VERIFY: 1
DOCKER_CERT_PATH: $DOCKER_TLS_CERTDIR/client
FILEPATH_DEPLOY_BACKEND: infra/k8s/default/bt-backend.yaml
FILEPATH_DEPLOY_DATA: infra/k8s/default/bt-backend-data-updater.yaml
FILEPATH_DEPLOY_FRONTEND: infra/k8s/default/bt-frontend.yaml
FILEPATH_DEPLOY_INGRESS: infra/k8s/default/bt-ingress-tricycle.yaml
FILEPATH_LOCAL_DOCKER_COMPOSE_BACKEND: backend
FILEPATH_LOCAL_DOCKER_COMPOSE_FRONTEND: frontend
stages:
- build
- deploy-dev
- deploy-staging
- deploy-prod
.before_build:
before_script:
- until docker info; do sleep 1; done;
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- |
tag=":$CI_COMMIT_BRANCH"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
build-backend:
stage: build
image: docker:19.03.13-dind
extends: .before_build
script:
- docker build -t "${CI_REGISTRY_IMAGE}/bt-backend${tag}" $FILEPATH_LOCAL_DOCKER_COMPOSE_BACKEND
- docker push "${CI_REGISTRY_IMAGE}/bt-backend${tag}"
build-frontend:
stage: build
image: docker:19.03.13-dind
extends: .before_build
script:
- docker build -t "${CI_REGISTRY_IMAGE}/bt-frontend${tag}" $FILEPATH_LOCAL_DOCKER_COMPOSE_FRONTEND
- docker push "${CI_REGISTRY_IMAGE}/bt-frontend${tag}"
deploy-dev:
stage: deploy-dev
except:
refs:
- master
environment:
name: staging
image: $CI_SERVER_HOST:5000/berkeleytime/bt-gitlab-runner
script:
- npm --prefix infra/tricycle install && node infra/tricycle
- kubectl rollout restart deploy/bt-backend-dev-$CI_COMMIT_BRANCH
- kubectl rollout restart deploy/bt-frontend-dev-$CI_COMMIT_BRANCH
- kubectl rollout status --timeout=1200s deploy/bt-backend-dev-$CI_COMMIT_BRANCH
- kubectl rollout status --timeout=1200s deploy/bt-frontend-dev-$CI_COMMIT_BRANCH
deploy-staging:
stage: deploy-staging
only:
refs:
- master
environment:
name: staging
image: $CI_SERVER_HOST:5000/berkeleytime/bt-gitlab-runner
script:
- envsubst < $FILEPATH_DEPLOY_BACKEND | kubectl apply -f - --kubeconfig $SECRET_KUBERNETES_CREDENTIALS
- envsubst < $FILEPATH_DEPLOY_DATA | kubectl apply -f - --kubeconfig $SECRET_KUBERNETES_CREDENTIALS
- envsubst < $FILEPATH_DEPLOY_FRONTEND| kubectl apply -f - --kubeconfig $SECRET_KUBERNETES_CREDENTIALS
- kubectl rollout restart deploy/bt-backend-staging
- kubectl rollout restart deploy/bt-frontend-staging
- kubectl rollout status --timeout=1200s deploy/bt-backend-staging
- kubectl rollout status --timeout=1200s deploy/bt-frontend-staging
deploy-prod:
stage: deploy-prod
only:
refs:
- master
environment:
name: prod
when: manual
image: $CI_SERVER_HOST:5000/berkeleytime/bt-gitlab-runner
script:
- envsubst < $FILEPATH_DEPLOY_BACKEND | kubectl apply -f - --kubeconfig $SECRET_KUBERNETES_CREDENTIALS
- envsubst < $FILEPATH_DEPLOY_DATA | kubectl apply -f - --kubeconfig $SECRET_KUBERNETES_CREDENTIALS
- envsubst < $FILEPATH_DEPLOY_FRONTEND| kubectl apply -f - --kubeconfig $SECRET_KUBERNETES_CREDENTIALS
- kubectl rollout restart deploy/bt-backend-prod
- kubectl rollout restart deploy/bt-frontend-prod
- kubectl rollout status --timeout=1200s deploy/bt-backend-prod
- kubectl rollout status --timeout=1200s deploy/bt-frontend-prod