Files
archie/internal/app/archied/model_egress_setup.go
T
sam f92c5b4536
ci/woodpecker/pr/quality Pipeline was successful
Quality / check (pull_request) Canceled after 7m39s
chore(runtime): delete Kit and external agent harness support (#1877)
Archie runs its own agent loop only. Removes Kit resolution and launch,
the harness runner and adapters, the setup terminal and sandbox view,
harness secrets and OAuth capture (table dropped in migration 0075), the
task-tools contract that only Kit containers reached, and the
sandbox-kit-spec dependency. Agent profiles carry image and tools only.
The egress proxy keeps the model-session path; the sandbox relay code
stays for #1867.
2026-11-12 21:29:05 +11:00

47 lines
1.8 KiB
Go

package archied
import (
"context"
"errors"
"net"
"net/http"
"path/filepath"
"time"
"github.com/samcharles93/archie-core/internal/infrastructure/egress"
)
// setupModelEgress starts the egress proxy task containers send their model
// calls through, on the worker bridge's host gateway. It degrades to no
// proxy rather than failing boot; a task that needs a keyed provider then
// reports why it cannot start.
func (b *boot) setupModelEgress(ctx context.Context) {
pool, log := b.containerPool, b.log
if pool == nil || pool.HostGateway() == "" {
log.InfoContext(ctx, "model egress disabled: it needs the managed container pool on a bridge with a host gateway")
return
}
caDir := filepath.Join(b.cfg.StateDir, "egress")
ca, err := egress.LoadOrCreateCA(caDir)
if err != nil {
log.WarnContext(ctx, "model egress disabled: egress CA", "err", err)
return
}
ln, err := (&net.ListenConfig{}).Listen(ctx, "tcp", net.JoinHostPort(pool.HostGateway(), "0"))
if err != nil {
log.WarnContext(ctx, "model egress disabled: egress proxy listener", "err", err)
return
}
resolver := runCredentialResolver{runs: b.stateStoreGrants.Client, models: b.taskModels, config: b.cfgHolder, secrets: b.secrets, credentials: b.credentialWatch}
proxy := egress.NewProxy(ca, egress.ProxyOptions{Resolver: resolver})
srv := &http.Server{Handler: proxy, ReadHeaderTimeout: 30 * time.Second}
go func() {
if err := srv.Serve(ln); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.ErrorContext(ctx, "egress proxy stopped", "err", err)
}
}()
b.addCleanup(func() { _ = srv.Close() })
b.modelEgress = modelEgress{proxy: proxy, addr: ln.Addr().String(), caFile: egress.CACertPath(caDir), config: b.cfgHolder, secrets: b.secrets}
log.InfoContext(ctx, "model egress enabled", "proxy", ln.Addr().String())
}