Back to articles
DevOps & Systems

Integrating VPS with GitHub Actions: Building a Professional CI/CD Pipeline for Personal Projects

This guide details how to integrate a VPS with GitHub Actions to build a professional CI/CD pipeline, automating development, testing, and deployment for personal projects. It...

DPTCloud Engineering4 min read
Integrating VPS with GitHub Actions: Building a Professional CI/CD Pipeline for Personal Projects

This guide details how to integrate a VPS with GitHub Actions to build a professional CI/CD pipeline, automating development, testing, and deployment for personal projects. It covers SSH key setup, workflow configuration, automated deployment, and verification steps to ensure system stability and security.

Introduction to CI/CD and Benefits for Personal Projects

CI/CD (Continuous Integration / Continuous Deployment) is a core DevOps practice that automates code testing and deployment. For personal projects, building a professional CI/CD pipeline reduces errors, accelerates development, and ensures code stability. GitHub Actions, an integrated CI/CD platform, enables you to define workflows that automatically run when changes are pushed to your repository.

Integrating a VPS with GitHub Actions allows you to deploy code directly to your server without manual steps. This is especially useful when you want full control over your deployment environment, using technologies like Docker, Nginx, or databases on your VPS. With NVMe Cloud VPS solutions such as those offered at NVMe Cloud VPS for Docker, Nginx & Databases, you can leverage high performance to run applications and CI/CD pipelines smoothly.

Setting Up SSH Keys to Connect GitHub Actions to VPS

To allow GitHub Actions to connect and deploy to your VPS, you need to generate an SSH key pair and add the public key to your VPS. Start by generating the SSH key on your local machine:

ssh-keygen -t ed25519 -C "github-actions@vps" -f ~/.ssh/github_actions

After generating the key, copy the public key to your VPS using the following command:

ssh-copy-id -i ~/.ssh/github_actions.pub user@your-vps-ip

Replace user with your VPS username and your-vps-ip with your VPS IP address. Once connected, add the SSH key to your GitHub repository as a secret.

Configuring GitHub Actions Workflow

In your repository, create a .github/workflows directory and add a deploy.yml file. Below is a simple example workflow for deploying a Node.js application to your VPS:

name: Deploy to VPS

on:
  push:
    branches: [ main ]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Deploy to VPS
        uses: appleboy/ssh-action@v1
        with:
          host: ${{ secrets.VPS_HOST }}
          username: ${{ secrets.VPS_USER }}
          key: ${{ secrets.VPS_SSH_KEY }}
          port: 22
          script: |
            cd /home/user/myproject
            git pull origin main
            npm install
            npm run build
            pm2 restart app

Set the following secrets in your GitHub repository:

  • VPS_HOST: The VPS IP address or domain name.
  • VPS_USER: The username on the VPS.
  • VPS_SSH_KEY: The private SSH key encoded in base64.

To create a secret, go to your repository, select Settings → Secrets and variables → Actions → New repository secret. Enter the secret name and value.

Automating Testing and Deployment

After configuring the workflow, every push to the main branch triggers the pipeline. The process includes:

  1. Checking out the source code from the repository.
  2. Connecting to the VPS via SSH.
  3. Automatically updating the code, installing dependencies, and restarting the application.

To verify the pipeline works, make a small commit and check the workflow status in the Actions tab of your repository. If successful, you should see deployment logs on your VPS.

Troubleshooting and Security

During deployment, you may encounter issues such as SSH connection refused, permission denied, or script execution errors. To resolve:

  • Ensure the SSH key is correctly added to the VPS.
  • Check the VPS firewall to allow connections from GitHub Actions.
  • Verify that the commands in the script run properly on the VPS.

To enhance security:

  • Avoid storing SSH keys in source code.
  • Use GitHub secrets instead of hardcoding sensitive information.
  • Limit SSH key access permissions.

Integrating VPS with GitHub Actions enables a professional CI/CD pipeline, automating development and deployment for personal projects. With technologies like Docker and Nginx supported on NVMe VPS, you can deploy scalable applications efficiently and reliably.

Related infrastructure & engineering guides: Review of Top VPS Control Panels Available Today

DPTCloud Tier III Infrastructure

Recommended NVMe Cloud VPS Plans to Deploy This Setup

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02

VPS-2E

94.600 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 2 GB
  • SSD: 30 GB NVMe
ECO · vn-02Recommended

VPS-3E

170.500 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 4 GB
  • SSD: 50 GB NVMe
BASIC · vn-01Recommended

VPS-05

457.600 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478