-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
199 lines (188 loc) · 5.35 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
stages:
- build
- image
- deploy
# Define some conditions to run the whole pipeline
workflow:
rules:
- if: $CI_MERGE_REQUEST_ID # Run on MRs
- if: $CI_COMMIT_TAG # Run on tags
- if: $CI_COMMIT_BRANCH == "standalone" # Run on standalone
# Customize the build rules and the artifacts here
build:
stage: build
image: registry.ocamlpro.com/ocamlpro/ocaml-docker-images:4.10
variables:
GIT_SUBMODULE_STRATEGY: recursive
before_script:
- sudo apk add pkgconf && opam option --global 'depext-bypass+=["pkgconfig"]'
- sudo apk add bash
- "[ -d _opam ] || opam switch create . ocaml.4.07.1 --deps-only --locked"
script:
- opam exec -- ocp-build init
- opam exec -- sh build_deps.sh
- opam exec -- make website
- tar czhf www.tar.gz -C www .
cache:
key:
files:
- opam
paths:
- _opam
artifacts:
paths:
- www.tar.gz
# The Dockerfile for the image we want to generate
# Here we inherit from nginx and just add the contents of our web-app
.gen-dockerfile: &gen-dockerfile
- |
echo "\
FROM bitnami/nginx:latest
ADD --chown=www-data www.tar.gz /app
ADD --chown=www-data http://d4.dune.network:6789/timeline_data?min_level=10 /app/timeline_data
ADD --chown=www-data http://d4.dune.network:6789/title /app/title
USER 0
RUN sed -i '/X-Frame-Options/d' /opt/bitnami/nginx/conf/nginx.conf
RUN chmod a+rX-w -R /app
USER 1001
" > /kaniko/Dockerfile
# Builds and pushes the Docker image using Kaniko
make-image:
stage: image
image:
name: gcr.io/kaniko-project/executor:debug-v0.19.0
entrypoint: [""]
script:
- *gen-dockerfile
- |
echo "\
{ \"auths\": {
\"$CI_REGISTRY\": {
\"username\":\"$CI_REGISTRY_USER\",
\"password\":\"$CI_REGISTRY_PASSWORD\"
}}}
" > /kaniko/.docker/config.json
- /kaniko/executor
--context=$CI_PROJECT_DIR
--dockerfile=/kaniko/Dockerfile
--destination=$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
--destination=$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA
$(if [ "$CI_COMMIT_BRANCH" = "$CI_DEFAULT_BRANCH" ]; then
echo "--destination=$CI_REGISTRY_IMAGE:latest";
fi)
# Configuration for the bitnami/nginx helm chart that we deploy
.gen-deploy-yaml: &gen-deploy-yaml
- |
echo "\
image:
registry: ${CI_REGISTRY}
repository: ${CI_REGISTRY_IMAGE#$CI_REGISTRY/}
tag: ${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHORT_SHA}
pullPolicy: Always
pullSecrets:
- gitlab-deploy
service:
type: ClusterIP
serverBlock: |
server {
listen 0.0.0.0:8080;
root /app;
location / {
index index.html;
}
}
ingress:
enabled: true
hostname: \"${PUBLIC_HOST}\"
annotations:
kubernetes.io/ingress.class: nginx
kubernetes.io/tls-acme: \"true\"
tls:
- secretName: ${CI_PROJECT_NAME}-${CI_COMMIT_REF_SLUG}-tls
hosts:
- \"${PUBLIC_HOST}\"
" > deploy.yaml
# This defines the deploy jobs, shouldn't need to be changed
# See https://gitlab.com/gitlab-org/cluster-integration/auto-deploy-image/-/blob/master/src/bin/auto-deploy for guidance.
.deploy_template: &deploy-job
stage: deploy
# We just need an image where we can run helm (v.3 minimum)
image: dtzar/helm-kubectl:3.2.0
# Skip downloading of the artifacts
dependencies: []
interruptible: true
variables: &deploy-variables
POD_NAME: ${CI_ENVIRONMENT_SLUG}-${CI_COMMIT_REF_SLUG}
PUBLIC_HOST: ${CI_PROJECT_NAME}-${CI_COMMIT_REF_SLUG}.${KUBE_INGRESS_BASE_DOMAIN}
# Uncomment this for verbose debug
# CI_DEBUG_TRACE: "true"
before_script:
# We use the bitnami/nginx chart that works well with the associated Docker
# image used as base for our server
- helm repo add bitnami https://charts.bitnami.com/bitnami
- helm repo update
script:
- *gen-deploy-yaml
- helm upgrade --install --reset-values --atomic --cleanup-on-fail
--force
--namespace="$KUBE_NAMESPACE"
--values deploy.yaml
"$POD_NAME"
bitnami/nginx
# Only master
deploy-master:
<<: *deploy-job
environment:
name: dev
url: https://${PUBLIC_HOST}
on_stop: stop-deploy-dev
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
# For MRs or other branches: same, but auto-stop after 3 days
deploy-temp:
<<: *deploy-job
environment:
name: dev
url: https://${PUBLIC_HOST}
on_stop: stop-deploy-dev
auto_stop_in: 3 days
rules:
- if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
# Adjust the PUBLIC_HOST here. Be sure to set the DNS too!
deploy-prod:
<<: *deploy-job
variables:
<<: *deploy-variables
PUBLIC_HOST: ${CI_PROJECT_NAME}.ocamlpro.com
environment:
name: prod
url: https://${PUBLIC_HOST}
on_stop: stop-deploy-prod
rules:
- when: manual
allow_failure: true
stop-deploy-dev:
<<: *deploy-job
environment:
name: dev
action: stop
interruptible: false
script:
- helm uninstall "$POD_NAME"
rules:
- when: manual
allow_failure: true
stop-deploy-prod:
<<: *deploy-job
variables:
<<: *deploy-variables
PUBLIC_HOST: ${CI_PROJECT_NAME}.ocamlpro.com
environment:
name: prod
action: stop
interruptible: false
script:
- helm uninstall "$POD_NAME"
rules:
- when: manual
allow_failure: true