Skip to content

Commit 72873a9

Browse files
authored
Bring back local development docs (#2491)
* Bring back docs on local development * Improve local dev docs
1 parent b1e58a5 commit 72873a9

File tree

7 files changed

+108
-18
lines changed

7 files changed

+108
-18
lines changed

docs/ce/local-development/backend.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Backend (orchestrator) local setup
2+
title: Orchestrator local setup
33
---
44

55
The backend serves orchestration APIs, GitHub app endpoints, and internal APIs the UI relies on.
@@ -51,7 +51,7 @@ The backend serves orchestration APIs, GitHub app endpoints, and internal APIs t
5151

5252
## GitHub app integration
5353

54-
- For a quick install link, set `ORCHESTRATOR_GITHUB_APP_URL` in `ui/.env.local` to your apps install URL (`https://github.com/apps/<app>/installations/new`).
54+
- For a quick install link, set `ORCHESTRATOR_GITHUB_APP_URL` in `ui/.env.local` to your app's install URL (`https://github.com/apps/<app>/installations/new`).
5555
- To create a new app via the backend, open `http://localhost:3000/github/setup` (requires `HOSTNAME` set to a reachable URL for callbacks).
5656

5757
## Troubleshooting
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: GitHub App settings for local dev
3+
---
4+
5+
Use these settings when connecting a GitHub App to your local stack (tunneled via the UI domain).
6+
7+
## Required URLs
8+
9+
- **Callback URL** (OAuth/web): `https://<your-public-ui-domain>/orchestrator/github/callback`
10+
- **Webhook URL**: `https://<your-public-ui-domain>/orchestrator/github/webhook`
11+
- **Setup URL (optional)**: `https://<your-public-ui-domain>/dashboard/onboarding?step=github`
12+
13+
> The UI forwards these to the backend. Ensure `ORCHESTRATOR_BACKEND_URL`/`SECRET` are set in UI and the backend is reachable from the UI host.
14+
15+
## Permissions & events (recommended)
16+
17+
- Permissions: `contents:read`, `pull_requests:write`, `issues:write`, `statuses:write`, `checks:write`, `metadata:read`, `administration:read`, `workflows:write`, `repository_hooks:write`, `members:read`.
18+
- Events: `issue_comment`, `pull_request`, `pull_request_review`, `pull_request_review_comment`, `push`, `check_run`, `status`.
19+
20+
## Install URL
21+
22+
After creating the app, use its install URL (e.g., `https://github.com/apps/<app-name>/installations/new`) as `ORCHESTRATOR_GITHUB_APP_URL` in `ui/.env.local`. This drives the "Connect with GitHub" button.
23+
24+
## Creating an app via the backend wizard
25+
26+
- Open `http://localhost:3000/github/setup` (or the backend's public URL) to generate a manifest and create the app in GitHub. Needed envs on backend: `HOSTNAME` set to a reachable URL, and optional `GITHUB_ORG` if you want to scope to an org.
27+
- Once created, copy the install URL into `ORCHESTRATOR_GITHUB_APP_URL` and restart the UI.
28+
29+
## Troubleshooting
30+
31+
- **404 on connect**: `ORCHESTRATOR_GITHUB_APP_URL` not set or points to a non-existent path.
32+
- **Callbacks fail**: UI not exposed publicly; tunnel the UI port and update callback/webhook URLs to that domain.
33+
- **Backend rejects /api/github/link**: ensure `DIGGER_ENABLE_API_ENDPOINTS=true` and `DIGGER_INTERNAL_SECRET` matches the UI `ORCHESTRATOR_BACKEND_SECRET`.

docs/ce/local-development/overview.mdx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This section explains how to run the three core services locally:
66

77
- **Backend** (`backend/`, port 3000 by default) – orchestrator + REST APIs for repos/orgs/jobs.
88
- **Statesman** (`taco/cmd/statesman`, port 8080) – state storage API and Terraform Cloud-compatible endpoints.
9-
- **UI** (`ui/`, port 3030) – TanStack Start frontend that talks to both services and WorkOS.
9+
- **UI** (`ui/`, port 3030) – TanStack Start frontend that talks to both services and WorkOS. When tunneling (e.g., ngrok), expose the UI host; WorkOS and GitHub callbacks should point to the UI domain.
1010

1111
## Prerequisites
1212

@@ -23,17 +23,17 @@ This section explains how to run the three core services locally:
2323

2424
## High-level workflow
2525

26-
1) **Start backend** with internal + API endpoints enabled (so UI can call `/api/*` and `/github/*`).
27-
2) **Start statesman** with internal endpoints enabled; use memory storage for quick start.
28-
3) **Configure UI** `.env.local` with URLs + secrets + WorkOS creds; run `pnpm dev --host --port 3030`.
29-
4) **Sync org/user** into backend and statesman (WorkOS org id and user id/email) via the provided curl snippets in each page.
30-
5) (Optional) **GitHub App**: set `ORCHESTRATOR_GITHUB_APP_URL` to your install URL or `http://localhost:3000/github/setup` to create one via the backend.
26+
1) **Start backend** with internal + API endpoints enabled (so UI can call `/api/*` and `/github/*`).
27+
2) **Start statesman** with internal endpoints enabled; use memory storage for quick start.
28+
3) **Configure UI** `.env.local` with URLs + secrets + WorkOS creds; run `pnpm dev --host --port 3030`.
29+
4) **Sync org/user** into backend and statesman (WorkOS org id and user id/email) via the provided curl snippets in each page.
30+
5) (Optional) **GitHub App**: set `ORCHESTRATOR_GITHUB_APP_URL` to your install URL or `http://localhost:3000/github/setup` to create one via the backend. Use the UI domain for app callback/webhook URLs (see GitHub App settings page).
3131

