-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
137 lines (131 loc) · 4.89 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
variables:
P1_PROJECT: p1authapp
stages:
- build
- deploy
build:
stage: build
before_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
script:
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID .
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID
- (if [ -f Dockerfile.nginx ]; then docker build -t $CI_REGISTRY_IMAGE:"$CI_COMMIT_REF_SLUG"-static.$CI_PIPELINE_ID -f Dockerfile.nginx . ; else echo "Project without static content"; fi);
- (if [ -f Dockerfile.nginx ]; then docker push $CI_REGISTRY_IMAGE:"$CI_COMMIT_REF_SLUG"-static.$CI_PIPELINE_ID ; else echo "Project without static content"; fi);
deploy_production:
stage: deploy
environment:
name: production
script:
- docker run
--rm
-v $PWD/.helm:/.helm
-e "K8S_API_URL=$K8S_API_URL"
-e "K8S_CI_TOKEN=$K8S_CI_TOKEN"
-e "P1_PROJECT=$P1_PROJECT"
-e "CI_PROJECT_PATH_SLUG=$CI_PROJECT_PATH_SLUG"
-e "CI_ENVIRONMENT_NAME=$CI_ENVIRONMENT_NAME"
-e "CI_REGISTRY=$CI_REGISTRY"
-e "CI_REGISTRY_IMAGE=$CI_REGISTRY_IMAGE"
-e "CI_PROJECT_NAMESPACE=$CI_PROJECT_NAMESPACE"
-e "CI_PROJECT_NAME=$CI_PROJECT_NAME"
-e "CI_COMMIT_REF_SLUG=$CI_COMMIT_REF_SLUG"
-e "CI_PIPELINE_ID=$CI_PIPELINE_ID"
-e "CI_DEPLOY_USER=$CI_DEPLOY_USER"
-e "CI_DEPLOY_PASSWORD=$CI_DEPLOY_PASSWORD"
p1hub/kubernetes-helm:2.11.0
/bin/sh -c
'kubectl config set-cluster k8s --insecure-skip-tls-verify=true --server=$K8S_API_URL &&
kubectl config set-credentials ci --token=$K8S_CI_TOKEN &&
kubectl config set-context ci --cluster=k8s --user=ci &&
kubectl config use-context ci &&
helm init --client-only &&
helm upgrade --install $P1_PROJECT .helm
--set backend.image=$CI_REGISTRY_IMAGE
--set backend.imageTag="$CI_COMMIT_REF_SLUG".$CI_PIPELINE_ID
--wait
--timeout 180 ||
(helm history --max 2 $P1_PROJECT | head -n 2 | tail -n 1 | awk "{print \$1}" | xargs helm rollback $P1_PROJECT && exit 1)'
only:
- master
when: on_success
review:
stage: deploy
environment:
name: $P1_PROJECT-$CI_COMMIT_REF_NAME
url: http://$CI_ENVIRONMENT_SLUG.tst.protocol.one
on_stop: stop_review
script:
- docker run
--rm
-v $PWD/.helm:/.helm
-e "K8S_API_URL=$K8S_API_URL"
-e "K8S_CI_TOKEN=$K8S_CI_TOKEN"
-e "CI_PROJECT_PATH_SLUG=$CI_PROJECT_PATH_SLUG"
-e "CI_ENVIRONMENT_NAME=$CI_ENVIRONMENT_NAME"
-e "CI_ENVIRONMENT_SLUG=$CI_ENVIRONMENT_SLUG"
-e "CI_REGISTRY=$CI_REGISTRY"
-e "CI_REGISTRY_IMAGE=$CI_REGISTRY_IMAGE"
-e "CI_PROJECT_NAMESPACE=$CI_PROJECT_NAMESPACE"
-e "CI_PROJECT_NAME=$CI_PROJECT_NAME"
-e "CI_COMMIT_REF_SLUG=$CI_COMMIT_REF_SLUG"
-e "CI_PIPELINE_ID=$CI_PIPELINE_ID"
-e "CI_DEPLOY_USER=$CI_DEPLOY_USER"
-e "CI_DEPLOY_PASSWORD=$CI_DEPLOY_PASSWORD"
p1hub/kubernetes-helm:2.11.0
/bin/sh -c
'kubectl config set-cluster k8s --insecure-skip-tls-verify=true --server=$K8S_API_URL &&
kubectl config set-credentials ci --token=$K8S_CI_TOKEN &&
kubectl config set-context ci --cluster=k8s --user=ci &&
kubectl config use-context ci &&
helm init --client-only &&
kubectl get namespace $CI_ENVIRONMENT_SLUG ||
kubectl create namespace $CI_ENVIRONMENT_SLUG &&
helm upgrade --install $CI_ENVIRONMENT_SLUG .helm
--set backend.image=$CI_REGISTRY_IMAGE
--set backend.imageTag="$CI_COMMIT_REF_SLUG".$CI_PIPELINE_ID
--set replicas=1
--set ingress.hostname=$CI_ENVIRONMENT_SLUG.tst.protocol.one
--wait
--timeout 180
--namespace $CI_ENVIRONMENT_SLUG'
only:
- branches
when: manual
except:
- master
stop_review:
image: p1hub/kubernetes-helm:2.11.0
stage: deploy
variables:
GIT_STRATEGY: none
script:
- docker run
--rm
-e "K8S_API_URL=$K8S_API_URL"
-e "K8S_CI_TOKEN=$K8S_CI_TOKEN"
-e "CI_PROJECT_PATH_SLUG=$CI_PROJECT_PATH_SLUG"
-e "CI_ENVIRONMENT_NAME=$CI_ENVIRONMENT_NAME"
-e "CI_ENVIRONMENT_SLUG=$CI_ENVIRONMENT_SLUG"
-e "CI_REGISTRY=$CI_REGISTRY"
-e "CI_PROJECT_NAMESPACE=$CI_PROJECT_NAMESPACE"
-e "CI_PROJECT_NAME=$CI_PROJECT_NAME"
-e "CI_COMMIT_REF_SLUG=$CI_COMMIT_REF_SLUG"
-e "CI_PIPELINE_ID=$CI_PIPELINE_ID"
p1hub/kubernetes-helm:2.11.0
/bin/sh -c
'kubectl config set-cluster k8s --insecure-skip-tls-verify=true --server=$K8S_API_URL &&
kubectl config set-credentials ci --token=$K8S_CI_TOKEN &&
kubectl config set-context ci --cluster=k8s --user=ci &&
kubectl config use-context ci &&
helm init --client-only &&
helm delete --purge $CI_ENVIRONMENT_SLUG &&
kubectl delete namespace $CI_ENVIRONMENT_SLUG'
environment:
name: $P1_PROJECT-$CI_COMMIT_REF_NAME
action: stop
when: manual
only:
- branches
except:
- master