-
Notifications
You must be signed in to change notification settings - Fork 7
/
.gitlab-ci.yml
107 lines (99 loc) · 2.88 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
stages:
- pre_build
- pre_deploy
- deploy
variables:
IMAGE_TAG: ${CI_COMMIT_REF_SLUG}.${CI_PIPELINE_ID}
.before_script: &before_script
- |
tags_variables() {
if [ "$CI_COMMIT_REF_SLUG" == "master" ]; then
if ! [ -x "$(command -v git)" ]; then
echo 'Error: git is not installed.' >&2
exit 1
fi
COMMIT_DATE=$(git show -s --format=%ci $CI_COMMIT_SHA | sed 's/^\([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\).*/\1/')
if [ -z "$COMMIT_DATE" ]; then
echo "Error: $CI_COMMIT_SHA not checked out" >&2
exit 1
fi
export HELM_VERSION="1.1.$CI_PIPELINE_ID"
export HELM_NAME="bitwarden"
export APP_RELEASE="$COMMIT_DATE.$CI_PIPELINE_ID"
else
export HELM_VERSION="1.1.0-alpha.$IMAGE_TAG"
export HELM_NAME="bitwarden-${CI_COMMIT_REF_SLUG}"
export APP_RELEASE="$IMAGE_TAG"
fi
}
default:
image: ekreative/toolbox:helm-3
tags:
- kubernetes
before_script:
- *before_script
check_charts:
stage: pre_build
except:
- tags
script:
- helm lint charts/bitwarden
pre_deploy_chart:
stage: pre_deploy
except:
- tags
dependencies: []
script:
- tags_variables
- gcloud auth activate-service-account --key-file "$GCLOUD_KEY_FILE"
- helm package --destination charts --version "$HELM_VERSION" charts/bitwarden
- curl --fail --data-binary "@charts/bitwarden-$HELM_VERSION.tgz" "$HELM_CHARTS_URL/api/charts"
- |
if [ "$CI_COMMIT_REF_SLUG" == "master" ]; then
curl -H "PRIVATE-TOKEN: $GITLAB_API_TOKEN" -X POST -d "tag_name=$APP_RELEASE" -d "ref=$CI_COMMIT_SHA" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/repository/tags"
fi
.deploy:
stage: deploy
variables:
APP_VALUES: ${REVIEW_VALUES}
APP_CLUSTER: ${CLUSTER_TEST}
when: manual
allow_failure: false
dependencies: []
script:
- tags_variables
- gcloud auth activate-service-account --key-file "$GCLOUD_KEY_FILE"
- $APP_CLUSTER
- helm repo add ekreative-charts "$HELM_CHARTS_URL"
- |
helm upgrade "$HELM_NAME" ekreative-charts/bitwarden \
--install \
--create-namespace \
--namespace bitwarden \
--version "$HELM_VERSION" \
-f $APP_VALUES
- echo "Deployed $APP_RELEASE to $CI_ENVIRONMENT_NAME"
.stop:
stage: deploy
variables:
APP_CLUSTER: ${CLUSTER_TEST}
when: manual
dependencies: []
script:
- tags_variables
- gcloud auth activate-service-account --key-file "$GCLOUD_KEY_FILE"
- $APP_CLUSTER
- helm delete "$HELM_NAME" || true
deploy_live:
extends: .deploy
environment:
name: live
url: https://bitwarden.ekreative.com
only:
- master
variables:
APP_CLUSTER: ${CLUSTER_LIVE}
before_script:
- *before_script
# Cannot use variables for this, https://gitlab.com/gitlab-org/gitlab/-/issues/198357
- export APP_VALUES="$LIVE_VALUES"