diff --git a/Dockerfile b/Dockerfile index 5929322..dadbfbe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/go.mod b/go.mod index 2f5b221..edaf42b 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/main.go b/main.go index 7b18803..efee527 100644 --- a/main.go +++ b/main.go @@ -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)))