forked from brysontyrrell/PatchServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
91 lines (85 loc) · 2.24 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
stages:
- build
- yaml
- deploy
variables:
GIT_SUBMODULE_STRATEGY: recursive
build_docker:
stage: build
tags:
- kubernetes
image: gcr.io/kaniko-project/executor:debug
script:
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/installation/docker/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
- echo $CI_COMMIT_SHORT_SHA > tag.txt
- echo $DEV_FQDN > fqdn.txt
except:
refs:
- master
artifacts:
paths:
- tag.txt
- fqdn.txt
tag_docker:
stage: build
tags:
- kubernetes
image: gcr.io/go-containerregistry/crane:debug
script:
- crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- crane cp $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE:latest
- echo "latest" > tag.txt
- echo $PROD_FQDN > fqdn.txt
only:
refs:
- master
artifacts:
paths:
- tag.txt
- fqdn.txt
build_yaml:
stage: yaml
tags:
- kubernetes
script:
- apt update
- apt install gettext-base -y
- export DOCKER_AUTHS=`printf "$CI_DEPLOY_USER:$CI_DEPLOY_PASSWORD" | base64 -w 0`
- echo $DOCKER_AUTHS | base64 -d
- export REGISTRY_AUTH=`echo "{\"auths\":{\"$CI_REGISTRY\":{\"auth\":\"$DOCKER_AUTHS\"}}}" | base64 -w 0`
- export IMAGE=`cat tag.txt`
- export FQDN=`cat fqdn.txt`
- cat deploy.template.yml | envsubst > deploy.yml
- cat namespace.template.yml | envsubst > namespace.yml
artifacts:
paths:
- deploy.yml
- namespace.yml
deploy_review:
stage: deploy
tags:
- kubernetes
image: bitnami/kubectl:latest
script:
- export FQDN=`cat fqdn.txt`
- cat deploy.yml
- kubectl apply -f namespace.yml
- kubectl apply -f deploy.yml
environment:
name: $CI_COMMIT_REF_NAME
url: https://${FDQN}
on_stop: stop_review
stop_review:
stage: deploy
tags:
- kubernetes
image: bitnami/kubectl:latest
when: manual
script:
- export FQDN=`cat fqdn.txt`
- kubectl delete -f deploy.yml
environment:
name: $CI_COMMIT_REF_NAME
url: https://${FQDN}
action: stop