Self-hosted Open Source
Run Stategraph Open Source on one host with Docker Compose, connect GitHub or GitLab, and get your first plan on a pull request. Plans and applies run on your GitHub Actions or GitLab CI runners, not on the server.
Open Source is the ghcr.io/stategraph/stategraph-server-oss image. It is MPL-2.0 licensed and needs no license key. See Editions.
Before you begin
- Git
- Docker Engine 20.10 or later
- Docker Compose 2.24 or later
- Port 8080 free on the host
- For GitHub, admin rights in a GitHub organization or account, to create and install a GitHub App
- For GitLab, gitlab.com or self-managed GitLab 18.1 or later, a group (personal namespaces are not supported), and the rights to create an access token, add a project webhook, and change the CI/CD settings of the project
1. Get the Compose file
git clone --depth 1 https://github.com/stategraph/stategraph.git
cd stategraph/docker/stategraph
docker-compose.yml runs PostgreSQL and the Stategraph server, with Orchestration on. Your settings go in .env, in this directory.
2. Start Stategraph
docker compose up -d
3. Check that Stategraph is ready
docker compose ps
curl http://localhost:8080/health/live
curl http://localhost:8080/health/ready
/health/ready answers 200 when the migrations are done and the server serves requests. This takes about 15 seconds at the first start. If Stategraph does not start, docker compose logs -f server gives the cause.
4. Create the admin account
Open http://localhost:8080. The setup screen creates the first admin account. The password needs at least 8 characters. You are then signed in.
5. Set the public URL
GitHub and GitLab send webhooks to the server, and your runners call it, so the server needs a public HTTPS URL. Put the URL in .env:
STATEGRAPH_PUBLIC_URL=https://stategraph.example.com
STATEGRAPH_UI_BASE=${STATEGRAPH_PUBLIC_URL}
STATEGRAPH_OAUTH_REDIRECT_BASE=${STATEGRAPH_PUBLIC_URL}
Your own URL comes from a reverse proxy or a load balancer that terminates TLS in front of port 8080. If the host has no public URL, for example a laptop or a server behind a firewall, use Terratunnel:
- Open tunnel.terrateam.dev, and sign in with GitHub or GitLab.
- Copy your tunnel URL,
https://<name>.tunnel.terrateam.dev. It is your public URL. - Click Generate API Key, and copy the key. The page shows it one time.
- Put the tunnel URL, the key, and the
tunnelprofile in.env:
STATEGRAPH_PUBLIC_URL=https://<name>.tunnel.terrateam.dev
STATEGRAPH_UI_BASE=${STATEGRAPH_PUBLIC_URL}
STATEGRAPH_OAUTH_REDIRECT_BASE=${STATEGRAPH_PUBLIC_URL}
TERRATUNNEL_API_KEY=<key>
COMPOSE_PROFILES=tunnel
COMPOSE_PROFILES=tunnel makes Docker Compose start terratunnel, which forwards each request on your tunnel URL to the server. A new key replaces the old one, so run one stack per key. Terratunnel makes the whole server public at the tunnel URL: for production, use your own URL.
Apply the change:
docker compose up -d
Then open the console at your public URL, not localhost. The console shows webhook URLs from the address in your browser.
6. Connect GitHub
Skip this step for GitLab.
Create the App
In the console, open Get Started, and select Continue with GitHub. The first step is Create:
- Keep the App name that the console suggests, or type your own. GitHub requires a name that no other App uses. To create the App under an organization, enter the organization name.
- Click Create on GitHub. GitHub opens with the App filled in: webhook URL, callback URLs, permissions, and events.
- Create the App on GitHub. GitHub returns you to the console.
The console shows "The App is created. Starting the orchestration engine." for a few seconds, then moves to the Install step. Nothing goes into .env, and no restart is needed.
Install the App
- On the Install step, click Install on GitHub.
- Select the organization that holds your repositories, and the repositories that the App can access.
- Back in the console, on the Link step, click Claim next to the installation. This links it to your tenant.
Pick a repository
The console asks Which repository?
For a first plan with no cloud credentials, use the example repository, stategraph/kick-the-tires. It uses null resources and local state, so nothing real is created. It already has the workflow file.
- Select Use the example repository.
- Fork it into an account or organization where the App is installed.
- In the fork, open the Actions tab, and enable workflows. GitHub turns workflows off on every fork, and the first plan never starts until you turn them on.
- In
dev/main.tfof the fork, changenull_resource_count = 0tonull_resource_count = 1on a new branch.
For your own repository:
- Select Continue with my repository. The App must have access to it.
- Create
.github/workflows/stategraph.ymlon the default branch. Push it directly, or merge a pull request that contains only this file. Keep the file name and the action as shown:
name: 'Stategraph'
on:
workflow_dispatch:
inputs:
# The work-token and api-base-url are passed in by the backend
work-token:
description: 'Work Token'
required: true
api-base-url:
description: 'API Base URL'
environment:
description: 'Environment in which to run the action'
type: environment
runs_on:
description: 'runs-on configuration'
type: string
default: '"ubuntu-latest"'
jobs:
stategraph:
permissions: # Required to pass credentials to the action
id-token: write
contents: read
runs-on: ${{ fromJSON(github.event.inputs.runs_on) }}
timeout-minutes: 1440
name: Stategraph
environment: '${{ github.event.inputs.environment }}'
steps:
- uses: actions/checkout@v4
- name: Run Stategraph
id: stategraph
uses: terrateamio/action@v1
with:
work-token: '${{ github.event.inputs.work-token }}'
api-base-url: '${{ github.event.inputs.api-base-url }}'
env:
SECRETS_CONTEXT: ${{ toJson(secrets) }}
VARIABLES_CONTEXT: ${{ toJson(vars) }}
- If your Terraform connects to a cloud, add credentials as GitHub secrets, or use OIDC. See Cloud credentials.
- On a new branch, change a
.tfor.tfvarsfile.
7. Connect GitLab
Skip this step for GitHub.
Add the GitLab application
- Create a dedicated GitLab user for Stategraph.
- As that user, create a personal access token with the
apiscope. - As the same user, in Preferences > Applications, add an application with the
apiscope and the redirect URI<public-url>/api/v1/gitlab/callback. Copy its application ID and secret.
Add the three values to .env:
GITLAB_APP_ID=<application id>
GITLAB_APP_SECRET=<application secret>
GITLAB_ACCESS_TOKEN=<access token>
On self-managed GitLab, also set GITLAB_API_BASE_URL and GITLAB_WEB_BASE_URL, and mirror the CI template: see Self-managed GitLab.
Restart, and follow the server log:
docker compose up -d
docker compose logs -f server
A missing GitLab variable logs a CONFIG : ERROR line that names it.
Connect the group
In the console, open Get Started, and select Continue with GitLab.
- Enter the GitLab URL, the group path as it shows in URLs, and the numeric group ID (under the group name, or Copy group ID in the group menu). Check the group ID yourself. The wizard does not check it, and a wrong ID gives an installation that never receives webhooks.
- Enter the project path under the group. For a first plan with no cloud credentials, use the example project instead, and fork terrateam-demo/kick-the-tires into the group (gitlab.com only).
- Create an access token with the
apiscope, and enter it. Group and project tokens need at least the Developer role. Merge request comments and pipelines for the group run as the user of the token. - Add a project webhook in GitLab with the URL and secret token that the wizard shows, and with Push events, Comments, Merge request events, and Job events on. Copy the secret before you continue: it shows one time only. Save the webhook, and run Test > Push events on it to activate it.
- In GitLab, set Settings > CI/CD > Variables > Minimum role to use pipeline variables to Developer.
- Put the
.gitlab-ci.ymlbelow at the root of the default branch. In a fork of the example project, replace its.gitlab-ci.yml. If the project already has one, merge these jobs into it.
# .gitlab-ci.yml - Stategraph pipeline
spec:
inputs:
TERRATEAM_TRIGGER:
description: "Is this being triggered by Stategraph?"
type: string
default: "$TERRATEAM_TRIGGER"
WORK_TOKEN:
description: "The work token from Stategraph"
type: string
default: "$WORK_TOKEN"
API_BASE_URL:
description: "The base url for the Stategraph API"
type: string
default: "$API_BASE_URL"
RUNS_ON:
description: "The tags to use for the runner"
type: array
default: []
---
include:
- project: 'terrateam-io/terrateam-template'
file: 'terrateam-template.yml'
inputs:
TERRATEAM_TRIGGER: $[[ inputs.TERRATEAM_TRIGGER ]]
WORK_TOKEN: $[[ inputs.WORK_TOKEN ]]
API_BASE_URL: $[[ inputs.API_BASE_URL ]]
RUNS_ON: $[[ inputs.RUNS_ON ]]
stages:
- terrateam
terrateam_job:
extends: .terrateam_template
Then create a branch from the default branch, and change a .tf or .tfvars file. In the example project, change null_resource_count = 0 to null_resource_count = 1 in dev/main.tf.
8. Open a pull request
Open a pull request, or a merge request on GitLab, against the default branch. On a fork, open it against the fork, not the upstream repository.
Each directory with .tf or .tfvars files becomes a root. Each pull request that changes files in a root gets a plan. Orchestration starts the workflow or pipeline on your runner and posts a plan comment with what the change creates, changes, or destroys. On GitHub, your GitHub App posts it. On GitLab, the user of the access token posts it. Each push plans again. Comment stategraph plan to plan on demand.
On GitHub, the first run may need approval. GitHub marks the run Action required and holds it until someone with write access approves it. Open the Actions tab, select the run, and select Approve and run.
Nothing is applied until someone comments stategraph apply. See Pull request workflow.
If no plan starts
- On GitHub, check that GitHub Actions is enabled and that the workflow file is on the default branch.
- On GitHub, check the Actions tab for a run marked Action required. Select the run and select Approve and run.
- On GitLab, check that the source branch contains
.gitlab-ci.ymland that the minimum role to use pipeline variables is Developer. - Comment
stategraph repo-configto see the configuration that Orchestration derived for the repository. - When a run fails, the pull request comment names the cause. Fix it and comment
stategraph plan. docker compose logs servershowsGITHUB_APP : WAITINGuntil the GitHub App exists, andCONFIG : ERRORfor a missing GitLab variable. See Troubleshooting.
Next steps
- Pull request workflow: apply, merge, and every trigger.
- Configuration: discovery rules and guardrails in
.stategraph/config.yml. - Docker Compose: sign-in, updates, external PostgreSQL, and production settings.
- Connect GitHub or GitLab: self-managed GitLab, credential rotation, GitHub Enterprise Server, and an App from the environment.
- Kubernetes, Amazon ECS, and Google Cloud Run: other deployments.
- Editions: what Open Source and Enterprise include.