Restart Phala CVM #12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |