-
Notifications
You must be signed in to change notification settings - Fork 64
39 lines (36 loc) · 1.54 KB
/
Copy pathphala.yml
File metadata and controls
39 lines (36 loc) · 1.54 KB
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
name: Restart Phala CVM
on:
workflow_run:
workflows: ["Build and push Docker images"]
types:
- completed
jobs:
phala:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Restart Phala CVM
env:
PHALA_CLOUD_API_KEY: ${{ secrets.PHALA_CLOUD_API_KEY }}
PHALA_CLOUD_CVM_ID: ${{ secrets.PHALA_CLOUD_CVM_ID }}
run: |
echo "🚀 Preparing to restart Phala CVM..."
REQUIRED=(PHALA_CLOUD_API_KEY PHALA_CLOUD_CVM_ID)
for var in "${REQUIRED[@]}"; do
if [ -z "${!var}" ]; then
echo "❌ Error: $var environment variable is missing, please check repository Secrets."
exit 1
fi
done
echo "Calling Phala API to send restart request..."
RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}\n" -X POST "https://cloud-api.phala.com/api/v1/cvms/$PHALA_CLOUD_CVM_ID/restart" \
-H "x-api-key: $PHALA_CLOUD_API_KEY" \
-H "Content-Type: application/json" \
-d '{"force":true}')
HTTP_STATUS=$(echo "$RESPONSE" | grep "HTTP_STATUS" | tail -n 1 | awk -F":" '{print $2}')
if [ "$HTTP_STATUS" -eq 200 ] || [ "$HTTP_STATUS" -eq 201 ] || [ "$HTTP_STATUS" -eq 204 ]; then
echo "✅ Successfully triggered Phala CVM ($PHALA_CLOUD_CVM_ID) restart!"
else
echo "❌ Failed to trigger Phala CVM restart! (HTTP Status: $HTTP_STATUS)"
exit 1
fi