Skip to content

Deploying Docusaurus to Digital Ocean

This guide will walk you through setting up automatic deployment of your Docusaurus project to a Digital Ocean droplet using GitHub Actions.

First, ensure your Digital Ocean droplet is properly configured:

  1. SSH into your droplet:

    Terminal window
    ssh root@your-droplet-ip
  2. Copy the setup script from the scripts directory to your droplet and run it:

    Terminal window
    chmod +x setup-droplet.sh
    ./setup-droplet.sh
  3. Update the Nginx configuration with your actual domain name.

In your GitHub repository containing the Docusaurus project:

  1. Go to Settings > Secrets and variables > Actions
  2. Add the following secrets:
    • SSH_PRIVATE_KEY: Your private SSH key (generate a new one for deployment)
    • SSH_KNOWN_HOSTS: Output of ssh-keyscan your-droplet-ip
    • SSH_USER: Username for SSH (usually ‘root’)
    • SSH_HOST: Your droplet’s IP address

The workflow file is already added at .github/workflows/deploy.yml

Terminal window
# On your local machine
ssh-keygen -t rsa -b 4096 -C "github-actions-deploy" -f ~/.ssh/do_deploy_key

Add the public key to your Digital Ocean droplet:

Terminal window
# On your local machine
ssh-copy-id -i ~/.ssh/do_deploy_key.pub root@your-droplet-ip

Use the private key content as the value for the SSH_PRIVATE_KEY GitHub secret.

  1. Push a commit to your main branch on GitHub
  2. Go to the “Actions” tab in your GitHub repository to monitor the workflow
  3. Verify that your site is deployed to your Digital Ocean droplet

If you encounter issues with the deployment:

  1. Check the GitHub Actions logs for detailed error messages
  2. Ensure your SSH keys are correctly set up
  3. Verify that the paths in the rsync command match your Docusaurus build output
  4. Check Nginx logs: sudo tail -f /var/nginx/error.log

If you want to use a custom domain:

  1. Update your DNS records to point to your Digital Ocean droplet IP
  2. Update the Nginx configuration with your domain name
  3. Consider setting up HTTPS with Let’s Encrypt:
Terminal window
apt install -y certbot python3-certbot-nginx
certbot --nginx -d your-domain.com

If your Docusaurus site needs environment variables:

  1. Add them as GitHub secrets
  2. Update the GitHub Actions workflow to use them during the build step