-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.gitlab-ci.yml
147 lines (134 loc) · 3.88 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
stages:
- test
- build
- release
- deploy
variables:
CONTAINER_IMAGE: ${CI_REGISTRY}/${CI_PROJECT_PATH}
NAMESPACE: hosting
SECRET: gitlab-registry
REPOSITORY: ${CI_REGISTRY}/${CI_PROJECT_PATH}
.docker-login: &docker-login
before_script:
- docker login -u gitlab-ci-token -p ${CI_BUILD_TOKEN} ${CI_REGISTRY}
test-build:
services:
image: docker:latest
stage: test
tags:
- build
script:
- docker build -t ${CONTAINER_IMAGE}:${CI_COMMIT_SHA:0:8} .
- docker rmi --force ${CONTAINER_IMAGE}:${CI_COMMIT_SHA:0:8}
except:
- develop
- master
- staging
- tags
dev-release:
image: docker:latest
stage: release
tags:
- build
<<: *docker-login
script:
- docker build -t ${CONTAINER_IMAGE}:${CI_COMMIT_SHA:0:8} .
- docker push ${CONTAINER_IMAGE}:${CI_COMMIT_SHA:0:8}
- docker rmi --force ${CONTAINER_IMAGE}:${CI_COMMIT_SHA:0:8}
only:
- develop
dev-deploy:
image: exon/helm
stage: deploy
tags:
- develop
before_script:
- mkdir -p /etc/deploy/
- echo ${SANDBOX_KUBE_CONFIG} | base64 -d > ${KUBECONFIG}
- helm init --client-only
- helm repo update
environment:
name: develop
script:
- cd charts/api-gateway
- helm upgrade --install --debug --namespace=${NAMESPACE} ${CI_PROJECT_NAME} --set image.tag=${CI_COMMIT_SHA:0:8} --set image.secret=${SECRET} --set image.repository=${REPOSITORY} --set service.externalIP=88.99.247.59 --values values.yaml .
only:
- develop
pub-github:
image: alpine
stage: deploy
tags:
- build
before_script:
- apk update
- apk upgrade
- apk add --no-cache bash git openssh
- git config --global user.email "info@containerum.io"
- git config --global user.name "Containerum Bot"
- mkdir -p ~/.ssh
- echo ${ID_RSA_GITHUB} | base64 -d > ~/.ssh/id_rsa
- echo ${ID_RSA_PUB_GITHUB} | base64 -d > ~/.ssh/id_rsa.pub
- chmod 600 ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa.pub
- eval `ssh-agent -s`
- ssh-add ~/.ssh/id_rsa
- ssh-keyscan -H github.com >> ~/.ssh/known_hosts
script:
- git remote show
- if [ $(git remote show | grep github) ]; then git remote rm github; fi
- if [ $(git branch --list | grep pub) ]; then git branch -d pub; fi
- git remote add github ${GITHUB_REMOTE}
- git pull origin develop
- git fetch github
- git checkout origin/develop
- git checkout -b pub
- git push -u github pub:develop --force
- git remote rm github
only:
- develop
stage-release:
image: docker:latest
stage: release
tags:
- build
<<: *docker-login
script:
- docker build -t ${CONTAINER_IMAGE}:${CI_COMMIT_SHA:0:8} .
- docker push ${CONTAINER_IMAGE}:${CI_COMMIT_SHA:0:8}
- docker rmi --force ${CONTAINER_IMAGE}:${CI_COMMIT_SHA:0:8}
only:
- master
prod-release:
image: docker:latest
stage: release
tags:
- build
<<: *docker-login
script:
- docker pull ${CONTAINER_IMAGE}:${CI_COMMIT_SHA:0:8}
- docker tag ${CONTAINER_IMAGE}:${CI_COMMIT_SHA:0:8} ${CONTAINER_IMAGE}:latest
- docker tag ${CONTAINER_IMAGE}:${CI_COMMIT_SHA:0:8} ${CONTAINER_IMAGE}:${CI_COMMIT_TAG}
- docker push ${CONTAINER_IMAGE}:latest
- docker push ${CONTAINER_IMAGE}:${CI_COMMIT_TAG}
- docker rmi --force ${CONTAINER_IMAGE}:${CI_COMMIT_SHA:0:8}
only:
- tags
prod-deploy:
image: exon/helm
stage: deploy
tags:
- production
before_script:
- mkdir -p /etc/deploy/
- echo ${PRODUCTION_KUBE_CONFIG_2} | base64 -d > ${KUBECONFIG}
- helm init --client-only
- helm repo update
environment:
name: production
url: https://web.containerum.io
script:
- cd charts/api-gateway
- helm upgrade --install --namespace=${NAMESPACE} ${CI_PROJECT_NAME} --set image.tag=${CI_COMMIT_TAG} --set image.secret=${SECRET} --set image.repository=${REPOSITORY} --set service.externalIP=${PRODUCTION_IP} --values values.yaml .
only:
- tags
when: manual