Skip to content

hostinger/deploy-on-vps

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Deploy to Hostinger VPS GitHub Action

GitHub Marketplace License: MIT

Deploy your Docker applications to Hostinger VPS with ease using GitHub Actions.

Features

  • πŸš€ Easy Deployment: Deploy Docker applications with a simple workflow configuration
  • πŸ”’ Private Repository Support: Works with both public and private GitHub repositories
  • πŸ”§ Environment Variables: Pass environment variables to your Docker containers

Prerequisites

  • A Hostinger VPS with Docker installed
  • Hostinger API key (available in your Hostinger dashboard)
  • A docker-compose.yml file in your repository
  • For private repositories - SSH Deploy key

Usage

Basic Usage (Public Repository)

name: Deploy to Hostinger

on:
  push:
    branches: [ main ]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      
      - name: Deploy to Hostinger
        uses: hostinger/deploy-on-vps@v2
        with:
          api-key: ${{ secrets.HOSTINGER_API_KEY }}
          virtual-machine: ${{ vars.HOSTINGER_VM_ID }}

Advanced Usage (environment variables, custom docker compose path)

name: Deploy to Hostinger

on:
  push:
    branches: [ main, production ]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      
      - name: Deploy to Hostinger
        uses: hostinger/deploy-on-vps@v2
        with:
          api-key: ${{ secrets.HOSTINGER_API_KEY }}
          virtual-machine: ${{ vars.HOSTINGER_VM_ID }}
          project-name: my-awesome-app
          docker-compose-path: docker/docker-compose.yml
          environment-variables: |
            NODE_ENV=production
            API_URL=https://api.example.com
            DATABASE_URL=${{ secrets.DATABASE_URL }}

Inputs

Input Description Required Default
api-key Hostinger API key for authentication Yes -
virtual-machine Virtual machine ID where the application will be deployed Yes -
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 -

Setting up Secrets

  1. Get your Hostinger API Key:

  2. Get your Virtual Machine ID:

    • Go to your VPS overview dashboard
    • Find the VM ID:
  3. Add secrets to GitHub:

    • Go to your repository β†’ Settings β†’ Secrets and variables β†’ Actions
    • Add the following secrets:
      • HOSTINGER_API_KEY: Your Hostinger API key
    • Add the following variables:
      • HOSTINGER_VM_ID: Your Hostinger VM ID
  4. For private repositories:

    • Generate an SSH key in your VPS (if not yet generated)
    • Add your SSH deployment key to private repository by visiting url https://github.com/<owner name>/<your repo name>/settings/keys
    • You can find more information how to do that in Hostinger documentation

Environment Variables

You can pass environment variables in multiple formats:

environment-variables: |
  NODE_ENV=production
  PORT=3000
  DEBUG=false
  API_KEY=${{ secrets.API_KEY }}

Docker Compose File

Your repository should contain a docker-compose.y(a)ml / compose.y(a)ml file. Example:

services:
  web:
    build: .
    ports:
      - "80:3000"
    environment:
      - NODE_ENV=${NODE_ENV:-development}
      - PORT=${PORT:-3000}
    restart: unless-stopped

Examples

Deploy on Tag Creation

name: Deploy on Tag

on:
  push:
    tags:
      - 'v*'

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      
      - name: Deploy to Hostinger
        uses: hostinger/deploy-on-vps@v2
        with:
          api-key: ${{ secrets.HOSTINGER_API_KEY }}
          virtual-machine: ${{ vars.HOSTINGER_VM_ID }}
          project-name: my-app-${{ github.ref_name }}

Multi-Environment Deployment

name: Multi-Environment Deploy

on:
  push:
    branches: [ main, staging ]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      
      - name: Set environment
        id: env
        run: |
          if [ "${{ github.ref }}" == "refs/heads/main" ]; then
            echo "vm_id=${{ vars.PROD_VM_ID }}" >> $GITHUB_OUTPUT
            echo "env_vars=NODE_ENV=production" >> $GITHUB_OUTPUT
          else
            echo "vm_id=${{ vars.STAGING_VM_ID }}" >> $GITHUB_OUTPUT
            echo "env_vars=NODE_ENV=staging" >> $GITHUB_OUTPUT
          fi
      
      - name: Deploy to Hostinger
        uses: hostinger/deploy-on-vps@v2
        with:
          api-key: ${{ secrets.HOSTINGER_API_KEY }}
          virtual-machine: ${{ steps.env.outputs.vm_id }}
          environment-variables: ${{ steps.env.outputs.env_vars }}

Support

For issues and feature requests, please create an issue on GitHub.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Packages

 
 
 

Contributors