Automating Deployments with GitHub Actions and SSH
Manual git pull and service restarts on your remote server are prone to human error and slow down your iteration cycle. True developer efficiency comes from fully automated Continuous Integration and Continuous Deployment (CI/CD).
This guide demonstrates how to set up a lightweight automated deployment pipeline from GitHub to your Starlight VPS.
The Deployment Workflow Concept
- Push to Main: You push code updates to your GitHub repository.
- Trigger Runner: GitHub Actions triggers a workflow runner.
- SSH Remote Execution: The runner securely logs into your VPS via SSH, pulls the latest code, and restarts your Docker containers.
Setting Up Your GitHub Action Workflow
Create a file at .github/workflows/deploy.yml in your project repository:
name: Deploy to VPS
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Deploy via SSH
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
script: |
cd /var/www/my-project
git pull origin main
docker compose up -d --build
Securing Your Secrets
Never hardcode your server IP addresses or SSH private keys into code repositories. Store them securely under your GitHub repository's Settings > Secrets and variables > Actions.
Build on a Solid Foundation
Smooth CI/CD pipelines rely on low-latency network connectivity and dependable server uptimes.
- Explore Spaceship Cloud Solutions to build your high-performance deployment environment today.
Have questions about configuring SSH keys or GitHub Actions? Feel free to reach out via GitHub or email.