-
Notifications
You must be signed in to change notification settings - Fork 32
Fix issue 64 #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix issue 64 #71
Changes from all commits
e24ae05
b4cdaac
1aef50c
b7a3fe3
d1f24f8
5eab334
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Multi-stage build for agentcube-router | ||
| FROM golang:1.24.9-alpine AS builder | ||
|
|
||
| # Build arguments for multi-architecture support | ||
| ARG TARGETOS=linux | ||
| ARG TARGETARCH | ||
|
|
||
| WORKDIR /workspace | ||
|
|
||
| # Copy go mod files | ||
| COPY go.mod go.sum ./ | ||
| RUN go mod download | ||
|
|
||
| # Copy source code | ||
| COPY cmd/ cmd/ | ||
| COPY pkg/ pkg/ | ||
| COPY client-go/ client-go/ | ||
|
|
||
| # Build with dynamic architecture support | ||
| # Supports amd64, arm64, arm/v7, etc. | ||
| RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ | ||
| go build -o agentcube-router ./cmd/router | ||
|
|
||
| # Runtime image | ||
| FROM alpine:3.19 | ||
|
|
||
| RUN apk --no-cache add ca-certificates | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Copy binary from builder | ||
| COPY --from=builder /workspace/agentcube-router . | ||
|
|
||
| # Run as non-root user | ||
| RUN adduser -D -u 1000 router | ||
| USER router | ||
|
|
||
| EXPOSE 8080 | ||
|
|
||
| ENTRYPOINT ["/app/agentcube-router"] | ||
| CMD ["--port=8080", "--debug"] |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,75 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| package main | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||||||||||||||
| "context" | ||||||||||||||||||||||||||||||||||||||||||||||
| "flag" | ||||||||||||||||||||||||||||||||||||||||||||||
| "log" | ||||||||||||||||||||||||||||||||||||||||||||||
| "os" | ||||||||||||||||||||||||||||||||||||||||||||||
| "os/signal" | ||||||||||||||||||||||||||||||||||||||||||||||
| "syscall" | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/volcano-sh/agentcube/pkg/router" | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| func main() { | ||||||||||||||||||||||||||||||||||||||||||||||
| var ( | ||||||||||||||||||||||||||||||||||||||||||||||
| port = flag.String("port", "8080", "Router API server port") | ||||||||||||||||||||||||||||||||||||||||||||||
| enableTLS = flag.Bool("enable-tls", false, "Enable TLS (HTTPS)") | ||||||||||||||||||||||||||||||||||||||||||||||
| tlsCert = flag.String("tls-cert", "", "Path to TLS certificate file") | ||||||||||||||||||||||||||||||||||||||||||||||
| tlsKey = flag.String("tls-key", "", "Path to TLS key file") | ||||||||||||||||||||||||||||||||||||||||||||||
| debug = flag.Bool("debug", true, "Enable debug mode") | ||||||||||||||||||||||||||||||||||||||||||||||
| maxConcurrentRequests = flag.Int("max-concurrent-requests", 1000, "Maximum number of concurrent requests") | ||||||||||||||||||||||||||||||||||||||||||||||
| requestTimeout = flag.Int("request-timeout", 30, "Request timeout in seconds") | ||||||||||||||||||||||||||||||||||||||||||||||
| maxIdleConns = flag.Int("max-idle-conns", 100, "Maximum number of idle connections") | ||||||||||||||||||||||||||||||||||||||||||||||
| maxConnsPerHost = flag.Int("max-conns-per-host", 10, "Maximum number of connections per host") | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Parse command line flags | ||||||||||||||||||||||||||||||||||||||||||||||
| flag.Parse() | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Create Router API server configuration | ||||||||||||||||||||||||||||||||||||||||||||||
| config := &router.Config{ | ||||||||||||||||||||||||||||||||||||||||||||||
| Port: *port, | ||||||||||||||||||||||||||||||||||||||||||||||
| Debug: *debug, | ||||||||||||||||||||||||||||||||||||||||||||||
| EnableTLS: *enableTLS, | ||||||||||||||||||||||||||||||||||||||||||||||
| TLSCert: *tlsCert, | ||||||||||||||||||||||||||||||||||||||||||||||
| TLSKey: *tlsKey, | ||||||||||||||||||||||||||||||||||||||||||||||
| MaxConcurrentRequests: *maxConcurrentRequests, | ||||||||||||||||||||||||||||||||||||||||||||||
| RequestTimeout: *requestTimeout, | ||||||||||||||||||||||||||||||||||||||||||||||
| MaxIdleConns: *maxIdleConns, | ||||||||||||||||||||||||||||||||||||||||||||||
| MaxConnsPerHost: *maxConnsPerHost, | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Create Router API server | ||||||||||||||||||||||||||||||||||||||||||||||
| server, err := router.NewServer(config) | ||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||
| log.Fatalf("Failed to create Router API server: %v", err) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Setup signal handling with context cancellation | ||||||||||||||||||||||||||||||||||||||||||||||
| ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) | ||||||||||||||||||||||||||||||||||||||||||||||
| defer cancel() | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Start Router API server in goroutine | ||||||||||||||||||||||||||||||||||||||||||||||
| errCh := make(chan error, 1) | ||||||||||||||||||||||||||||||||||||||||||||||
| go func() { | ||||||||||||||||||||||||||||||||||||||||||||||
| log.Printf("Starting agentcube Router server on port %s", *port) | ||||||||||||||||||||||||||||||||||||||||||||||
| if err := server.Start(ctx); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||
| errCh <- err | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| }() | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Wait for signal or error | ||||||||||||||||||||||||||||||||||||||||||||||
| select { | ||||||||||||||||||||||||||||||||||||||||||||||
| case <-ctx.Done(): | ||||||||||||||||||||||||||||||||||||||||||||||
| log.Println("Received shutdown signal, shutting down gracefully...") | ||||||||||||||||||||||||||||||||||||||||||||||
| // Cancel the context to trigger server shutdown | ||||||||||||||||||||||||||||||||||||||||||||||
| cancel() | ||||||||||||||||||||||||||||||||||||||||||||||
| // Wait for server goroutine to exit after graceful shutdown is complete | ||||||||||||||||||||||||||||||||||||||||||||||
| <-errCh | ||||||||||||||||||||||||||||||||||||||||||||||
| case err := <-errCh: | ||||||||||||||||||||||||||||||||||||||||||||||
| log.Fatalf("Server error: %v", err) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+63
to
+72
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a race condition in the graceful shutdown logic. If the server fails to start (e.g., port already in use) and a shutdown signal is received at the same time, the To fix this, you should ensure that any error from
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| log.Println("Router server stopped") | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
cleantarget was modified to removeagentcube-routerbut it no longer removesagentcube-apiserver. Since thebuildtarget foragentcube-apiserverstill exists, it should probably be included in thecleantarget to avoid leaving stale artifacts.