Skip to content

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 and COOLIFY_BASE_URL if 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:

  1. Create admin account
  2. Configure the wildcard domain in instance settings: preview-dev.scenarix.ai
  3. Create a project (e.g., "Preview Deployments") — note the project UUID
  4. Create an environment named preview within that project
  5. Add a GitHub Private Key/Source so Coolify can pull private repos — note the source UUID
  6. Note the default server UUID (localhost)
  7. Set GITHUB_PKG_TOKEN as a build argument at the project level for private @scenarix npm packages
  8. 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