DigitalOceanTutorial2 min read

How Do I Set Up Automatic Deployments to DigitalOcean?

Automate deploys to DigitalOcean on every Git push using GitHub Actions, webhooks, or App Platform — no manual SSH required.

Server racks and cloud infrastructure

Deployment Options

There are three common ways to auto-deploy to DigitalOcean:

  • App Platform — connects to GitHub and deploys on every push (zero config)
  • GitHub Actions — SSH into a Droplet and pull/build/restart on push
  • Webhook + deploy script — a listener on your Droplet triggers a pull script

Option A — App Platform (Easiest)

Create an app in the control panel, connect your GitHub repo, and select the branch. Every push triggers a build and deploy automatically. No SSH keys, no scripts, no server maintenance. Best for static sites, Node.js, Python, and Go apps.

Option B — GitHub Actions to a Droplet

Create .github/workflows/deploy.yml in your repo:

name: Deploy to DigitalOcean
on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Deploy via SSH
        uses: appleboy/ssh-action@v1
        with:
          host: ${{ secrets.DO_HOST }}
          username: root
          key: ${{ secrets.DO_SSH_KEY }}
          script: |
            cd /var/www/myapp
            git pull origin main
            npm ci --production
            pm2 reload myapp

Add DO_HOST (your Droplet IP) and DO_SSH_KEY (private key contents) as GitHub repository secrets under Settings → Secrets → Actions.

Option C — Webhook Deploy Script

On your Droplet, create a deploy script at /var/www/deploy.sh:

#!/bin/bash
cd /var/www/myapp
git pull origin main
npm ci --production
pm2 reload myapp
chmod +x /var/www/deploy.sh

Set up a GitHub webhook (Settings → Webhooks) pointing to a small listener on your Droplet, or use a tool like webhook (the adhoc-server/webhook project) to trigger the script on push events.

Best Practices

  • Deploy from CI, not directly from your laptop — reproducible and auditable
  • Run npm ci (not npm install) for deterministic builds
  • Use pm2 reload for zero-downtime restarts
  • Take a snapshot before the first automated deploy
  • Add a health check step after deploy to verify the app is responding

Database Migrations in CI

Add a migration step before restarting the app:

npx prisma migrate deploy
# or: npm run db:migrate

Automatic deployments turn every push to main into a live update — ship faster with confidence.