-
Notifications
You must be signed in to change notification settings - Fork 0
175 lines (174 loc) · 6.12 KB
/
test_deploy_env.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
---
description: >
Deploy via helm, using chart found in the helm_deploy dir of the repo.
Optionally send a slack notification.
executor:
name: default_small
tag: "3.10"
parameters:
env:
type: string
default: dev
release_name:
type: string
default: PROJECT_NAME
chart_name:
type: string
default: PROJECT_NAME
chart_version:
type: string
default: latest
helm_repo:
type: string
default: local
description: For using non local helm chart set to URL of helm repo
helm_dir:
type: string
default: helm_deploy
slack_notification:
type: boolean
default: false
description: When true, notifies a Slack channel after every deployment done with this job.
slack_channel_name:
type: string
default: "dps-releases"
description: Slack channel to use for deployment notifications.
helm_additional_args:
type: string
default: ""
show_changelog:
type: boolean
default: true
description: When true, displays what is new since the previous deployment in the job, and in Slack, if applicable
changelog_git_paths:
type: string
default: ""
description: When set it will limit the file changes shown in the changelog to the specified paths only. This is useful for multi-project builds where otherwise it will show all changes from all projects.
k8s_deployment_name:
type: string
default: PROJECT_NAME
description: The Deployment resource's name in Kubernetes to interrogate for the previous deployment's version
jira_update:
type: boolean
default: false
description: When true, updates any referenced Jira tickets with deployment information. Note that Jira integration must be enabled in your CircleCI project settings.
jira_env_type:
type: enum
default: development
description: Environment type to use when updating Jira
enum:
- production
- staging
- testing
- development
- unmapped
helm_timeout:
type: string
default: 5m
pipeline_id:
type: string
default: ""
description: Required if jira_update is set (otherwise the Notify Jira job will pass but do nothing), passed in as << pipeline.id >>
pipeline_number:
type: integer
default: 0
description: Required if jira_update is set, passed in as << pipeline.number >>
steps:
- checkout
- k8s_setup
- install_helm
- install_aws_cli
- mem/recall:
env_var: APP_VERSION
- when:
condition: <<parameters.show_changelog>>
steps:
- run:
name: Show changes about to be released on << parameters.env >>
environment:
K8S_DEPLOYMENT_NAME: << parameters.k8s_deployment_name >>
CHANGELOG_GIT_PATHS: << parameters.changelog_git_paths >>
command: <<include(scripts/version_history.sh)>>
- run:
name: Store deployment changelog
command: |
echo 'export DEPLOYMENT_CHANGELOG=$(<.deployment_changelog)' >> $BASH_ENV
- mem/recall:
env_var: APP_VERSION
- run:
name: Deploy to << parameters.env >>
working_directory: << parameters.helm_dir >>
environment:
RELEASE_NAME: << parameters.release_name >>
CHART_NAME: << parameters.chart_name >>
CHART_VERSION: << parameters.chart_version >>
HELM_REPO: << parameters.helm_repo >>
ENV_NAME: << parameters.env >>
HELM_ADDITIONAL_ARGS: << parameters.helm_additional_args >>
HELM_TIMEOUT: << parameters.helm_timeout >>
command: <<include(scripts/deploy_env.sh)>>
- when:
condition: <<parameters.slack_notification>>
steps:
- run:
name: Slack channels to notify
command: |
# For prod releases only always notify central dps-releases channel in addition to custom team channels.
if [[ "<< parameters.env >>" == "prod" || "<< parameters.env >>" == "production" ]]; then
# By default send to channel ID CVA3MKDTR = #dps-releases
if [[ "<< parameters.slack_channel_name >>" == "CVA3MKDTR" || "<< parameters.slack_channel_name >>" == "dps-releases" ]]; then
NOTIFY_SLACK_CHANNELS="CVA3MKDTR"
else
# Also send to custom team channel
NOTIFY_SLACK_CHANNELS="CVA3MKDTR,<< parameters.slack_channel_name >>"
fi
else
# non prod envs, send to custom team channel.
NOTIFY_SLACK_CHANNELS="<< parameters.slack_channel_name >>"
fi
echo "export NOTIFY_SLACK_CHANNELS=$NOTIFY_SLACK_CHANNELS" >> $BASH_ENV
- slack/notify:
event: always
channel: ${NOTIFY_SLACK_CHANNELS}
custom: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*${RELEASE_NAME}* version `${APP_VERSION}` deploy to *<< parameters.env >>*"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "View job"
},
"url": "${CIRCLE_BUILD_URL}"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": ":circleci-${CCI_STATUS}: Deploy ${CCI_STATUS}"
},
{
"type": "plain_text",
"text": "\n${DEPLOYMENT_CHANGELOG}"
}
]
}
]
}
- when:
condition: << parameters.jira_update >>
steps:
- jira/notify:
job_type: deployment
environment: << parameters.env >>
environment_type: << parameters.jira_env_type >>
pipeline_id: << parameters.pipeline_id >>
pipeline_number: << parameters.pipeline_number >>