Deploying Docusaurus to Digital Ocean
Deploying Docusaurus to Digital Ocean
Section titled â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.
1. Set Up Your Digital Ocean Droplet
Section titled â1. Set Up Your Digital Ocean DropletâFirst, ensure your Digital Ocean droplet is properly configured:
-
SSH into your droplet:
Terminal window ssh root@your-droplet-ip -
Copy the setup script from the scripts directory to your droplet and run it:
Terminal window chmod +x setup-droplet.sh./setup-droplet.sh -
Update the Nginx configuration with your actual domain name.
2. Set Up GitHub Secrets
Section titled â2. Set Up GitHub SecretsâIn your GitHub repository containing the Docusaurus project:
- Go to Settings > Secrets and variables > Actions
- Add the following secrets:
SSH_PRIVATE_KEY: Your private SSH key (generate a new one for deployment)SSH_KNOWN_HOSTS: Output ofssh-keyscan your-droplet-ipSSH_USER: Username for SSH (usually ârootâ)SSH_HOST: Your dropletâs IP address
3. Add GitHub Actions Workflow
Section titled â3. Add GitHub Actions WorkflowâThe workflow file is already added at .github/workflows/deploy.yml
4. Generate SSH Keys for Deployment
Section titled â4. Generate SSH Keys for Deploymentâ# On your local machinessh-keygen -t rsa -b 4096 -C "github-actions-deploy" -f ~/.ssh/do_deploy_keyAdd the public key to your Digital Ocean droplet:
# On your local machinessh-copy-id -i ~/.ssh/do_deploy_key.pub root@your-droplet-ipUse the private key content as the value for the SSH_PRIVATE_KEY GitHub secret.
5. Testing the Deployment
Section titled â5. Testing the Deploymentâ- Push a commit to your main branch on GitHub
- Go to the âActionsâ tab in your GitHub repository to monitor the workflow
- Verify that your site is deployed to your Digital Ocean droplet
Troubleshooting
Section titled âTroubleshootingâIf you encounter issues with the deployment:
- Check the GitHub Actions logs for detailed error messages
- Ensure your SSH keys are correctly set up
- Verify that the paths in the rsync command match your Docusaurus build output
- Check Nginx logs:
sudo tail -f /var/nginx/error.log
Additional Configuration
Section titled âAdditional ConfigurationâCustom Domain
Section titled âCustom DomainâIf you want to use a custom domain:
- Update your DNS records to point to your Digital Ocean droplet IP
- Update the Nginx configuration with your domain name
- Consider setting up HTTPS with Letâs Encrypt:
apt install -y certbot python3-certbot-nginxcertbot --nginx -d your-domain.comEnvironment Variables
Section titled âEnvironment VariablesâIf your Docusaurus site needs environment variables:
- Add them as GitHub secrets
- Update the GitHub Actions workflow to use them during the build step