This commit is contained in:
Christoph Haas 2026-08-22 10:33:53 +02:00
parent e7bd20eae9
commit 434adf1f66
3 changed files with 17 additions and 2 deletions

View file

@ -26,8 +26,10 @@ RUN tar -xzf /tmp/onnx.tgz -C /tmp
RUN mkdir -p /usr/local/lib && cp /tmp/onnxruntime-linux-x64-1.27.0/lib/libonnxruntime.so* /usr/local/lib/
RUN rm -rf /tmp/onnxruntime-linux-x64-1.27.0 /tmp/onnx.tgz
# Build Go binary with CGO enabled
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o /app/vector-server main.go 2>&1
# Build Go binary with CGO enabled, baking in the git commit (provided by Coolify)
ARG SOURCE_COMMIT=dev
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \
go build -ldflags "-X main.version=${SOURCE_COMMIT}" -o /app/vector-server main.go 2>&1
# Stage 2: Runtime
FROM debian:bookworm-slim

2
go.mod
View file

@ -8,7 +8,9 @@ require (
)
require (
github.com/emirpasic/gods v1.18.1 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/schollz/progressbar/v2 v2.15.0 // indirect
github.com/sugarme/regexpset v0.0.0-20200920021344-4d4ec8eaf93c // indirect

11
main.go
View file

@ -20,6 +20,7 @@ var (
session *onnxruntime_go.DynamicAdvancedSession
maxLen = int64(128)
embeddingSize = int64(384)
version = "dev"
)
func init() {
@ -218,6 +219,15 @@ func healthHandler(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(map[string]string{"status": "ok"})
}
func versionHandler(w http.ResponseWriter, r *http.Request) {
v := os.Getenv("SOURCE_COMMIT")
if v == "" {
v = version
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]string{"version": v})
}
func main() {
port := os.Getenv("PORT")
if port == "" {
@ -226,6 +236,7 @@ func main() {
http.HandleFunc("/vector", vectorHandler)
http.HandleFunc("/ok", healthHandler)
http.HandleFunc("/version", versionHandler)
log.SetOutput(os.Stdout)
log.Printf("Starting server on port %s...\n", port)
log.Fatal(http.ListenAndServe(":"+port, loggingMiddleware(http.DefaultServeMux)))