Slice 1: build green, MVP core flow

- New agentlib module (gitutil + deployer with NewGo / NewPHP) replaces
  agent-micro/internal so both agents can share it (Go's internal/ rule
  was blocking agent-gateway from importing agent-micro's packages).
- Migrate agents from legacy github.com/docker/docker/client to the
  current github.com/moby/moby/client v0.5.0 / moby/moby/api v1.55.0.
- Fix compile errors in the original committed code: missing
  gorilla/websocket import in control-plane/internal/ws/handlers.go,
  unaliased dockerclient reference, wrong SQLite driver name
  (sqlite3 -> sqlite), Dialer.Dial 3-return-value mismatch.
- scripts/build.sh: Go 1.23 -> 1.24, apk add git, safe.directory for
  bind-mounted host tree, chmod inside container (host can't chmod
  files owned by container root).
- README and REQUIREMENTS updated to reflect the actual architecture
  (Go + SQLite, no Spring Boot, moby SDK, per-deploy no image build)
  with a per-feature status checklist at the end of REQUIREMENTS.
This commit is contained in:
opencode
2026-06-24 01:43:43 +00:00
parent 7c1013e083
commit 2bc3ff73a2
18 changed files with 3218 additions and 321 deletions
+17 -11
View File
@@ -1,8 +1,8 @@
// Command agent-gateway runs on the API Gateway VM (172.18.139.186). It
// maintains a WebSocket to the control plane and deploys the gateway
// service. The gateway uses the same pipeline as the micro services —
// ponytail: same shape, different repo map. If the gateway ever needs a
// different build (PHP composer install, etc.), split the deployer package.
// maintains a WebSocket to the control plane and deploys the gateway
// which is a PHP project that runs in a pre-loaded php:8.3-apache
// container. The Go agent itself only orchestrates; it does not build
// the PHP code.
package main
import (
@@ -15,14 +15,16 @@ import (
"sync"
"time"
"github.com/docker/docker/client"
docker "github.com/moby/moby/client"
"github.com/gorilla/websocket"
"github.com/sdp/agent-micro/internal/deployer"
"github.com/sdp/agent-micro/internal/gitutil"
"github.com/sdp/agentlib/deployer"
"github.com/sdp/agentlib/gitutil"
"github.com/sdp/protocol"
)
// ponytail: the gateway VM holds a single PHP project at the path below.
// Real version reads a yaml config like agent-micro does.
var repos = map[string]string{
"api-gateway": "/home/user/SDP",
}
@@ -32,7 +34,7 @@ func main() {
nodeID := flag.String("node", envOr("SDP_NODE_ID", "gateway"), "node id sent in WS query")
flag.Parse()
cli, err := client.NewClientWithOpts(client.FromEnv)
cli, err := docker.NewClientWithOpts(docker.FromEnv)
if err != nil {
log.Fatalf("docker client: %v", err)
}
@@ -66,9 +68,12 @@ func main() {
func dial(u *url.URL) (*websocket.Conn, error) {
log.Printf("connecting to %s", u)
return websocket.DefaultDialer.Dial(u.String(), nil)
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
return c, err
}
// writer pumps outbound events to whichever conn is current. If conn is
// nil (during reconnect), messages buffer until the next conn is set.
func writer(conn **websocket.Conn, mu *sync.Mutex, out <-chan []byte) {
for msg := range out {
mu.Lock()
@@ -88,7 +93,7 @@ type runState struct {
cancel context.CancelFunc
}
func readLoop(c *websocket.Conn, cli *dockerclient.Client, out chan<- []byte, mu *sync.Mutex, connPtr **websocket.Conn) {
func readLoop(c *websocket.Conn, cli *docker.Client, out chan<- []byte, mu *sync.Mutex, connPtr **websocket.Conn) {
inflight := map[string]*runState{}
for {
_, raw, err := c.ReadMessage()
@@ -123,7 +128,7 @@ func readLoop(c *websocket.Conn, cli *dockerclient.Client, out chan<- []byte, mu
})
continue
}
d := deployer.New(cli, frame.Data.DeploymentID,
d := deployer.NewPHP(cli, frame.Data.DeploymentID,
frame.Data.Repository, repoPath,
frame.Data.Branch, frame.Data.Env,
gitutil.Creds{Username: frame.Data.Username, Password: frame.Data.Password},
@@ -159,6 +164,7 @@ func emit(out chan<- []byte, e protocol.Event) {
select {
case out <- b:
default:
// ponytail: drop on backpressure. Deploys are rare.
}
}
+10 -3
View File
@@ -1,8 +1,15 @@
module github.com/sdp/agent-gateway
go 1.23
go 1.24
require (
github.com/docker/docker/client v0.0.0-00010101000000-000000000000
github.com/sdp/protocol v0.0.0
github.com/gorilla/websocket v1.5.1
github.com/moby/moby/client v0.5.0
github.com/sdp/agentlib v0.0.0-00010101000000-000000000000
github.com/sdp/protocol v0.0.0-00010101000000-000000000000
)
replace (
github.com/sdp/agentlib => ../agentlib
github.com/sdp/protocol => ../protocol
)