forked from juicycleff/ultimate-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
151 lines (140 loc) · 4.41 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
image: node:10.16.0
cache:
paths:
- node_modules/
- .yarn
- dist
variables:
DOCKER_HOST: tcp://docker:2375
IMAGE_TAG: $CI_COMMIT_SHORT_SHA
stages:
- prebuild
- build
- dockerize
- deploy
before_script:
- apt-get update -qq && apt-get install
- apk update
- apk upgrade
- apk add --update curl && rm -rf /var/cache/apk/*
Prebuild:
stage: prebuild
before_script:
- yarn config set cache-folder .yarn
script:
- yarn install
# - yarn lint
artifacts:
paths:
- node_modules/
- .yarn
- dist
Build:
stage: build
before_script:
- apt-get update
- apt-get install software-properties-common -y
- apt-get update
- apt-get install jq -y
- ln -s bash /bin/sh.bash
- mv /bin/sh.bash /bin/sh
- apt-get update
- yarn global add npx
script:
- sh ./scripts/setup.sh
- ln -s dash /bin/sh.dash
- mv /bin/sh.dash /bin/sh
Dockerize:
stage: dockerize
image: docker/compose:1.25.0-rc1
services:
- docker:18.09.7-dind
when: manual
allow_failure: false
before_script:
- apk update
- apk upgrade
- apk add --update curl && rm -rf /var/cache/apk/*
- echo "$DOCKER_PASSWORD" | docker login -u ${DOCKER_USERNAME} --password-stdin ${DOCKER_REGISTRY}
script:
- sh ./scripts/dockerize.sh
Upgrade production:
stage: deploy
image: dtzar/helm-kubectl
only:
- master
when: manual
allow_failure: false
before_script:
- curl -L https://github.com/kubernetes/kompose/releases/download/v1.21.0/kompose-linux-amd64 -o kompose
- chmod +x kompose
- mv ./kompose /usr/local/bin/kompose
script:
- mkdir deploy
- kompose -f docker-compose.yml convert -o deploy/
- kubectl config set-cluster k8s --server="${KUBE_SERVER}"
- kubectl config set clusters.k8s.certificate-authority-data ${CERTIFICATE_AUTHORITY}
- kubectl config set-credentials gitlab --token="${KUBE_TOKEN}"
- kubectl config set-context default --cluster=k8s --user=gitlab
- kubectl config use-context default
- kubectl apply -f deploy --namespace default
Upgrade Staging:
stage: deploy
image: dtzar/helm-kubectl
only:
- staging
when: manual
before_script:
- curl -L https://github.com/kubernetes/kompose/releases/download/v1.21.0/kompose-linux-amd64 -o kompose
- chmod +x kompose
- mv ./kompose /usr/local/bin/kompose
script:
- mkdir deploy
- kompose -f docker-compose.yml convert -o deploy/
- kubectl config set-cluster k8s --server="${KUBE_SERVER}"
- kubectl config set clusters.k8s.certificate-authority-data ${CERTIFICATE_AUTHORITY}
- kubectl config set-credentials gitlab --token="${KUBE_TOKEN}"
- kubectl config set-context default --cluster=k8s --user=gitlab
- kubectl config use-context staging
- kubectl apply -f deploy/ --namespace default
Patch Production:
stage: deploy
image: dtzar/helm-kubectl
only:
- master
when: manual
allow_failure: false
script:
- apk update
- apk add jq
- wget -q -O /usr/bin/yq $(wget -q -O - https://api.github.com/repos/mikefarah/yq/releases/latest | jq -r '.assets[] | select(.name == "yq_linux_amd64") | .browser_download_url')
- chmod +x /usr/bin/yq
- ln -s bash /bin/sh.bash
- mv /bin/sh.bash /bin/sh
- kubectl config set-cluster k8s --server="${KUBE_SERVER}"
- kubectl config set clusters.k8s.certificate-authority-data ${CERTIFICATE_AUTHORITY}
- kubectl config set-credentials gitlab --token="${KUBE_TOKEN}"
- kubectl config set-context default --cluster=k8s --user=gitlab
- kubectl config use-context default
- NAMESPACE=default
- sh scripts/kubernetes/update-deployment.sh
Patch Staging:
stage: deploy
image: dtzar/helm-kubectl
only:
- staging
when: manual
script:
- apk update
- apk add jq
- wget -q -O /usr/bin/yq $(wget -q -O - https://api.github.com/repos/mikefarah/yq/releases/latest | jq -r '.assets[] | select(.name == "yq_linux_amd64") | .browser_download_url')
- chmod +x /usr/bin/yq
- ln -s bash /bin/sh.bash
- mv /bin/sh.bash /bin/sh
- kubectl config set-cluster k8s --server="${KUBE_SERVER}"
- kubectl config set clusters.k8s.certificate-authority-data ${CERTIFICATE_AUTHORITY}
- kubectl config set-credentials gitlab --token="${KUBE_TOKEN}"
- kubectl config set-context default --cluster=k8s --user=gitlab
- kubectl config use-context default
- NAMESPACE=staging
- sh scripts/kubernetes/update-deployment.sh