-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
202 lines (187 loc) · 5.65 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
include:
- https://gitlab.exphost.pl/exphost/exphost-helms/-/raw/master/common/gitlab-ci.yml
stages:
- prepare
- build_app
- tests
- build
- push
- deploy
- cleanup
- upload
.registry:
before_script:
- echo -n $CI_REGISTRY_PASSWORD | podman login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
get version:
extends: .get version
buildapp:
stage: build_app
image: quay.io/podman/stable:v4
extends: .registry
script:
- podman --root podman pull ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-dev || true
- >
podman --root podman build
--pull
-f Dockerfile-dev
--tag ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-dev
--ulimit nofile=4096:4096
.
- podman --root podman push ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-dev
cache:
key: $CI_COMMIT_REF_SLUG
paths:
- podman
tests:
stage: tests
image: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-dev
script:
- cd /app
- npm run test:ci
- cp -r /app/test_out $CI_PROJECT_DIR
artifacts:
reports:
cobertura: test_out/cobertura-coverage.xml
junit: test_out/junit.xml
lint:
stage: tests
image: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-dev
script:
- cd /app
- npm run lint
build:
stage: build
image: quay.io/podman/stable:v4
extends: .registry
script:
- podman pull $CI_REGISTRY_IMAGE:latest || true
- >
podman build
--pull
--build-arg APPVER=${CI_COMMIT_SHORT_SHA}-dev
--build-arg APPIMAGE=${CI_REGISTRY_IMAGE}
--tag $CI_REGISTRY_IMAGE:dev
.
- podman push $CI_REGISTRY_IMAGE:dev
push latest:
variables:
GIT_STRATEGY: none
image: quay.io/podman/stable:v4
stage: push
extends: .registry
script:
- podman pull $CI_REGISTRY_IMAGE:dev
- podman tag $CI_REGISTRY_IMAGE:dev $CI_REGISTRY_IMAGE:latest
- podman push $CI_REGISTRY_IMAGE:latest
- "podman tag $CI_REGISTRY_IMAGE:dev $CI_REGISTRY_IMAGE:$(cat output/version.txt)"
- "podman push $CI_REGISTRY_IMAGE:$(cat output/version.txt)"
only:
refs:
- master
push tag:
variables:
GIT_STRATEGY: none
image: quay.io/podman/stable:v4
stage: push
extends: .registry
script:
- podman pull $CI_REGISTRY_IMAGE:dev
- podman tag $CI_REGISTRY_IMAGE:dev $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
- podman push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
only:
refs:
- tags
deploy branch:
stage: deploy
image:
name: alpine/helm
environment:
name: dev/$CI_COMMIT_REF_SLUG
on_stop: delete_app
url: https://$KUBE_NAMESPACE.ci.exphost.pl
before_script:
- helm repo add exphost https://gitlab.exphost.pl/charts
- helm repo add dex https://charts.dexidp.io
- helm repo update
- apk add --no-cache ca-certificates git curl
- curl -L "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" -o /usr/local/bin/kubectl
- chmod +x /usr/local/bin/kubectl
script:
# - export VERSION=$(git describe --tags)
# - sed -i "s/__VERSION__/$VERSION/" chart/Chart.yaml
- echo "CI_ENVIRONMENT_SLUG $CI_ENVIRONMENT_SLUG"
- echo "CI_ENVIRONMENT_SLUG $CI_ENVIRONMENT_SLUG"
- echo "KUBE_NAMESPACE $KUBE_NAMESPACE"
- sed -i "s/__DOMAIN__/${KUBE_NAMESPACE}.ci.exphost.pl/" gitlab-ci-values-dex.yml
- sed -i "s/__DOMAIN__/${KUBE_NAMESPACE}.ci.exphost.pl/" gitlab-ci-values-webui.yml
- sed -i "s/__DOMAIN__/${KUBE_NAMESPACE}.ci.exphost.pl/" gitlab-ci-values.yml
- >
helm upgrade -n $KUBE_NAMESPACE -i auth dex/dex -f gitlab-ci-values-dex.yml
--wait --wait-for-jobs
- >
helm upgrade -n $KUBE_NAMESPACE -i ldap exphost/openldap -f gitlab-ci-values.yml
--wait --wait-for-jobs
- >
helm upgrade -n $KUBE_NAMESPACE -i test-controller exphost/exphost-controller -f gitlab-ci-values.yml
--version v0.0.0-latest
--set global.domain=${KUBE_NAMESPACE}.ci.exphost.pl
--wait --wait-for-jobs --skip-crds
- >
helm upgrade -n $KUBE_NAMESPACE -i test-webui chart -f gitlab-ci-values-webui.yml
--set podAnnotations."app\.gitlab\.com/app"=$CI_PROJECT_PATH_SLUG
--set podAnnotations."app\.gitlab\.com/env"=$CI_ENVIRONMENT_SLUG
--set global.domain=${KUBE_NAMESPACE}.ci.exphost.pl
--wait --wait-for-jobs --skip-crds
- kubectl -n $KUBE_NAMESPACE rollout restart deployment test-webui-controller-webui
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: never
- if: $CI_COMMIT_BRANCH
delete_app:
stage: cleanup
image:
name: alpine/helm
before_script:
- apk add --no-cache ca-certificates git curl
- curl -L "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" -o /usr/local/bin/kubectl
- chmod +x /usr/local/bin/kubectl
script:
- helm uninstall -n $KUBE_NAMESPACE ldap --wait
- helm uninstall -n $KUBE_NAMESPACE auth --wait
- helm uninstall -n $KUBE_NAMESPACE test-controller --wait
- helm uninstall -n $KUBE_NAMESPACE test-webui --wait
- kubectl -n $KUBE_NAMESPACE delete pvc --all
variables:
GIT_STRATEGY: none
environment:
name: dev/$CI_COMMIT_REF_SLUG
action: stop
needs:
- deploy branch
when: manual
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: never
- if: $CI_COMMIT_BRANCH
upload:
extends: .upload
only:
refs:
- tags
- master
upload latest:
extends: .upload latest
only:
refs:
- tags
- master
update general helm:
extends: .deploy-to-git
stage: upload
variables:
patch_cmd: yq -i e ".dependencies[] |= select(.name == \"controller-webui\").version=\"$$VERSION\"" chart/Chart.yaml
repo: [email protected]:exphost-controller/controller-helms.git
only:
refs:
- tags
- master