Prerequisites
Before you begin, ensure you have:- Digital Ocean Account: Sign up at digitalocean.com
- GitHub Account: With access to repositories you want to enable
- Node.js: Version 20 or higher (download)
- pnpm: Package manager (install)
- Terraform: Version 1.5 or higher (install)
- Ansible: Version 2.14 or higher (install)
- SSH Key: For accessing the Digital Ocean droplet
Step 1: Install preview-deployer
Clone the repository and install dependencies:Step 2: Get Required Tokens
Digital Ocean API Token
- Go to Digital Ocean API Tokens
- Click “Generate New Token”
- Give it a name (e.g., “preview-deployer”)
- Select “Write” scope
- Copy the token (you won’t see it again!)
GitHub Personal Access Token
- Go to GitHub Settings > Developer settings > Personal access tokens
- Click “Generate new token (classic)”
- Give it a name (e.g., “preview-deployer”)
- Select scopes:
repo(Full control of private repositories)admin:repo_hook(Full control of repository hooks)
- Generate and copy the token
Step 3: Initialize Configuration
Run the init command:- Digital Ocean API token
- Digital Ocean region (default: nyc3)
- Droplet size (default: s-2vcpu-4gb)
- GitHub personal access token
- GitHub repositories (comma-separated, format: owner/repo)
- Cleanup TTL in days (default: 7)
- Max concurrent previews (default: 10)
~/.preview-deployer/config.yml. Sensitive values are stored in your OS keychain.
Step 4: Prepare Your Repository
Add apreview-config.yml file to your repository root:
Step 5: Set Up Infrastructure
Run the setup command:- Provision a Digital Ocean droplet
- Configure the server with Docker, nginx, and the orchestrator
- Create GitHub webhooks for your repositories
- SSH public key (for droplet access)
- Confirmation to create infrastructure
Step 6: Test It Out
- Create a new branch in your repository
- Make some changes
- Open a pull request
- Wait 2–3 minutes for the preview to deploy
- Check the PR comments for the preview URL
http://YOUR_SERVER_IP/{projectSlug}/pr-{PR_NUMBER}/ (e.g. http://YOUR_SERVER_IP/myorg-myapp/pr-12/).
Step 7: Verify Deployment
Check the status:- Infrastructure status
- Orchestrator health
- Active preview deployments
Troubleshooting
If something goes wrong:-
Check the orchestrator logs:
-
Check Docker containers:
-
Check nginx configuration:
Next Steps
- Read the Architecture Documentation to understand how it works
- Customize your Configuration
- Set up monitoring and alerts
- Configure custom domains (future feature)
Cost Estimation
Default setup costs approximately:- Digital Ocean droplet (s-2vcpu-4gb): ~$24/month
- Reserved IP: Free
- Firewall: Free
- Monitoring: Free
- Using a smaller droplet (s-1vcpu-2gb: ~$12/month)
- Using a cheaper region
- Disabling backups
Cleanup
To destroy all infrastructure:- Cleanup all preview deployments
- Delete GitHub webhooks
- Destroy the Digital Ocean droplet