Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ jobs:
| `project-name` | Name of the project for identification | No | `${{ github.repository }}` |
| `environment-variables` | Environment variables (KEY=value format, newline separated) | No | - |
| `docker-compose-path` | Path to docker-compose.yml file (will be detected automatically otherwise) | No | - |
| `force-delete-project` | Delete original project if exists, to allow a clean deployment | No | `false` |

## Setting up Secrets

Expand Down
60 changes: 58 additions & 2 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy on Hostinger VPS
name: Deploy on Hostinger VPS Project Down
author: Hostinger
description: Deploy your dockerized application on Hostinger VPS instance

Expand All @@ -25,6 +25,10 @@ inputs:
description: 'Relative path to docker-compose.yml file from repository root'
required: false
default: ""
force-delete-project:
description: 'Force delete the running project if exists, before deployment'
required: false
default: "false"

runs:
using: composite
Expand Down Expand Up @@ -52,6 +56,58 @@ runs:

echo "url=$URL" >> $GITHUB_OUTPUT

- name: Delete project if force-delete-project enabled
if: inputs.force-delete-project == 'true'
shell: bash
run: |
echo "🗑️ Force delete enabled. Attempting to delete running container..."
echo "📦 Project: ${{ inputs.project-name }}"
echo "🖥️ VM: ${{ inputs.virtual-machine }}"

RESPONSE=$(curl -s -w "\n%{http_code}" -X DELETE \
-H "Authorization: Bearer ${{ inputs.api-key }}" \
-H "Content-Type: application/json" \
"https://developers.hostinger.com/api/vps/v1/virtual-machines/${{ inputs.virtual-machine }}/docker/${{ inputs.project-name }}/down")

# Extract response body and status code
HTTP_BODY=$(echo "$RESPONSE" | sed '$d')
HTTP_STATUS=$(echo "$RESPONSE" | tail -n1)

# Check if API response
if [ "$HTTP_STATUS" -ge 200 ] && [ "$HTTP_STATUS" -lt 300 ]; then
echo "✅ Container deleted successfully!"
else
echo "⚠️ Failed to delete container with status code: $HTTP_STATUS"

# Try to parse error message
if command -v jq &> /dev/null && [ -n "$HTTP_BODY" ]; then
ERROR_MSG=$(echo "$HTTP_BODY" | jq -r '.message' 2>/dev/null || echo "")
if [ -n "$ERROR_MSG" ]; then
echo "Error: $ERROR_MSG"
else
echo "$HTTP_BODY"
fi
else
echo "$HTTP_BODY"
fi

case $HTTP_STATUS in
401)
echo "🔑 Hint: Check if your API key is valid and has the necessary permissions."
;;
404)
echo "🔍 Hint: Verify that the virtual machine ID '${{ inputs.virtual-machine }}' exists."
;;
422)
echo "⚠️ Hint: The request data might be invalid. Check your docker-compose file format."
;;
500|502|503)
echo "🔧 Hint: Server error. The Hostinger API might be experiencing issues. Try again later."
;;
esac
Comment thread
Archi657 marked this conversation as resolved.
echo "ℹ️ Continuing with deployment anyway..."
fi

- name: Deploy to Hostinger
shell: bash
run: |
Expand Down Expand Up @@ -127,4 +183,4 @@ runs:
echo "🖥️ VM: ${{ inputs.virtual-machine }}"
echo "🔄 Commit: ${{ github.sha }}"
echo "👤 Triggered by: ${{ github.actor }}"
echo "======================================"
echo "======================================"