Skip to content

Install

Terraform

Run a released CirCI on a Docker host with the Terraform module, and update it by changing one version.

The Terraform module (the repository's deploy/terraform, published on the Terraform Registry as cir-ci/circi/docker) runs a released CirCI on one Docker host: the app (ghcr.io/cir-ci/circi:<version>), Postgres in a container unless you give your own, and Caddy for TLS and hosted sites when you ask for it. It runs the same services as Docker Compose with the Caddy overlay, but from published images. It needs Terraform 1.8 or later and the kreuzwerker/docker provider.

For a Kubernetes cluster such as EKS, use the Helm chart instead. Its settings have the same names as this module's inputs, so one configuration translates to the other.

Pin the module to the same release as the image with version, so the two always match.

provider "docker" {
host = "ssh://ubuntu@ci.acme.io" # or unix:///var/run/docker.sock on the host itself
}
module "circi" {
source = "cir-ci/circi/docker"
version = "0.1.0" # a registry version is the CirCI release of the same number
circi_version = "0.1.0" # the image tag: ghcr.io/cir-ci/circi:0.1.0, and circi-caddy:0.1.0
image_repository = "ghcr.io/cir-ci/circi" # the default; a mirror of it works too
better_auth_secret = var.better_auth_secret # openssl rand -base64 32; keep it stable
postgres_password = var.postgres_password
caddy = {
dashboard_host = "ci.acme.io"
sites_host = "acme-sites.com" # a domain used for nothing else
}
smtp = {
host = "email-smtp.eu-west-1.amazonaws.com"
from = "CirCI <ci@acme.io>"
user = var.smtp_user
}
smtp_password = var.smtp_password
}

To use the module without the registry, point source at the repository and pin it to the release tag with ?ref=: source = "git::https://github.com/cir-ci/repo.git//deploy/terraform?ref=@circi/server@0.1.0" (and no version).

The images come from GitHub's container registry: ghcr.io/cir-ci/circi:<version> for the app and ghcr.io/cir-ci/circi-caddy:<version> for Caddy, both linux/amd64. To pull from a mirror, set image_repository to it (the Caddy image is <repository>-caddy). If your registry needs a login, give the Docker provider its credentials:

provider "docker" {
host = "ssh://ubuntu@ci.acme.io"
registry_auth {
address = "registry.acme.io"
username = var.registry_user
password = var.registry_password
}
}

Without caddy, the app is published on port (3000) at public_url; put your own proxy in front and list it in trusted_proxies. With caddy, read Site domains first: the sites domain must be used for nothing else.

The volumes for screenshots and the bundled Postgres have prevent_destroy, so terraform destroy stops at them instead of deleting your data.

Change circi_version and the module's version (or its ?ref=) and apply. Terraform pulls that image and replaces the container. The server applies database migrations as it starts, and the apply waits for the image's health check, so a version that doesn't start fails the apply instead of leaving a restarting container. GET /healthz reports the version a server runs. See Upgrades and migrations.

Every environment variable the server reads is a key of a group, one module variable per area, named after its setting: smtp.host is SMTP_HOST, tuning.diff_engine is CIRCI_DIFF_ENGINE. variables.tf lists each group's keys with their types and defaults.

Group Keys
smtp host, port, secure, user, from
s3 bucket, region, endpoint, force_path_style, access_key_id, connect_timeout_seconds, request_timeout_seconds
sign_in email, password, sso: which sign-in methods are on
sso github_client_id, google_client_id, gitlab_client_id, gitlab_url, oidc_issuer, oidc_client_id, oidc_name, oidc_trusted_for_email
github_app id, api_url, api_timeout_seconds
slack client_id, api_url
vapid public_key, subject
sites host (without caddy), max_mb
jobs upload_timeout_minutes, gc_grace_hours, retention_days, retry_base_seconds, retry_max_seconds
webhooks timeout_seconds, allow_private_addresses
tuning database_pool_max, diff_engine, diff_threads, live_max_streams

log_level and workspace_creation are variables of their own, and so is each secret (below).

  • A misspelled key fails the plan (smtp takes host, port, secure, user, from: hots isn't one.), and so does a value of the wrong type. Every change to a setting shows in the plan.
  • Settings that go together are checked in the plan: smtp.user with smtp_password, each client ID with its secret, the three GitHub App values, the three OIDC values. The message names the variables (These settings go together, set all of each or none: smtp.user / smtp_password.). The server checks the same groups when it starts, but the plan catches a half-set pair before anything is replaced.
  • A key left out leaves the setting unset. Each group defaults to {}, and every key you don't give is null, which keeps the setting out of the container's environment. The server's default applies, and a setting that Instance settings can change (mail, sign-in methods, Slack, the limits) stays changeable in the dashboard. Setting it here locks it there.
  • The module sets a few itself: DATABASE_URL (from the database inputs below), PUBLIC_URL, TRUSTED_PROXIES and STATIC_SITES_HOST with Caddy. The image fixes NODE_ENV, HOST, PORT, STORAGE_PATH and its own paths.

Each secret is a variable of its own, named after the setting in lower case and marked sensitive: better_auth_secret, smtp_password, s3_secret_access_key, github_app_private_key, github_app_webhook_secret, slack_client_secret, vapid_private_key, the auth_*_client_secrets, and the database password. None of them goes into the container's environment. Each is uploaded as a file under /run/circi/secrets/, and the server reads it through <NAME>_FILE (see Configuration). So the plan shows every other setting in plain text, and a change to log_level reads as LOG_LEVEL=info → LOG_LEVEL=debug.

Leave database unset and the module runs Postgres 18 in a container with its own volume. Set postgres_password for it. Postgres takes the password only when its volume is first made: to change it later, run ALTER USER circi PASSWORD '…' in the database first, then change the variable and apply.

To use your own Postgres, such as Amazon RDS, set database and database_password:

module "circi" {
# ...
database = {
host = aws_db_instance.circi.address
user = aws_db_instance.circi.username
name = "circi"
ca_certificate = data.http.rds_ca.response_body
}
database_password = var.database_password
}
data "http" "rds_ca" {
url = "https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem"
}
databaseobject

host, port (5432), name (circi), user, tls (true) and ca_certificate. With tls, the server verifies the database's certificate (sslmode=verify-full). ca_certificate is the PEM it chains to when that isn't a public certificate authority: Amazon RDS's certificates aren't trusted by Node, so pass Amazon's bundle. Without it the server fails to start with a certificate error.

database_passwordstring

The password of database.user. Any characters work: the module URL-encodes it.

The other requirements are in Database: a direct connection, a user that may create tables, and room for the connections.

The module's Docker network has a fixed subnet, network_subnet (192.168.250.0/24), and Caddy gets its 10th address, the only proxy the app trusts. Keep the subnet outside any network the host has to reach: Docker's own default networks (172.17.0.0/16 and up) overlap an AWS default VPC (172.31.0.0/16), which would send traffic for RDS into Docker.

Caddy needs Route53 for the sites domain's wildcard certificate. An instance role works without settings; otherwise set caddy_aws_credentials = { access_key_id, secret_access_key }, which Caddy reads from a file, out of its environment and the plan.

On EC2, a container reaches the instance role (for Caddy's Route53, or s3 without access_key_id) only when the instance's metadata hop limit is 2: metadata_options { http_put_response_hop_limit = 2 }.

Besides the groups and secrets described above:

Name Default
circi_version (required) The release to run, e.g. 0.1.0.
better_auth_secret (required) 32 characters or more.
postgres_password null For the bundled Postgres; required unless database is set.
database, database_password null Your own Postgres; its keys default to port = 5432, name = "circi", tls = true, the rest null.
public_url, previous_public_urls http://localhost:3000, [] public_url is ignored with caddy: it becomes https://<dashboard_host>.
caddy, caddy_aws_credentials null dashboard_host, sites_host, aws_region (default "us-east-1"); Route53 keys when there's no instance role.
port, trusted_proxies 3000, [] Without caddy: the host port, and your proxy's addresses.
network_subnet 192.168.250.0/24 The Docker network.
image_repository ghcr.io/cir-ci/circi Another registry or a mirror; the Caddy image is <repository>-caddy.
postgres_image postgres:18-alpine Keep the major version: a new one needs a dump and restore.
name_prefix circi Container, volume and network names, for two installs on one host.
log_level, workspace_creation null LOG_LEVEL, WORKSPACE_CREATION.
smtp, s3, sign_in, sso, github_app, slack, vapid, sites, jobs, webhooks, tuning {} The settings' groups (above); a key you don't give is null.

Outputs: version, image, public_url.