Skip to content

Commit 5f7fd9b

Browse files
authored
UPDATE embed palette into gateway services (#49)
* UPDATE embed palette into gateway services - add palette checks to images Signed-off-by: ParleSec <mason@masonparle.com> * UPDATE quick start docs + palette ref Signed-off-by: ParleSec <mason@masonparle.com> --------- Signed-off-by: ParleSec <mason@masonparle.com>
1 parent fb313c4 commit 5f7fd9b

7 files changed

Lines changed: 43 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Run the full stack locally with Docker:
2727
```bash
2828
git clone https://github.com/ParleSec/ProtocolSoup.git
2929
cd ProtocolSoup/docker
30-
docker compose up -d
30+
docker compose up -d --build
3131
```
3232

3333
Then open:

backend/cmd/gateway/main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,28 @@ import (
1212

1313
"github.com/ParleSec/ProtocolSoup/internal/core"
1414
"github.com/ParleSec/ProtocolSoup/internal/gateway"
15+
"github.com/ParleSec/ProtocolSoup/internal/palette"
1516
)
1617

1718
func main() {
1819
cfg := core.LoadConfig()
1920

21+
var paletteSvc *palette.Service
22+
if cfg.PaletteDBPath != "" {
23+
svc, err := palette.NewService(cfg.PaletteDBPath)
24+
if err != nil {
25+
if cfg.IsProduction() {
26+
log.Fatalf("Failed to load palette index at %s: %v", cfg.PaletteDBPath, err)
27+
}
28+
log.Printf("Palette service disabled: %v", err)
29+
} else {
30+
paletteSvc = svc
31+
stats := svc.Stats()
32+
log.Printf("Palette service initialized from %s (%d artefacts, index v%s)",
33+
cfg.PaletteDBPath, stats.ArtefactCount, stats.IndexVersion)
34+
}
35+
}
36+
2037
upstreams := []gateway.UpstreamConfig{
2138
{Name: "federation", BaseURL: strings.TrimSpace(os.Getenv("FEDERATION_SERVICE_URL"))},
2239
{Name: "scim", BaseURL: strings.TrimSpace(os.Getenv("SCIM_SERVICE_URL"))},
@@ -33,6 +50,7 @@ func main() {
3350
StartupRetryInitial: envDuration("GATEWAY_STARTUP_RETRY_INITIAL", 2*time.Second),
3451
StartupRetryMax: envDuration("GATEWAY_STARTUP_RETRY_MAX", 30*time.Second),
3552
RequestTimeout: envDuration("GATEWAY_REQUEST_TIMEOUT", 5*time.Second),
53+
Palette: paletteSvc,
3654
})
3755
if err != nil {
3856
log.Fatalf("Failed to initialize gateway: %v", err)

backend/internal/gateway/gateway.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"sync"
1616
"time"
1717

18+
"github.com/ParleSec/ProtocolSoup/internal/palette"
1819
"github.com/go-chi/chi/v5"
1920
"github.com/go-chi/cors"
2021
)
@@ -29,6 +30,9 @@ type Config struct {
2930
StartupRetryInitial time.Duration
3031
StartupRetryMax time.Duration
3132
RequestTimeout time.Duration
33+
// Palette serves POST /api/palette/query from a local SQLite index. Nil
34+
// omits the route (split deployments without a baked index).
35+
Palette *palette.Service
3236
}
3337

3438
// UpstreamConfig represents an upstream service.
@@ -66,6 +70,8 @@ type Upstream struct {
6670
type Gateway struct {
6771
cfg Config
6872

73+
palette *palette.Service
74+
6975
client *http.Client
7076
upstreams map[string]*Upstream
7177
order []string
@@ -119,7 +125,8 @@ func NewGateway(cfg Config) (*Gateway, error) {
119125
}
120126

121127
return &Gateway{
122-
cfg: cfg,
128+
cfg: cfg,
129+
palette: cfg.Palette,
123130
client: &http.Client{
124131
Timeout: cfg.RequestTimeout,
125132
},
@@ -161,6 +168,10 @@ func (g *Gateway) Router() http.Handler {
161168
r.Post("/lookingglass/decode", g.handleDecodeToken)
162169
r.Get("/lookingglass/sessions", g.handleListSessions)
163170
r.Get("/lookingglass/sessions/{id}", g.handleGetSession)
171+
172+
if g.palette != nil {
173+
r.Post("/palette/query", g.palette.Handler())
174+
}
164175
})
165176

166177
r.Get("/ws/lookingglass/{session}", g.handleLookingGlassWS)

backend/internal/gateway/handlers.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ func (g *Gateway) handleAPIIndex(w http.ResponseWriter, r *http.Request) {
6060
"lookingglass": "/api/lookingglass",
6161
"lookingglass_ws": "/ws/lookingglass/{session}",
6262
}
63+
if g.palette != nil {
64+
endpoints["palette"] = "/api/palette/query"
65+
}
6366

6467
g.writeJSON(w, http.StatusOK, apiIndexResponse{
6568
Service: "protocol-lens-gateway",

docker/docker-compose.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Protocol Soup - Split Backend Services (Base)
2-
# Run with: docker compose up -d
2+
# Run with: docker compose up -d --build
3+
# After pulling new code, always pass --build so frontend and gateway images
4+
# are rebuilt from source (palette UI and /api/palette/query are baked in).
35
#
46
# This starts:
57
# - Gateway (API aggregation + protocol routing)
@@ -45,6 +47,7 @@ services:
4547
- SHOWCASE_LISTEN_ADDR=:8080
4648
- SHOWCASE_BASE_URL=http://localhost:8080
4749
- SHOWCASE_CORS_ORIGINS=http://localhost:3000,http://localhost:5173
50+
- SHOWCASE_PALETTE_DB=/app/palette.db
4851
- FEDERATION_SERVICE_URL=http://federation-service:8080
4952
- SCIM_SERVICE_URL=http://scim-service:8080
5053
- SSF_SERVICE_URL=http://ssf-service:8080
@@ -177,6 +180,7 @@ services:
177180
NEXT_PUBLIC_WS_BASE_URL: ws://localhost:8080
178181
# For using published GHCR images, comment 'build:' above and uncomment:
179182
# image: ghcr.io/parlesec/protocolsoup-frontend:latest
183+
image: protocol-lens-frontend:latest
180184
container_name: protocol-showcase-frontend
181185
ports:
182186
- "3000:3000"

docs/starlight/src/content/docs/deploy/deployment-models.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ Run the complete ProtocolSoup experience with all services.
1111

1212
```bash
1313
cd docker
14-
docker compose up -d
14+
docker compose up -d --build
1515
```
1616

1717
**Services started:** frontend, gateway, federation-service, scim-service, ssf-service
1818

19+
The gateway image ships the [palette content index](/deploy/palette-index/) at `/app/palette.db` and serves `POST /api/palette/query` for homepage search and **cmd+K**. Rebuild images after pulling new code (`--build`); `docker compose up -d` alone reuses cached layers and can leave you on an older UI.
20+
1921
**Add SPIFFE:**
2022

2123
```bash

docs/starlight/src/content/docs/start-here/quickstart.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Run the frontend, gateway, federation, SCIM, and SSF services together.
1616

1717
```bash
1818
cd docker
19-
docker compose up -d
19+
docker compose up -d --build
2020
```
2121

2222
This starts five services:

0 commit comments

Comments
 (0)