|
| 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. |
0 commit comments