-
Notifications
You must be signed in to change notification settings - Fork 0
218 lines (198 loc) · 8.14 KB
/
14addcyclecloud.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
name: 14addcyclecloud
on:
workflow_run:
workflows: ["01azure_deploy"]
branches: [main]
types:
- completed
push:
paths:
- senarios/cyclecloud
jobs:
cyclecloud_deploy:
runs-on: ubuntu-latest
# on.push.paths と on.push.branch の && は利用できないため回避策
if: github.ref == 'refs/heads/main'
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 }}
# Map a step output to a job output
outputs:
output1: ${{ steps.step1.outputs.test }}
output2: ${{ steps.step2.outputs.test }}
output3: ${{ steps.step3.outputs.test }}
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: add cyclecloud"
env:
SSH_SECRET_KEY: ${{ secrets.SSH_SECRET_KEY }}
SSH_PUBLIC_KEY: ${{ secrets.SSH_PUBLIC_KEY }}
run: |
# 設定ファイル変更反映: addcyclecloud.shの場合、hpcbmtenv.sh, addcyclecloud.sh, cyc.sh 3つ必要
bash ./setupcreds.sh hpcbmtenv.sh
bash ./setupcreds.sh addcyclecloud.sh
bash ./setupcreds.sh cyclesetting.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=" ./addcyclecloud.sh | head -n 1
grep "VMPREFIX=" ./addcyclecloud.sh | head -n 1
grep "azure_*" ./addcyclecloud.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
sed -i -e 's!^#azure_name="uuid"!azure_name="${{ secrets.AZURE_NAME }}"!' ./addcyclecloud.sh
sed -i -e 's!^#azure_password="uuid"!azure_password="${{ secrets.AZURE_PASSWORD }}"!' ./addcyclecloud.sh
sed -i -e 's!^#azure_tenant="uuid"!azure_tenant="${{ secrets.AZURE_TENANT }}"!' ./addcyclecloud.sh
sed -i -e 's!^#azure_name="uuid"!azure_name="${{ secrets.AZURE_NAME }}"!' ./cyclesetting.sh
sed -i -e 's!^#azure_password="uuid"!azure_password="${{ secrets.AZURE_PASSWORD }}"!' ./cyclesetting.sh
sed -i -e 's!^#azure_tenant="uuid"!azure_tenant="${{ secrets.AZURE_TENANT }}"!' ./cyclesetting.sh
# Update NSG
bash ./hpcbmtenv.sh updatensg
# Azure CycleCloud 構築
echo "create cyclecloud..."
bash ./addcyclecloud.sh
# Azure CycleCloud 設定
echo "postinstall cyclecloud setting..."
bash ./cyclesetting.sh
- name: Create file status_cyclecloud.txt and write the job status into it
if: always()
run: |
echo ${{ job.status }} > status_cyclecloud.txt
- name: Upload file status_cyclecloud.txt as an artifact
if: always()
uses: actions/upload-artifact@v1
with:
name: pass_status_cyclecloud
path: status_cyclecloud.txt
success:
name: cyclecloud-success_teams_notification
runs-on: ubuntu-18.04
needs: [cyclecloud_deploy]
steps:
- uses: actions/checkout@master
- name: Microsoft Teams Notification
uses: skitionek/notify-microsoft-teams@master
with:
webhook_url: ${{ secrets.MSTEAMS_WEBHOOK }}
needs: ${{ toJson(needs) }}
job: ${{ toJson(job) }}
steps: ${{ toJson(steps) }}
dry_run: False
- name: sucuess!
run: |
echo '::success::cyclecloud_deploy(and config) was sucuess!'
setup_failure:
name: setup_failure
runs-on: ubuntu-latest
needs: cyclecloud_deploy
steps:
- name: setup_failure
uses: actions/checkout@v2
- name: dummy
run: uname -a
deploy_failure:
name: cyclecloud-failure_teams_notification
runs-on: ubuntu-latest
needs: setup_failure
if: always()
outputs:
status_cyclecloud: ${{ steps.set_outputs_cyclecloud.outputs.status_cyclecloud }}
steps:
- uses: actions/checkout@master
- name: Download artifact pass_status_cyclecloud
uses: actions/download-artifact@v1
with:
name: pass_status_cyclecloud
- name: Set the statuses of cyclecloud as output parameters
id: set_outputs_cyclecloud
run: |
echo "::set-output name=status_cyclecloud::$(<pass_status_cyclecloud/status_cyclecloud.txt)"
echo "::set-output name=pass_status_cyclecloud::$(<pass_status_cyclecloud/status_cyclecloud.txt)"
- name: check_failure
if: steps.set_outputs_cyclecloud.outputs.status_cyclecloud == 'failure'
run: |
echo "steps.set_outputs_cyclecloud.outputs.status_cyclecloud: ${{ steps.set_outputs_cyclecloud.outputs.status_cyclecloud }}"
exit 1
- name: Microsoft Teams Notification
uses: skitionek/notify-microsoft-teams@master
if: failure()
with:
webhook_url: ${{ secrets.MSTEAMS_WEBHOOK }}
needs: ${{ toJson(needs) }}
job: ${{ toJson(job) }}
steps: ${{ toJson(steps) }}
dry_run: False
add_label:
runs-on: ubuntu-latest
needs: [success]
steps:
- uses: actions/checkout@master
- name: Download artifact
uses: dawidd6/action-download-artifact@v2
with:
# Optional, GitHub token
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Required, workflow file name or ID
workflow: 01azure_deploy.yml
# Optional, the status or conclusion of a completed workflow to search for
# Can be one of a workflow conclusion::
# "failure", "success", "neutral", "cancelled", "skipped", "timed_out", "action_required"
# Or a workflow status:
# "completed", "in_progress", "queued"
# Default: "completed,success"
###workflow_conclusion: success
# Optional, will use specified workflow run
#run_id: 1122334455
# Optional, run number from the workflow
#run_number: 34
name: pass_status_cardid
# Optional, directory where to extract artifact
#path: status_cardid.txt
- name: Set the statuses of status_cardid as output parameters
id: set_outputs_cardid
run: |
echo "cat ./pass_status_cardid/status_cardid.txt"
echo "::set-output name=status_cardid::$(<status_cardid.txt)"
echo "::set-output name=issue_number::$(<status_cardid.txt)"
- name: Add label
uses: actions-ecosystem/action-add-labels@v1
with:
labels: |
azurewf01
01a_done
02p_done
03c_done
number: ${{ steps.set_outputs_cardid.outputs.status_cardid }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}