This repository has been archived by the owner on May 6, 2023. It is now read-only.
forked from polkadot-js/apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
159 lines (142 loc) · 3.77 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
154
155
156
157
158
159
image: roffe/kubectl:latest
variables:
CI_REGISTRY: parity.azurecr.io
CI_REGISTRY_USER: parity
AUTO_DEVOPS_DOMAIN: poc-3.polkadot.io
.kubernetes: &kubernetes
tags:
- kubernetes
stages:
- dockerize
- test
- review
- staging
- production
- cleanup
before_script:
- export DOCKER_IMAGE=$CI_REGISTRY/$CI_PROJECT_PATH_SLUG
- export DOCKER_TAG=$CI_COMMIT_REF_SLUG-$VERSION
- export DOCKER_IMAGE_FULL_NAME=$DOCKER_IMAGE:$DOCKER_TAG
dockerize:
stage: dockerize
environment:
name: infrastructure_build
tags:
- kubernetes-parity-build
image: docker:git
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://localhost:2375
script:
- echo $DOCKER_IMAGE
- echo $DOCKER_TAG
- echo $DOCKER_IMAGE_FULL_NAME
- echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin "$CI_REGISTRY"
- docker build -t "$DOCKER_IMAGE_FULL_NAME" .
- docker push "$DOCKER_IMAGE_FULL_NAME"
only:
- master
review:
stage: review
<<: *kubernetes
script:
- setup_kubernetes
- deploy
environment:
name: review/$CI_COMMIT_REF_NAME
url: https://$CI_ENVIRONMENT_SLUG.$AUTO_DEVOPS_DOMAIN
on_stop: stop_review
only:
refs:
- branches
kubernetes: active
except:
- master
stop_review:
stage: cleanup
<<: *kubernetes
variables:
GIT_STRATEGY: none
script:
- setup_kubernetes
- delete
environment:
name: review/$CI_COMMIT_REF_NAME
action: stop
when: manual
allow_failure: true
only:
refs:
- branches
kubernetes: active
except:
- master
staging:
stage: staging
<<: *kubernetes
script:
- setup_kubernetes
- deploy
environment:
name: staging
url: https://staging.$AUTO_DEVOPS_DOMAIN
only:
refs:
- master
kubernetes: active
production:
stage: production
<<: *kubernetes
script:
- setup_kubernetes
- deploy
environment:
name: production
url: https://$AUTO_DEVOPS_DOMAIN
when: manual
only:
refs:
- master
kubernetes: active
# ---------------------------------------------------------------------------
.auto_devops: &auto_devops |
# Auto DevOps variables and functions
[[ "$TRACE" ]] && set -x
export DOCKER_IMAGE=$CI_REGISTRY/$CI_PROJECT_PATH_SLUG
export DOCKER_TAG=$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHA
export DOCKER_IMAGE_FULL_NAME=$DOCKER_IMAGE:$DOCKER_TAG
export AUTODEVOPS_HOST=$(echo $CI_ENVIRONMENT_URL | awk -F/ '{print $3}')
function build() {
if [[ -n "$CI_REGISTRY_USER" ]]; then
echo "Logging to GitLab Container Registry with CI credentials..."
docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
echo ""
fi
echo "Building Dockerfile-based application..."
docker build -t "$DOCKER_IMAGE_FULL_NAME" .
echo "Pushing to GitLab Container Registry..."
docker push "$DOCKER_IMAGE_FULL_NAME"
echo ""
}
function setup_kubernetes() {
kubectl describe namespace "$KUBE_NAMESPACE" || kubectl create namespace "$KUBE_NAMESPACE"
kubectl create secret -n "$KUBE_NAMESPACE" \
docker-registry gitlab-registry \
--docker-server="$CI_REGISTRY" \
--docker-username="$CI_REGISTRY_USER" \
--docker-password="$CI_REGISTRY_PASSWORD" \
--docker-email="$GITLAB_USER_EMAIL" \
-o yaml --dry-run | kubectl replace -n "$KUBE_NAMESPACE" --force -f -
}
function deploy() {
cat ./deployment.template.yml | envsubst | kubectl apply -n "$KUBE_NAMESPACE" -f -
}
function delete() {
kubectl -n "$KUBE_NAMESPACE" delete "deploy/$CI_ENVIRONMENT_SLUG-backend"
kubectl -n "$KUBE_NAMESPACE" delete "svc/$CI_ENVIRONMENT_SLUG-service"
kubectl -n "$KUBE_NAMESPACE" delete "ing/$CI_ENVIRONMENT_SLUG-ingress"
}
before_script:
- *auto_devops