-
Notifications
You must be signed in to change notification settings - Fork 0
261 lines (235 loc) · 8.85 KB
/
01azure_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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
name: 01azure_deploy
on:
push:
branches: [main]
paths:
- senarios/basicdeploy
jobs:
# 作成された issue をプロジェクトに自動登録するためのジョブ
issue_generate:
name: Creating the issue for the project01
runs-on: ubuntu-latest
# on.push.paths と on.push.branch の && は利用できないため回避策
if: github.ref == 'refs/heads/main'
outputs:
issue-number: ${{ steps.set_outputs_cardid.outputs.issue-number }}
steps:
# Repo code checkout required if `template` is used
- name: Checkout
uses: actions/checkout@v2
# https://stackoverflow.com/a/60942437
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y/%m/%d-%H:%m')"
# 作成された issue をプロジェクトに自動登録
- name: Creating new deployment project card
id: set_outputs_cardid
uses: imjohnbo/issue-bot@v3.3.0
with:
title: AzureDeployment - ${{ steps.date.outputs.date }}
assignees: "hirtanak"
labels: "azurewf01"
project: 1 # project01, number is 1
column: "In progress"
milestone: 1
body: |-
:wave: Hi, {{#each assignees}}@{{this}}{{#unless @last}}, {{/unless}}{{/each}}!
pinned: false
close-previous: false
# template: ".github/ISSUE_TEMPLATE/generate_issuelist.md"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create file status_cardid.txt and write the cardid status into it
id: set_outputs_cardid2
if: always()
run: |
echo ${{ steps.set_outputs_cardid.outputs.issue-number }} > status_cardid.txt
- name: Upload file status_cardid.txt as an artifact
if: always()
uses: actions/upload-artifact@v1
with:
name: pass_status_cardid
path: status_cardid.txt
- name: Create or Update Project Card
uses: peter-evans/create-or-update-project-card@v1
with:
project-name: project01
column-name: deploying
issue-number: ${{ steps.set_outputs_cardid.outputs.issue-number }}
azure_deploy:
runs-on: ubuntu-latest
needs: issue_generate
env:
MyResourceGroup: tmcbmgt01-hpccicd01
VMPREFIX: hpccicd01
# secret
AZURE_NAME: ${{ secrets.AZURE_NAME }}
AZURE_PASSWORD: ${{ secrets.AZURE_PASSWORD }}
AZURE_TENANT: ${{ secrets.AZURE_TENANT }}
SSH_SECRET_KEY: ${{ secrets.SSH_SECRET_KEY }}
SSH_PUBLIC_KEY: ${{ secrets.SSH_PUBLIC_KEY }}
steps:
# スクリプト実行には事前にリポジトリのチェックアウトが必要
- name: Check out repository
uses: actions/checkout@v2
- name: "prep run script1"
run: |
echo "RG: ${MyResourceGroup}"
echo "VMPREFIX: ${VMPREFIX}"
# check environment
uname -a
cat /etc/debian_version
echo "GITHUB_ENV: $GITHUB_ENV"
# actだと必要。github actionsだとPermissionエラーになる
#sudo apt-get -qq update
#sudo apt-get -qq -y install libxml2-utils curl openssh-server
#apt-get -qq -y install curl openssh-server || sudo apt-get -qq -y install curl openssh-server
curl -V
# curl -sL https://aka.ms/InstallAzureCLIDeb | bash
# github actions だとsudoが必要
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
az version -o table
- name: "run script"
env:
SSH_SECRET_KEY: ${{ secrets.SSH_SECRET_KEY }}
SSH_PUBLIC_KEY: ${{ secrets.SSH_PUBLIC_KEY }}
run: |
# 設定ファイル変更反映
bash ./setupcreds.sh hpcbmtenv.sh
# SSH秘密鍵の設定
echo "setting ssh private key...."
echo "$SSH_SECRET_KEY" > ./${VMPREFIX}
md5sum ./${VMPREFIX}
# SSH公開鍵の設定
echo "setting ssh public key...."
echo "$SSH_PUBLIC_KEY" > ./${VMPREFIX}.pub
md5sum ./${VMPREFIX}.pub
grep "MyResourceGroup=" ./hpcbmtenv.sh | head -n 1
grep "VMPREFIX=" ./hpcbmtenv.sh | head -n 1
grep "MAXVM=" ./hpcbmtenv.sh | head -n 1
grep "azure_*" ./hpcbmtenv.sh | head -n 2
# クルデンシャル
sed -i -e 's!^#azure_name="uuid"!azure_name="${{ secrets.AZURE_NAME }}"!' ./hpcbmtenv.sh
sed -i -e 's!^#azure_password="uuid"!azure_password="${{ secrets.AZURE_PASSWORD }}"!' ./hpcbmtenv.sh
sed -i -e 's!^#azure_tenant="uuid"!azure_tenant="${{ secrets.AZURE_TENANT }}"!' ./hpcbmtenv.sh
# スクリプト実行:作成
bash ./hpcbmtenv.sh updatensg
bash ./hpcbmtenv.sh create
- name: Create file status_azure_deploy.txt and write the job status into it
if: always()
run: |
echo ${{ job.status }} > status_azure_deploy.txt
- name: Upload file status_azure_deploy.txt as an artifact
if: always()
uses: actions/upload-artifact@v1
with:
name: pass_status_azure_deploy
path: status_azure_deploy.txt
success:
name: azure_deploy-success_teams_notification
runs-on: ubuntu-18.04
needs: [azure_deploy]
steps:
- uses: actions/checkout@master
- name: Microsoft Teams Notification
uses: skitionek/notify-microsoft-teams@master
if: always()
with:
webhook_url: ${{ secrets.MSTEAMS_WEBHOOK }}
needs: ${{ toJson(needs) }}
job: ${{ toJson(job) }}
steps: ${{ toJson(steps) }}
dry_run: False
- name: sucuess!
run: |
echo '::success::Previous workflow was sucuess!'
# ステータスチェック・テストジョブ
checkcontext:
runs-on: ubuntu-latest
needs: [success]
steps:
- run: |
echo "The job context is:"
echo "${{ toJson(job) }}"
echo ""
echo "The steps context is:"
echo "${{ toJson(steps) }}"
echo ""
echo "The runner context is:"
echo "${{ toJson(runner) }}"
echo ""
echo "The strategy context is:"
echo "${{ toJson(strategy) }}"
echo ""
echo "The matrix context is:"
echo "${{ toJson(matrix) }}"
add_label:
runs-on: ubuntu-latest
needs: [checkcontext]
steps:
- uses: actions/checkout@master
- name: Download artifact pass_status_pingpong
uses: actions/download-artifact@v1
with:
name: pass_status_cardid
- name: Set the statuses of pingpong as output parameters
id: set_outputs_cardid
run: |
echo "::set-output name=status_cardid::$(<pass_status_cardid/status_cardid.txt)"
- name: Add label
uses: actions-ecosystem/action-add-labels@v1
with:
labels: |
azurewf01
01a_done
number: ${{ steps.set_outputs_cardid.outputs.status_cardid }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
setup_failure:
name: setup_failure
runs-on: ubuntu-latest
needs: azure_deploy
steps:
- name: setup_failure
uses: actions/checkout@v2
- name: dummy
run: uname -a
deploy_failure:
name: azure_deploy-failure_teams_notification
runs-on: ubuntu-latest
needs: setup_failure
if: always()
outputs:
status_azure_deploy: ${{ steps.set_outputs.outputs.status_azure_deploy }}
steps:
# job azure_deploy の結果を得る
#- name: Getting azure_deploy result
# uses: technote-space/workflow-conclusion-action@v2
#- run: |
# echo "show the workflow conclusion"
# echo ${{ env.WORKFLOW_CONCLUSION }}
- uses: actions/checkout@master
- name: Download artifact pass_status_azure_deploy
uses: actions/download-artifact@v1
with:
name: pass_status_azure_deploy
- name: Set the statuses of azure_deploy as output parameters
id: set_outputs
run: |
echo "::set-output name=status_azure_deploy::$(<pass_status_azure_deploy/status_azure_deploy.txt)"
echo "::set-output name=pass_status_azure_deploy::$(<pass_status_azure_deploy/status_azure_deploy.txt)"
- name: check_failure
#if: ${{ needs.deploy_failure.outputs.azure_deploy }} == 'failure'
if: steps.set_outputs.outputs.status_azure_deploy == 'failure'
run: |
echo "steps.set_outputs.outputs.status_azure_deploy: ${{ steps.set_outputs.outputs.status_azure_deploy }}"
exit 1
- name: Microsoft Teams Notification
uses: skitionek/notify-microsoft-teams@master
#if: env.WORKFLOW_CONCLUSION == 'failure' # notify only if failure
if: failure()
with:
webhook_url: ${{ secrets.MSTEAMS_WEBHOOK }}
needs: ${{ toJson(needs) }}
job: ${{ toJson(job) }}
steps: ${{ toJson(steps) }}
dry_run: False