-
Notifications
You must be signed in to change notification settings - Fork 0
230 lines (214 loc) · 8.13 KB
/
deploy.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
name: 2. Deploy to Cluster
on:
workflow_call:
secrets:
AWS_SECRET_ACCESS_KEY:
required: true
AWS_ACCESS_KEY_ID:
required: true
SLACK_BOT_TOKEN:
required: true
inputs:
AWS_REGION:
type: string
required: true
SLACK_CHANNEL:
type: string
required: true
DATABASE_HOST:
type: string
required: false
image-tag:
type: string
required: true
deploy-reference:
type: string
required: true
namespace:
type: string
required: false
default: 'default'
project:
type: string
required: true
chart:
type: string
required: false
default: 'kamma-charts/kamma-laravel'
domain:
type: string
required: true
runs-on:
type: string
required: false
default: ubuntu-latest
cluster:
type: string
required: false
default: 'kamma-qa-cluster'
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
DEPLOY_REFERENCE: ${{ inputs.deploy-reference }}
jobs:
deploy:
name: Deploy to Kube
runs-on: ${{ inputs.runs-on }}
environment: production
timeout-minutes: 15
steps:
# IF Production
- name: Set Deployment Name
id: release
run: |
if [ "${DEPLOY_NAMESPACE}" = "production"] || [ "${DEPLOY_NAMESPACE}" = "staging" ]; then
echo "::set-output name=name::${DEPLOY_NAMESPACE}"
else
echo "::set-output name=name::$(echo ${DEPLOY_REFERENCE##*/} | tr '_' '-' | tr '[:upper:]' '[:lower:]')"
fi
env:
DEPLOY_NAMESPACE: ${{ inputs.namespace }}
- name: Set Deployment Ingress
id: ingress
run: |
if [ "${DEPLOY_NAMESPACE}" = "production"] || [ "${DEPLOY_NAMESPACE}" = "staging" ]; then
echo "::set-output name=name::${DEPLOY_DOMAIN}"
else
echo "::set-output name=name::${DEPLOY_RELEASE}-${DEPLOY_PROJECT}.${DEPLOY_DOMAIN}"
fi
env:
DEPLOY_RELEASE: ${{ steps.release.outputs.name }}
DEPLOY_NAMESPACE: ${{ inputs.namespace }}
DEPLOY_PROJECT: ${{ inputs.project }}
DEPLOY_DOMAIN: ${{ inputs.domain }}
# Configure Helm
- name: Set up Helm
uses: azure/[email protected]
with:
version: v3.8.2
# Configure the aws credentials use by eks.
- name: Configure AWS credentials
uses: aws-actions/[email protected]
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ inputs.AWS_REGION }}
mask-aws-account-id: 'no'
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
# v1.24.0 Is currently broken with aws eks - this can be removed when that is fixed
# https://github.com/aws/aws-cli/issues/6920
- name: Setup Kubectl
run: |
apt list -a kubectl
curl -LO "https://dl.k8s.io/release/v1.23.6/bin/linux/amd64/kubectl"
install kubectl /usr/local/bin/kubectl
# Use EKS to setup the Kubeconfig file with the aws token creation
- name: Setup EKS
run: |
aws eks --region ${{ inputs.AWS_REGION }} update-kubeconfig --name ${{ inputs.cluster }} --role-arn arn:aws:iam::621897733001:role/eksClusterRole
# Add the Helm Charts for the kamma repo
- name: Deliverybot Helm Action
id: helm
run: |
helm repo add kamma-charts https://kammadata.github.io/kamma-charts
export HELM_COMMAND="helm upgrade --install ${{ inputs.project }}-${{ steps.release.outputs.name }} --set environment=${{ inputs.namespace }} --set ingress.host=${{ steps.ingress.outputs.name }} --set image.registry=${ECR_REGISTRY} --set image.repository=${{ inputs.project }} --set image.tag=${{ inputs.image-tag }} --set database.host=${{ inputs.DATABASE_HOST }} --set database.name=${{ inputs.project }}-${{ steps.release.outputs.name }} ${{ inputs.chart }}"
$HELM_COMMAND
echo "::set-output name=command::$(echo "${HELM_COMMAND}")"
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
- name: Post to a Slack channel.
id: slack
uses: slackapi/[email protected]
with:
channel-id: C011YADU2V8
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "A new deployment has been completed:\n*<${{ env.DEPLOYMENT_WORKFLOW_URL }}|Deploy to Cluster>*"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Type:* ${{ env.DEPLOYMENT_TYPE }}\n*Ingress:* <https://${{ env.DEPLOYMENT_INGRESS }}|${{ env.DEPLOYMENT_INGRESS }}>\n*Image:* ${{ env.DEPLOYMENT_IMAGE }}\n*Reference:* ${{ env.DEPLOYMENT_REFERENCE }}\n*Namespace:* ${{ env.DEPLOYMENT_NAMESPACE }}\n*Chart:* ${{ env.DEPLOYMENT_CHART }}"
}
},
{
"type": "divider"
},
{
"type": "context",
"elements": [
{
"type": "plain_text",
"text": "kamma kube logs ${{ env.DEPLOYMENT_REFERENCE }}",
"emoji": true
}
]
},
{
"type": "context",
"elements": [
{
"type": "plain_text",
"text": "kamma kube shell ${{ env.DEPLOYMENT_REFERENCE }}",
"emoji": true
}
]
},
{
"type": "context",
"elements": [
{
"type": "plain_text",
"text": "kubectl get pods ${{ env.DEPLOYMENT_REFERENCE }}",
"emoji": true
}
]
},
{
"type": "context",
"elements": [
{
"type": "plain_text",
"text": "helm uninstall ${{ env.DEPLOYMENT_REFERENCE }}",
"emoji": true
}
]
},
{
"type": "context",
"elements": [
{
"type": "plain_text",
"text": "${{ env.DEPLOYMENT_HELM_COMMAND }}",
"emoji": true
}
]
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
DEPLOYMENT_TYPE: "${{ github.event_name }}"
DEPLOYMENT_WORKFLOW_URL: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
DEPLOYMENT_INGRESS: "${{ steps.ingress.outputs.name }}"
DEPLOYMENT_IMAGE: "${{ inputs.image-tag }}"
DEPLOYMENT_IMAGE_URL: "https://${{ steps.login-ecr.outputs.registry }}/${{ inputs.project }}:${{ inputs.image-tag }}"
DEPLOYMENT_REFERENCE: "${{ inputs.project }}-${{ steps.release.outputs.name }}"
DEPLOYMENT_NAMESPACE: "${{ inputs.namespace }}"
DEPLOYMENT_CHART: "${{ inputs.chart }}"
DEPLOYMENT_HELM_COMMAND: "${{ steps.helm.outputs.command }}"