How to deploy with GitHub Actions on DigitalOcean

intermediate 12 min read Updated 2026-04-20
Quick Answer

Deploy to DigitalOcean using GitHub Actions by creating a workflow file that builds your application, pushes it to a registry, and deploys to your Droplet via SSH. Set up secrets in GitHub for secure authentication and use DigitalOcean's App Platform or manual Droplet deployment.

Prerequisites

  • GitHub repository with your application code
  • DigitalOcean account
  • Basic knowledge of Docker and CI/CD concepts
  • SSH key pair for server access

Step-by-Step Instructions

1

Create a DigitalOcean Droplet or App

Log into your DigitalOcean dashboard and click Create > Droplets. Choose Ubuntu 22.04 LTS, select your preferred plan, and add your SSH key. Alternatively, use App Platform by clicking Create > Apps for a managed deployment solution.
App Platform is easier for beginners but Droplets offer more control and are often more cost-effective.
2

Set up GitHub Secrets

In your GitHub repository, go to Settings > Secrets and variables > Actions. Click New repository secret and add:
  • DIGITALOCEAN_ACCESS_TOKEN - Your DO API token
  • HOST - Your Droplet's IP address
  • USERNAME - SSH username (usually root)
  • PRIVATE_KEY - Your private SSH key content
Generate your DigitalOcean API token from Account > API > Personal Access Tokens in the DO dashboard.
3

Create GitHub Actions Workflow File

In your repository, create .github/workflows/deploy.yml. Start with the basic structure:
name: Deploy to DigitalOcean
on:
  push:
    branches: [ main ]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
4

Configure Build and Test Steps

Add build steps to your workflow:
    - uses: actions/checkout@v4
    - name: Setup Node.js
      uses: actions/setup-node@v4
      with:
        node-version: '18'
    - name: Install dependencies
      run: npm install
    - name: Run tests
      run: npm test
    - name: Build application
      run: npm run build
Adapt these steps based on your technology stack (Python, Go, etc.).
5

Add Docker Build Step (Optional)

If using Docker, add container build steps:
    - name: Build Docker image
      run: docker build -t ${{ github.repository }}:${{ github.sha }} .
    - name: Push to registry
      run: |
        echo ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} | docker login registry.digitalocean.com -u ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} --password-stdin
        docker push registry.digitalocean.com/${{ github.repository }}:${{ github.sha }}
Create a Container Registry in DigitalOcean first if using this approach.
6

Configure SSH Deployment

Add deployment step using SSH:
    - name: Deploy to DigitalOcean
      uses: appleboy/ssh-action@v1.0.0
      with:
        host: ${{ secrets.HOST }}
        username: ${{ secrets.USERNAME }}
        key: ${{ secrets.PRIVATE_KEY }}
        script: |
          cd /var/www/your-app
          git pull origin main
          npm install --production
          pm2 restart all
Install PM2 or your preferred process manager on the Droplet beforehand.
7

Test and Monitor Deployment

Push changes to your main branch to trigger the workflow. Monitor progress in Actions tab of your GitHub repository. Check the Jobs section for detailed logs. Verify your application is running by visiting your Droplet's IP address or domain.
Enable DigitalOcean monitoring and set up alerts for your Droplet's resource usage.

Common Issues & Troubleshooting

SSH connection fails during deployment

Verify your SSH key is correctly added to GitHub secrets and that the public key is in /root/.ssh/authorized_keys on your Droplet. Check that SSH is enabled and the firewall allows port 22.

Docker push fails to DigitalOcean Container Registry

Ensure your Container Registry name matches exactly in the push command. Verify the DIGITALOCEAN_ACCESS_TOKEN has write permissions to the registry.

Application fails to start after deployment

Check application logs using pm2 logs or journalctl. Verify all environment variables are set correctly on the Droplet and dependencies are properly installed.

GitHub Actions workflow times out

Increase timeout values using timeout-minutes in your job configuration. Optimize your build process by using caching with actions/cache@v3 for dependencies.

Prices mentioned in this guide are pulled from current plan data and may change. Always verify on the official DigitalOcean website before purchasing.