-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
174 lines (162 loc) · 4.92 KB
/
.gitlab-ci.yml
File metadata and controls
174 lines (162 loc) · 4.92 KB
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
include:
- https://gitlab.exphost.pl/exphost/exphost-helms/-/raw/master/common/gitlab-ci.yml
- https://gitlab.exphost.pl/exphost-controller/controller-helms/-/raw/master/helpers/gitlab-ci.yml
stages:
- prepare
- tests
- build
- push
- deploy_to_dev
- deploy
- cleanup
- upload
get version:
extends: .get version
tests:
stage: tests
image: python:3.9
script:
- pip install -r requirements.txt
- cd app
- flake8
- pytest --cov --cov-report term --cov-report xml --junitxml=report.xml
artifacts:
reports:
cobertura: app/coverage.xml
junit: app/report.xml
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
cache:
paths:
- .cache/pip
build:
stage: build
image: quay.io/podman/stable
extends: .registry
script:
- podman pull $CI_REGISTRY_IMAGE:dev || true
- >
podman build
--pull
--tag $CI_REGISTRY_IMAGE:dev
.
- podman push $CI_REGISTRY_IMAGE:dev
push image:
variables:
GIT_STRATEGY: none
image: quay.io/podman/stable
stage: push
extends: .registry
only:
- master
- tags
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)"
#push tag:
# variables:
# GIT_STRATEGY: none
# image: quay.io/podman/stable
# stage: push
# extends: .registry
# only:
# - tags
# 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
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:
- 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-appsservice.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-appsservice chart -f gitlab-ci-values-appsservice.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-appsservice
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-appsservice --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 == \"appsservice\").version=\"$$VERSION\"" chart/Chart.yaml
repo: git@gitlab.exphost.pl:exphost-controller/controller-helms.git
only:
refs:
- tags
- master