Coolify Preview Infrastructure¶
Preview deployments run on a single EC2 instance managed by Coolify (a self-hosted PaaS). Coolify handles Docker builds, container orchestration, Traefik reverse proxy, and SSL.
Infrastructure (Terraform)¶
cd terraform
terraform init
terraform plan
terraform apply
# Save SSH key
terraform output -raw ssh_private_key > coolify-preview.pem
chmod 600 coolify-preview.pem
# View outputs (Elastic IP, dashboard URL, SSH command)
terraform output
This creates:
- EC2 instance (t3.medium, Ubuntu 24.04, 40GB gp3) with Coolify auto-installed
- Security group (ports 22, 80, 443, 8000)
- Elastic IP
- SSH key pair
DNS¶
Current Elastic IP:
32.193.200.63— update DNS records andCOOLIFY_BASE_URLif the IP changes.
Create a wildcard A record pointing to the Elastic IP:
*.preview-dev.scenarix.ai -> 32.193.200.63
Coolify Configuration¶
Once the dashboard is accessible at http://32.193.200.63:8000:
- Create admin account
- Configure the wildcard domain in instance settings:
preview-dev.scenarix.ai - Create a project (e.g., "Preview Deployments") — note the project UUID
- Create an environment named
previewwithin that project - Add a GitHub Private Key/Source so Coolify can pull private repos — note the source UUID
- Note the default server UUID (localhost)
- Set
GITHUB_PKG_TOKENas a build argument at the project level for private@scenarixnpm packages - Generate an API token: Settings -> API -> Generate token
GitHub Actions Secrets/Variables for Preview¶
Set these on scenarix/auto-pr:
| Type | Name | Value |
|---|---|---|
| Secret | COOLIFY_API_TOKEN |
API token from Coolify dashboard |
| Secret | PREVIEW_ENV_VARS |
Runtime env vars for preview apps (see below) |
| Variable | COOLIFY_BASE_URL |
http://32.193.200.63:8000 |
| Variable | COOLIFY_PROJECT_UUID |
UUID from Coolify project |
| Variable | COOLIFY_ENVIRONMENT_NAME |
preview |
| Variable | COOLIFY_SERVER_UUID |
UUID of the localhost server in Coolify |
| Variable | COOLIFY_GITHUB_SOURCE_UUID |
UUID of the GitHub source in Coolify |
Runtime Environment Variables (PREVIEW_ENV_VARS)¶
Preview apps need runtime env vars (MongoDB URI, Redis URL, JWT secrets, API keys, etc.). These are stored as a single GitHub Actions secret called PREVIEW_ENV_VARS and injected per-app via Coolify's API at creation time.
Format: one KEY=VALUE per line (blank lines and # comments are skipped):
MONGODB_URI=mongodb+srv://...
REDIS_URL=redis://...
JWT_SECRET=xxx
To update: edit the PREVIEW_ENV_VARS secret in GitHub Actions settings on scenarix/auto-pr. Changes take effect on the next new preview app creation. Existing apps need to be deleted and recreated (close + reopen the PR).
Note: Coolify's shared environment variables require
{{ environment.VAR }}syntax per-app and don't auto-inject into API-created apps. That's why we inject env vars directly via the API instead.
SSH Access¶
ssh -i coolify-preview.pem ubuntu@32.193.200.63