DigitalOcean Provider
Deploy preview environments to DigitalOcean Droplets via SSH.
How it works
- Build: SSHs into a fresh Droplet, clones the repo, and runs
docker build. Docker is installed automatically via cloud-init on first boot. - Deploy: runs the built Docker image in a container on the same Droplet. Each PR gets its own Droplet.
- Delete: destroys the Droplet.
- List: lists all Droplets tagged
preview-repo-{owner}-{repo}.
Prerequisites
- A DigitalOcean account.
- A personal access token with read/write scope.
- An SSH key registered in DigitalOcean (used for Droplet access).
Step 1 — Create a DigitalOcean personal access token
- Go to API → Tokens → Generate New Token.
- Enable both Read and Write scopes.
- Store the token as
DIGITALOCEAN_TOKENin Previewops secrets.
Step 2 — Register an SSH key in DigitalOcean
If you already have an SSH key pair:
- Go to Settings → Security → SSH Keys → Add SSH Key.
- Paste the public key.
- Note the Key ID (numeric) or fingerprint shown after adding it (or find either with
doctl compute ssh-key list).
If you need a new key pair:
ssh-keygen -t ed25519 -C "previewops" -f ~/.ssh/previewops
# Upload ~/.ssh/previewops.pub to DigitalOcean (step above)
# Store the private key content as DO_SSH_PRIVATE_KEY in previewops secrets
cat ~/.ssh/previewops
Step 3 — Store secrets in Previewops
| Secret | Value |
|---|---|
DIGITALOCEAN_TOKEN |
Personal access token from step 1 |
DO_SSH_PRIVATE_KEY |
PEM-encoded private key from step 2 |
Step 4 — Configure the repo
provider: digitalocean
providerConfig:
sshKeyId: "12345678" # required — numeric Key ID or fingerprint from step 2
# find yours with: doctl compute ssh-key list
region: nyc3 # optional (default: nyc3); run `doctl compute region list` for options
size: s-1vcpu-1gb # optional (default: s-1vcpu-1gb); run `doctl compute size list` for options
Complete example with all options:
# .previewops.yaml
provider: digitalocean
providerConfig:
sshKeyId: "12345678" # DigitalOcean SSH key ID or fingerprint (required)
region: nyc3 # Droplet region (default: nyc3)
size: s-1vcpu-1gb # Droplet size (default: s-1vcpu-1gb)
# Common options — all optional
concurrency: 3 # max simultaneous active previews per repo
ttlHours: 24 # auto-delete after N hours (default: 24)
port: 3000 # optional — auto-detected from your Dockerfile EXPOSE; falls back to 8080
memory: 512Mi # container memory passed to docker run (default: 512Mi)
cpu: 1 # CPU shares passed to docker run (default: 1)
dockerfile: Dockerfile # Dockerfile path relative to repo root (default: Dockerfile)
buildContext: . # Docker build context (default: .)
env:
NODE_ENV: preview # inject env vars into the preview container
Step 5 — Verify
Comment /validate-previewops on any open PR. The bot will call GET /v2/account and report the account email and status.
Notes
- Droplets are provisioned on-demand for each PR and destroyed on delete/close.
- First deploy takes ~3 minutes (Droplet boot + Docker/git installation via cloud-init).
- Subsequent deploys to the same PR reuse the existing Droplet and are faster (~30s).
- The preview URL is
http://{droplet-ip}. For HTTPS, place a load balancer or Caddy reverse proxy in front.
Troubleshooting
| Error | Fix |
|---|---|
DIGITALOCEAN_TOKEN environment variable is required |
Set the token in secrets |
digitalocean providerConfig.sshKeyId is required |
Add sshKeyId to providerConfig |
| SSH connection refused | Droplet hasn't finished cloud-init; the provider waits 3 min automatically |
docker: command not found |
cloud-init failed — check Droplet console logs in the DO dashboard |