-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
46 lines (43 loc) · 1.42 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
stages:
- build
- push
- deploy
build:
stage: build
script:
- docker build -t $CI_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID .
push:
stage: push
variables:
GIT_STRATEGY: none
before_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
script:
- docker push $CI_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID
only:
- master
deploy:
stage: deploy
image: hypnoglow/kubernetes-helm:3.1
environment:
name: production
script:
- kubectl config set-cluster k8s --server=$K8S_API_URL --insecure-skip-tls-verify=true
- kubectl config set-credentials ci --token=$K8S_CI_TOKEN
- kubectl config set-context ci --cluster=k8s --user=ci
- kubectl config use-context ci
- if [ "$(helm -n $CI_PROJECT_NAMESPACE list | tail -n-1 | wc -l)" != "0" ] ; then
helm upgrade --install
--set app.repository=$CI_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME
--set app.tag=$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID
--namespace $CI_PROJECT_NAMESPACE
$CI_PROJECT_PATH_SLUG .helm;
else
helm install
--set app.repository=$CI_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME
--set app.tag=$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID
--create-namespace --namespace $CI_PROJECT_NAMESPACE
$CI_PROJECT_PATH_SLUG .helm;
fi
only:
- master