Skip to content

Commit 61637d4

Browse files
committed
Add docs for local development
1 parent 6f1ead0 commit 61637d4

File tree

5 files changed

+215
-1
lines changed

5 files changed

+215
-1
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
title: Backend (orchestrator) local setup
3+
---
4+
5+
The backend serves orchestration APIs, GitHub app endpoints, and internal APIs the UI relies on.
6+
7+
## Quick start
8+
9+
1. Create `backend/.env` with the essentials (adjust DB URL/ports):
10+
```bash
11+
DATABASE_URL=postgres://postgres:root@localhost:5432/postgres?sslmode=disable
12+
DIGGER_INTERNAL_SECRET=orchestrator-secret # must match UI ORCHESTRATOR_BACKEND_SECRET
13+
DIGGER_ENABLE_INTERNAL_ENDPOINTS=true # enables /_internal/*
14+
DIGGER_ENABLE_API_ENDPOINTS=true # enables /api/*
15+
HOSTNAME=http://localhost:3000 # used for GitHub app callbacks
16+
```
17+
Optional but useful:
18+
- `GITHUB_APP_ID`, `GITHUB_APP_PEM`, `GITHUB_APP_WEBHOOK_SECRET` if you already have an app.
19+
- `GITHUB_ORG` if you want `/github/setup` to target an org.
20+
2. Start the service (from `backend/`):
21+
```bash
22+
set -a; source .env; set +a
23+
go run main.go # or: make start
24+
```
25+
Default port: `3000`.
26+
27+
## Make the UI happy
28+
29+
- The UI calls `/api/*` and `/github/*` with `Authorization: Bearer $DIGGER_INTERNAL_SECRET` and `DIGGER_ORG_ID`/`DIGGER_USER_ID` headers.
30+
- You must upsert the WorkOS org + user the UI is authenticated as:
31+
```bash
32+
SECRET=$DIGGER_INTERNAL_SECRET
33+
ORG_ID=org_xxx # WorkOS org id
34+
ORG_NAME=my-org # slug shown in backend
35+
ADMIN_EMAIL=you@example.com
36+
USER_ID=user_xxx # WorkOS user id
37+
USER_EMAIL=$ADMIN_EMAIL
38+
39+
# org
40+
curl -s -X POST http://localhost:3000/_internal/api/upsert_org \
41+
-H "Authorization: Bearer $SECRET" \
42+
-H "Content-Type: application/json" \
43+
-d '{"org_name":"'"$ORG_NAME"'","external_source":"workos","external_id":"'"$ORG_ID"'","admin_email":"'"$ADMIN_EMAIL"'"}'
44+
45+
# user
46+
curl -s -X POST http://localhost:3000/_internal/api/create_user \
47+
-H "Authorization: Bearer $SECRET" \
48+
-H "Content-Type: application/json" \
49+
-d '{"external_source":"workos","external_id":"'"$USER_ID"'","email":"'"$USER_EMAIL"'","external_org_id":"'"$ORG_ID"'"}'
50+
```
51+
52+
## GitHub app integration
53+
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`).
55+
- To create a new app via the backend, open `http://localhost:3000/github/setup` (requires `HOSTNAME` set to a reachable URL for callbacks).
56+
57+
## Troubleshooting
58+
59+
- **404 on /api/repos**: ensure `DIGGER_ENABLE_API_ENDPOINTS=true` and the org/user above are created.
60+
- **401/403**: verify `Authorization` header uses `DIGGER_INTERNAL_SECRET`.
61+
- **GitHub connect 404**: set `ORCHESTRATOR_GITHUB_APP_URL` as described.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: Local development overview
3+
---
4+
5+
This section explains how to run the three core services locally:
6+
7+
- **Backend** (`backend/`, port 3000 by default) – orchestrator + REST APIs for repos/orgs/jobs.
8+
- **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.
10+
11+
## Prerequisites
12+
13+
- Go toolchain for backend + statesman, Node 18+ for UI (`pnpm` or `npm`).
14+
- A WorkOS project with User Management enabled and at least one organization + member (needed for UI auth and org IDs).
15+
- Optional: GitHub App for repo onboarding (the backend can help you create one via `/github/setup`).
16+
17+
## Shared secrets and ports
18+
19+
- Pick two secrets and reuse them across components:
20+
- `ORCHESTRATOR_BACKEND_SECRET``DIGGER_INTERNAL_SECRET` (backend) ≡ UI env.
21+
- `STATESMAN_BACKEND_WEBHOOK_SECRET``OPENTACO_ENABLE_INTERNAL_ENDPOINTS` (statesman) ≡ UI env.
22+
- Default ports: backend `3000`, statesman `8080`, UI `3030`.
23+
24+
## High-level workflow
25+
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.
31+
32+
## Troubleshooting cheatsheet
33+
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.
37+
- **GitHub connect opens 404**: set `ORCHESTRATOR_GITHUB_APP_URL` to a valid install/setup URL.
38+
39+
Continue with the per-service pages for commands and env examples.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: Statesman local setup
3+
---
4+
5+
Statesman serves state storage + Terraform Cloud-compatible APIs. The UI uses its internal endpoints, so enable webhook auth and sync your org/user.
6+
7+
## Quick start
8+
9+
1. Set env vars:
10+
```bash
11+
OPENTACO_ENABLE_INTERNAL_ENDPOINTS=statesman-secret # must match UI STATESMAN_BACKEND_WEBHOOK_SECRET
12+
OPENTACO_AUTH_DISABLE=true # skips OIDC for local
13+
OPENTACO_STORAGE=memory # default; uses SQLite query backend automatically
14+
# Optional: OPENTACO_SECRET_KEY for signed URLs; OPENTACO_PORT=8080
15+
```
16+
2. Run the service (from repo root):
17+
```bash
18+
cd taco
19+
go run cmd/statesman/main.go -storage memory -auth-disable # or ./statesman with the same flags
20+
```
21+
Default port: `8080`.
22+
23+
## Sync org and user (required for UI)
24+
25+
Statesman resolves orgs by `external_org_id` (your WorkOS org id). If it cannot resolve, `/internal/api/units` will 500.
26+
27+
```bash
28+
SECRET=$OPENTACO_ENABLE_INTERNAL_ENDPOINTS
29+
ORG_ID=org_xxx # WorkOS org id
30+
ORG_NAME=digger-org # slug to store
31+
ORG_DISPLAY="Digger Org"
32+
USER_ID=user_xxx # WorkOS user id
33+
USER_EMAIL=you@example.com
34+
35+
# create/sync org
36+
curl -s -X POST http://localhost:8080/internal/api/orgs/sync \
37+
-H "Authorization: Bearer $SECRET" \
38+
-H "X-User-ID: $USER_ID" -H "X-Email: $USER_EMAIL" \
39+
-H "Content-Type: application/json" \
40+
-d '{"name":"'"$ORG_NAME"'","display_name":"'"$ORG_DISPLAY"'","external_org_id":"'"$ORG_ID"'"}'
41+
42+
# ensure user exists in that org
43+
curl -s -X POST http://localhost:8080/internal/api/users \
44+
-H "Authorization: Bearer $SECRET" \
45+
-H "X-Org-ID: '$ORG_ID'" -H "X-User-ID: $USER_ID" -H "X-Email: $USER_EMAIL" \
46+
-H "Content-Type: application/json" \
47+
-d '{"subject":"'"$USER_ID"'","email":"'"$USER_EMAIL"'"}'
48+
```
49+
50+
## Troubleshooting
51+
52+
- **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.
54+
- **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: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: UI local setup
3+
---
4+
5+
The UI is a TanStack Start app that authenticates via WorkOS and calls both backend and statesman.
6+
7+
## Quick start
8+
9+
1. Copy `.env.example` to `.env.local` in `ui/` and fill the essentials:
10+
```bash
11+
# URLs
12+
PUBLIC_URL=http://localhost:3030
13+
ALLOWED_HOSTS=localhost,127.0.0.1
14+
15+
# WorkOS (User Management)
16+
WORKOS_CLIENT_ID=<your_workos_client_id>
17+
WORKOS_API_KEY=<your_workos_api_key>
18+
WORKOS_COOKIE_PASSWORD=<32+ random chars>
19+
WORKOS_REDIRECT_URI=http://localhost:3030/api/auth/callback
20+
WORKOS_WEBHOOK_SECRET=<if using webhooks locally via tunnel>
21+
22+
# Backend
23+
ORCHESTRATOR_BACKEND_URL=http://localhost:3000
24+
ORCHESTRATOR_BACKEND_SECRET=orchestrator-secret # matches backend DIGGER_INTERNAL_SECRET
25+
ORCHESTRATOR_GITHUB_APP_URL=http://localhost:3000/github/setup # or your app install URL
26+
27+
# Statesman
28+
STATESMAN_BACKEND_URL=http://localhost:8080
29+
STATESMAN_BACKEND_WEBHOOK_SECRET=statesman-secret # matches OPENTACO_ENABLE_INTERNAL_ENDPOINTS
30+
31+
# Optional
32+
DRIFT_REPORTING_BACKEND_URL=http://localhost:3004
33+
DRIFT_REPORTING_BACKEND_WEBHOOK_SECRET=...
34+
POSTHOG_KEY=...
35+
```
36+
In WorkOS, add `http://localhost:3030/api/auth/callback` as a redirect.
37+
2. Install deps and run:
38+
```bash
39+
cd ui
40+
pnpm install # or npm install
41+
pnpm dev --host --port 3030
42+
```
43+
Open `http://localhost:3030` and sign in with a WorkOS user that belongs to at least one org.
44+
3. Ensure backend + statesman were started and the same secrets are in place (see [Backend](./backend) and [Statesman](./statesman)).
45+
4. Sync the WorkOS org/user to both services using the curl snippets on those pages (required for repos/units to load).
46+
47+
## Common errors
48+
49+
- **NotFound/Forbidden listing units**: statesman org/user not synced or webhook secret mismatch.
50+
- **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.
51+
- **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.

docs/docs.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@
165165
"ce/azure-specific/azure-devops-locking-connection-methods"
166166
]
167167
},
168+
{
169+
"group": "Local Development",
170+
"pages": [
171+
"ce/local-development/overview",
172+
"ce/local-development/backend",
173+
"ce/local-development/statesman",
174+
"ce/local-development/ui"
175+
]
176+
},
168177
{
169178
"group": "Contributing",
170179
"pages": [
@@ -213,4 +222,4 @@
213222
"linkedin": "https://www.linkedin.com/company/diggerhq/"
214223
}
215224
}
216-
}
225+
}

0 commit comments

Comments
 (0)