-
Notifications
You must be signed in to change notification settings - Fork 0
215 lines (193 loc) · 7.21 KB
/
deploy-with-bratiska-cli-inhouse.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
name: General workflow which initialize kubernetes with docker and runs bratiska-cli for deployment.
on:
workflow_call:
inputs:
runs-on:
description: 'Define the type of machine to run the job on'
type: string
required: false
default: '["self-hosted", "Linux", "X64", "bratislava"]'
directory:
description: 'A Folder within the repository where deployment should be called'
default: '/'
required: false
type: string
registry:
description: 'Registry where should be built images stored'
default: 'harbor.bratislava.sk'
required: false
type: string
namespace:
description: 'Namespace where should be build app deployed'
default: 'standalone'
required: false
type: string
flag:
description: 'Staging or production flag'
default: ''
required: false
type: string
debug:
description: 'Debug flag'
default: ''
required: false
type: string
cluster:
description: 'Kubernetes cluster name'
default: 'tkg-innov-dev'
required: true
type: string
url:
description: 'Kubernetes cluster url'
default: 'https://tkg.dev.bratislava.sk'
required: true
type: string
username:
description: 'Harbor username'
default: 'robot$github_actions'
required: false
type: string
docker-username:
description: 'Docker username'
default: 'bratislava'
required: false
type: string
version:
description: 'Bratiska-cli version'
default: 'stable'
required: false
type: string
skip_deployment_check:
description: 'Flag - skip checking if the kubernetes deployment was deployed successfully'
default: ''
required: false
type: string
build_arg:
description: 'Defining build arg for Dockerfile'
default: ''
required: false
type: string
fetch-depth:
description: 'Defining fetch-depth'
default: 0
required: false
type: number
slack-channel:
description: 'Channel for slack notification '
default: "alerts-pipelines"
required: false
type: string
secrets:
sentry-token:
description: 'Token used for sentry debugging.'
required: false
registry-pass:
description: 'Password for registry where docker is uploading images'
required: true
service-account:
# kubectl get secret <service account secret> -n=standalone -o jsonpath='{.data.token}' | base64 --decode > token.tmp
description: 'Kubernetes service account'
required: true
docker-pass:
description: 'Password for docker registry.'
required: false
slack-token:
description: 'Slackbot token'
required: false
jobs:
deploy-with-bratiska-cli:
name: Build and deploy with bratiska-cli
runs-on: ${{fromJSON(inputs.runs-on)}}
defaults:
run:
working-directory: ${{ inputs.directory }}
steps:
- name: Checking out
uses: actions/checkout@v4
with:
fetch-depth: ${{ inputs.fetch-depth }}
- name: Pipelines Version
run: |
echo "Pipelines version: 2.4.0"
- name: Directory check
run: pwd
- name: Print pipeline summary
run: |
echo "### Bratiska-cli is deploying:" >> $GITHUB_STEP_SUMMARY
echo ":arrow_right: Cluster: **${{ inputs.cluster }}**" >> $GITHUB_STEP_SUMMARY
echo ":arrow_right: Project folder: **${{ inputs.directory }}**" >> $GITHUB_STEP_SUMMARY
echo ":arrow_right: Namespace: **${{ inputs.namespace }}**" >> $GITHUB_STEP_SUMMARY
- name: Install Prerequisites - Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Installing Bratiska-cli ${{ inputs.version }}
run: |
yarn global add bratislava/bratiska-cli#${{ inputs.version }}
echo "~/.yarn/bin" >> $GITHUB_PATH
- name: Kubectl tool installer
uses: Azure/[email protected]
- name: Kubernetes set service account token
# to obtain token run: kubectl get secret <service account secret> -n=standalone -o jsonpath='{.data.token}' | base64 --decode > token.tmp
run: kubectl config set-credentials default --token=${{ secrets.service-account }}
- name: Kubernetes set server with certificate account token
run: kubectl config set-cluster ${{ inputs.cluster }} --insecure-skip-tls-verify --server=${{ inputs.url }}
- name: Kubernetes set context cluster
run: kubectl config set-context ${{ inputs.cluster }} --cluster=${{ inputs.cluster }} --user=default
- name: Kubernetes use context
run: kubectl config use-context ${{ inputs.cluster }}
- name: Login to Harbor
uses: docker/[email protected]
with:
registry: ${{ inputs.registry }}
username: ${{ inputs.username }}
password: ${{ secrets.registry-pass }}
- name: Check for Docker secret availability
id: docker-check
shell: bash
run: |
if [ "${{ secrets.docker-pass }}" != '' ]; then
echo "available=true" >> $GITHUB_OUTPUT;
else
echo "available=false" >> $GITHUB_OUTPUT;
fi
- name: Login to Docker
if: ${{ steps.docker-check.outputs.available == 'true' }}
uses: docker/[email protected]
with:
username: ${{ inputs.docker-username }}
password: ${{ secrets.docker-pass }}
- name: Get current branch name
if: github.event_name != 'pull_request'
run: |
raw=$(git branch -r --contains ${{ github.ref }})
branch=${raw##*/}
echo "GITHUB_BRANCH=$branch" >> $GITHUB_ENV
- name: Prints the current branch name
run: echo ${{ env.GITHUB_BRANCH }}
- name: Print Bratiska-cli version
run: bratiska-cli deploy --version
- name: Running build and deploy with Bratiska-cli
run: bratiska-cli deploy ${{ inputs.flag }} --namespace=${{ inputs.namespace }} --sentry=${{ secrets.sentry-token }} ${{ inputs.build_arg }} ${{ inputs.debug }} ${{ inputs.skip_deployment_check }}
continue-on-error: false
- name: Print pipeline summary
run: |
echo "### Deployment summary :ship:" >> $GITHUB_STEP_SUMMARY
echo ":partying_face: Bratiska-cli successfully deployed to ${{ inputs.cluster }}" >> $GITHUB_STEP_SUMMARY
- name: Check for Slack secret availability
id: slack-check
if: always()
shell: bash
run: |
if [ "${{ secrets.slack-token }}" != '' ]; then
echo "available=true" >> $GITHUB_OUTPUT;
else
echo "available=false" >> $GITHUB_OUTPUT;
fi
- name: Slack Report
if: ${{ always() && steps.slack-check.outputs.available == 'true' }}
uses: kpritam/slack-job-status-action@v1
with:
job-status: ${{ job.status }}
slack-bot-token: ${{ secrets.slack-token }}
channel: ${{ inputs.slack-channel }}