3232
## Troubleshooting cheatsheet
3333

34-
- **Backend /api/* returns 404**: `DIGGER_ENABLE_API_ENDPOINTS` not `true` or org not upserted.
35-
- **Statesman 403**: webhook secret mismatch. **Statesman 404/500 resolving org**: org not synced (missing `external_org_id`).
36-
- **UI WorkOS auth succeeds but org is empty**: add membership in WorkOS and resync org/user to services.
34+
- **Backend /api/* returns 404**: `DIGGER_ENABLE_API_ENDPOINTS` not `true` or org not upserted.
35+
- **Statesman 403**: webhook secret mismatch. **Statesman 404/500 resolving org**: org not synced (missing `external_org_id`).
36+
- **UI WorkOS auth succeeds but org is empty**: add membership in WorkOS and resync org/user to services.
3737
- **GitHub connect opens 404**: set `ORCHESTRATOR_GITHUB_APP_URL` to a valid install/setup URL.
3838

3939
Continue with the per-service pages for commands and env examples.

docs/ce/local-development/statesman.mdx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ title: Statesman local setup
44

55
Statesman serves state storage + Terraform Cloud-compatible APIs. The UI uses its internal endpoints, so enable webhook auth and sync your org/user.
66

7+
## First-time setup (SQLite migrations)
8+
9+
If using SQLite with persistence, run migrations before starting:
10+
11+
```bash
12+
cd taco
13+
14+
# If you get checksum errors, regenerate the hash first:
15+
atlas migrate hash --dir file://migrations/sqlite
16+
17+
# Apply migrations (adjust path to match your OPENTACO_SQLITE_DB_PATH)
18+
atlas migrate apply --dir file://migrations/sqlite --url "sqlite://cmd/statesman/data/taco.db"
19+
```
20+
21+
If you don't have Atlas installed: `make atlas-install`
22+
723
## Quick start
824

925
1. Set env vars:
@@ -24,6 +40,15 @@ Statesman serves state storage + Terraform Cloud-compatible APIs. The UI uses it
2440

2541
Statesman resolves orgs by `external_org_id` (your WorkOS org id). If it cannot resolve, `/internal/api/units` will 500.
2642

43+
A helper script is available at `taco/cmd/statesman/sync-org.sh` - edit the values before running:
44+
45+
```bash
46+
chmod +x taco/cmd/statesman/sync-org.sh
47+
./taco/cmd/statesman/sync-org.sh
48+
```
49+
50+
Or run manually:
51+
2752
```bash
2853
SECRET=$OPENTACO_ENABLE_INTERNAL_ENDPOINTS
2954
ORG_ID=org_xxx # WorkOS org id
@@ -49,6 +74,8 @@ curl -s -X POST http://localhost:8080/internal/api/users \
4974

5075
## Troubleshooting
5176

77+
- **"no such table: organizations"**: Run migrations first (see First-time setup above).
78+
- **Atlas checksum mismatch**: Run `atlas migrate hash --dir file://migrations/sqlite` then retry apply.
5279
- **403**: webhook secret mismatch (`OPENTACO_ENABLE_INTERNAL_ENDPOINTS` vs UI `STATESMAN_BACKEND_WEBHOOK_SECRET`).
53-
- **404/500 resolving org**: org not synced; rerun the `orgs/sync` call above.
80+
- **404/500 resolving org**: org not synced; rerun the sync script or `orgs/sync` call above.
5481
- **SQLite quirks**: defaults to SQLite in-process; no config needed for local. For Postgres/MySQL, set `TACO_QUERY_BACKEND` and related envs (see `docs/ce/state-management/query-backend`).

docs/ce/local-development/ui.mdx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
title: UI local setup
33
---
44

5-
The UI is a TanStack Start app that authenticates via WorkOS and calls both backend and statesman.
5+
The UI is a TanStack Start app that authenticates via WorkOS and calls both backend and statesman. It also acts as the public gateway when tunneling (e.g., ngrok): expose the UI port, and point external callbacks to the UI domain.
66

77
## Quick start
88

99
1. Copy `.env.example` to `.env.local` in `ui/` and fill the essentials:
1010
```bash
1111
# URLs
12-
PUBLIC_URL=http://localhost:3030
13-
ALLOWED_HOSTS=localhost,127.0.0.1
12+
PUBLIC_URL=http://localhost:3030 # replace host with your public tunnel when exposing UI
13+
ALLOWED_HOSTS=localhost,127.0.0.1 # include your public tunnel host here
1414

1515
# WorkOS (User Management)
1616
WORKOS_CLIENT_ID=<your_workos_client_id>
1717
WORKOS_API_KEY=<your_workos_api_key>
1818
WORKOS_COOKIE_PASSWORD=<32+ random chars>
19-
WORKOS_REDIRECT_URI=http://localhost:3030/api/auth/callback
19+
WORKOS_REDIRECT_URI=http://localhost:3030/api/auth/callback # replace host with your public tunnel; must match WorkOS config
2020
WORKOS_WEBHOOK_SECRET=<if using webhooks locally via tunnel>
2121

2222
# Backend
@@ -40,7 +40,7 @@ The UI is a TanStack Start app that authenticates via WorkOS and calls both back
4040
pnpm install # or npm install
4141
pnpm dev --host --port 3030
4242
```
43-
Open `http://localhost:3030` and sign in with a WorkOS user that belongs to at least one org.
43+
Open `http://localhost:3030` (or your tunnel URL) and sign in with a WorkOS user that belongs to at least one org. Ensure the WorkOS redirect URI matches the public URL you configured.
4444
3. Ensure backend + statesman were started and the same secrets are in place (see [Backend](./backend) and [Statesman](./statesman)).
4545
4. Sync the WorkOS org/user to both services using the curl snippets on those pages (required for repos/units to load).
4646

@@ -49,3 +49,4 @@ The UI is a TanStack Start app that authenticates via WorkOS and calls both back
4949
- **NotFound/Forbidden listing units**: statesman org/user not synced or webhook secret mismatch.
5050
- **404 on repos or GitHub connect**: backend missing org/user, `DIGGER_ENABLE_API_ENDPOINTS` not set, or `ORCHESTRATOR_GITHUB_APP_URL` points to a non-existent path.
5151
- **WorkOS login succeeds but dashboard redirects to / or errors**: the signed-in user has no WorkOS org membership; add to an org and resync to services.
52+
- **WorkOS redirect blocked**: public URL not whitelisted; add your tunnel host to `ALLOWED_HOSTS` and to the WorkOS redirect URI list.

docs/docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@
171171
"ce/local-development/overview",
172172
"ce/local-development/backend",
173173
"ce/local-development/statesman",
174-
"ce/local-development/ui"
174+
"ce/local-development/ui",
175+
"ce/local-development/github-app"
175176
]
176177
},
177178
{

taco/cmd/statesman/sync-org.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
SECRET=topsecret # must match OPENTACO_ENABLE_INTERNAL_ENDPOINTS
4+
ORG_ID=org_xxx # your WorkOS org id
5+
ORG_NAME=my-org # internal org name/slug
6+
ORG_DISPLAY="My Org" # display name
7+
USER_ID=user_xxx # your WorkOS user id
8+
USER_EMAIL=you@example.com # your email
9+
10+
# create/sync org
11+
curl -s -X POST http://localhost:8080/internal/api/orgs/sync \
12+
-H "Authorization: Bearer $SECRET" \
13+
-H "X-User-ID: $USER_ID" -H "X-Email: $USER_EMAIL" \
14+
-H "Content-Type: application/json" \
15+
-d '{"name":"'"$ORG_NAME"'","display_name":"'"$ORG_DISPLAY"'","external_org_id":"'"$ORG_ID"'"}'
16+
17+
echo ""
18+
echo "Org synced. Now syncing user..."
19+
20+
# ensure user exists in that org
21+
curl -s -X POST http://localhost:8080/internal/api/users \
22+
-H "Authorization: Bearer $SECRET" \
23+
-H "X-Org-ID: $ORG_ID" -H "X-User-ID: $USER_ID" -H "X-Email: $USER_EMAIL" \
24+
-H "Content-Type: application/json" \
25+
-d '{"subject":"'"$USER_ID"'","email":"'"$USER_EMAIL"'"}'
26+
27+
echo ""
28+
echo "Done!"

0 commit comments

Comments
 (0)