Skip to content

Commit 3af8549

Browse files
committed
feat(version): add server version endpoint and client version display
1 parent c0808f3 commit 3af8549

File tree

7 files changed

+74
-5
lines changed

7 files changed

+74
-5
lines changed

.github/workflows/release.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ jobs:
137137
platforms: linux/amd64, linux/arm64
138138
build-args: |
139139
"LLAMA_SERVER_VERSION=${{ inputs.llamaServerVersion }}"
140+
"VERSION=${{ inputs.releaseTag }}"
140141
push: true
141142
sbom: true
142143
provenance: mode=max
@@ -152,6 +153,7 @@ jobs:
152153
"LLAMA_SERVER_VERSION=${{ inputs.llamaServerVersion }}"
153154
"LLAMA_SERVER_VARIANT=cuda"
154155
"BASE_IMAGE=nvidia/cuda:12.9.0-runtime-ubuntu24.04"
156+
"VERSION=${{ inputs.releaseTag }}"
155157
push: true
156158
sbom: true
157159
provenance: mode=max
@@ -170,6 +172,7 @@ jobs:
170172
"VLLM_VERSION=${{ inputs.vllmVersion }}"
171173
"VLLM_CUDA_VERSION=cu130"
172174
"VLLM_PYTHON_TAG=cp38-abi3"
175+
"VERSION=${{ inputs.releaseTag }}"
173176
push: true
174177
sbom: true
175178
provenance: mode=max
@@ -186,6 +189,7 @@ jobs:
186189
"LLAMA_SERVER_VARIANT=cuda"
187190
"BASE_IMAGE=nvidia/cuda:12.9.0-runtime-ubuntu24.04"
188191
"SGLANG_VERSION=${{ inputs.sglangVersion }}"
192+
"VERSION=${{ inputs.releaseTag }}"
189193
push: true
190194
sbom: true
191195
provenance: mode=max
@@ -199,6 +203,7 @@ jobs:
199203
platforms: linux/amd64, linux/arm64
200204
build-args: |
201205
"LLAMA_SERVER_VERSION=${{ inputs.llamaServerVersion }}"
206+
"VERSION=${{ inputs.releaseTag }}"
202207
push: true
203208
sbom: true
204209
provenance: mode=max
@@ -214,6 +219,7 @@ jobs:
214219
"LLAMA_SERVER_VERSION=${{ inputs.llamaServerVersion }}"
215220
"LLAMA_SERVER_VARIANT=rocm"
216221
"BASE_IMAGE=rocm/dev-ubuntu-22.04"
222+
"VERSION=${{ inputs.releaseTag }}"
217223
push: true
218224
sbom: true
219225
provenance: mode=max
@@ -230,6 +236,7 @@ jobs:
230236
"LLAMA_SERVER_VERSION=${{ inputs.llamaServerVersion }}"
231237
"LLAMA_SERVER_VARIANT=musa"
232238
"BASE_IMAGE=mthreads/musa:rc4.3.0-runtime-ubuntu22.04-amd64"
239+
"VERSION=${{ inputs.releaseTag }}"
233240
push: true
234241
sbom: true
235242
provenance: mode=max
@@ -246,6 +253,7 @@ jobs:
246253
"LLAMA_SERVER_VERSION=${{ inputs.llamaServerVersion }}"
247254
"LLAMA_SERVER_VARIANT=cann"
248255
"BASE_IMAGE=ascendai/cann:8.2.rc2-910b-ubuntu22.04-py3.11"
256+
"VERSION=${{ inputs.releaseTag }}"
249257
push: true
250258
sbom: true
251259
provenance: mode=max

Dockerfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ ARG LLAMA_BINARY_PATH=/com.docker.llama-server.native.linux.${LLAMA_SERVER_VARIA
99
# use 22.04 for gpu variants to match ROCm/CUDA base images
1010
ARG BASE_IMAGE=ubuntu:26.04
1111

12+
ARG VERSION=dev
13+
1214
FROM docker.io/library/golang:${GO_VERSION}-bookworm AS builder
1315

16+
ARG VERSION
17+
1418
# Install git for go mod download if needed
1519
RUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/*
1620

@@ -30,13 +34,14 @@ COPY --link . .
3034
# Build the Go binary (static build)
3135
RUN --mount=type=cache,target=/go/pkg/mod \
3236
--mount=type=cache,target=/root/.cache/go-build \
33-
CGO_ENABLED=1 GOOS=linux go build -ldflags="-s -w" -o model-runner .
37+
CGO_ENABLED=1 GOOS=linux go build -ldflags="-s -w -X main.Version=${VERSION}" -o model-runner .
3438

3539
# Build the Go binary for SGLang (without vLLM)
3640
FROM builder AS builder-sglang
41+
ARG VERSION
3742
RUN --mount=type=cache,target=/go/pkg/mod \
3843
--mount=type=cache,target=/root/.cache/go-build \
39-
CGO_ENABLED=1 GOOS=linux go build -tags=novllm -ldflags="-s -w" -o model-runner .
44+
CGO_ENABLED=1 GOOS=linux go build -tags=novllm -ldflags="-s -w -X main.Version=${VERSION}" -o model-runner .
4045

4146
# --- Get llama.cpp binary ---
4247
FROM docker/docker-model-backend-llamacpp:${LLAMA_SERVER_VERSION}-${LLAMA_SERVER_VARIANT} AS llama-server

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ BUILD_DMR ?= 1
3232

3333
# Build the Go application
3434
build:
35-
CGO_ENABLED=1 go build -ldflags="-s -w" -o $(APP_NAME) .
35+
CGO_ENABLED=1 go build -ldflags="-s -w -X main.Version=$(shell git describe --tags --always --dirty --match 'v*')" -o $(APP_NAME) .
3636

3737
# Run the application locally
3838
run: build

cmd/cli/commands/version.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package commands
22

33
import (
4+
"runtime"
5+
46
"github.com/docker/model-runner/cmd/cli/commands/completion"
57
"github.com/docker/model-runner/cmd/cli/desktop"
68
"github.com/spf13/cobra"
@@ -11,8 +13,24 @@ func newVersionCmd() *cobra.Command {
1113
Use: "version",
1214
Short: "Show the Docker Model Runner version",
1315
Run: func(cmd *cobra.Command, args []string) {
14-
cmd.Printf("Docker Model Runner version %s\n", desktop.Version)
15-
cmd.Printf("Docker Engine Kind: %s\n", modelRunner.EngineKind())
16+
cmd.Println("Client:")
17+
cmd.Printf(" Version: %s\n", desktop.Version)
18+
cmd.Printf(" OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH)
19+
20+
cmd.Println()
21+
cmd.Println("Server:")
22+
if desktopClient == nil {
23+
cmd.Println(" Version: (not reachable)")
24+
cmd.Println(" Engine: (not reachable)")
25+
return
26+
}
27+
sv, err := desktopClient.ServerVersion()
28+
if err != nil {
29+
cmd.Println(" Version: (not reachable)")
30+
} else {
31+
cmd.Printf(" Version: %s\n", sv.Version)
32+
}
33+
cmd.Printf(" Engine: %s\n", modelRunner.EngineKind())
1634
},
1735
ValidArgsFunction: completion.NoComplete,
1836
}

cmd/cli/desktop/desktop.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,34 @@ func (c *Client) Remove(modelArgs []string, force bool) (string, error) {
694694
return modelRemoved, nil
695695
}
696696

697+
type ServerVersionResponse struct {
698+
Version string `json:"version"`
699+
}
700+
701+
func (c *Client) ServerVersion() (ServerVersionResponse, error) {
702+
resp, err := c.doRequest(http.MethodGet, "/version", nil)
703+
if err != nil {
704+
return ServerVersionResponse{}, err
705+
}
706+
defer resp.Body.Close()
707+
708+
if resp.StatusCode != http.StatusOK {
709+
return ServerVersionResponse{}, fmt.Errorf("failed to get server version: %s", resp.Status)
710+
}
711+
712+
body, err := io.ReadAll(resp.Body)
713+
if err != nil {
714+
return ServerVersionResponse{}, fmt.Errorf("failed to read response body: %w", err)
715+
}
716+
717+
var version ServerVersionResponse
718+
if err := json.Unmarshal(body, &version); err != nil {
719+
return ServerVersionResponse{}, fmt.Errorf("failed to unmarshal response body: %w", err)
720+
}
721+
722+
return version, nil
723+
}
724+
697725
// BackendStatus to be imported from docker/model-runner when https://github.com/docker/model-runner/pull/42 is merged.
698726
type BackendStatus struct {
699727
BackendName string `json:"backend_name"`

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"crypto/tls"
6+
"encoding/json"
67
"net"
78
"net/http"
89
"os"
@@ -264,6 +265,12 @@ func main() {
264265
anthropicHandler := anthropic.NewHandler(log, schedulerHTTP, nil, modelManager)
265266
router.Handle(anthropic.APIPrefix+"/", anthropicHandler)
266267

268+
// Register /version endpoint
269+
router.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
270+
w.Header().Set("Content-Type", "application/json")
271+
_ = json.NewEncoder(w).Encode(map[string]string{"version": Version})
272+
})
273+
267274
// Register root handler LAST - it will only catch exact "/" requests that don't match other patterns
268275
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
269276
// Only respond to exact root path

version.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package main
2+
3+
var Version = "dev"

0 commit comments

Comments
 (0)