Skip to content

Commit dafd755

Browse files
authored
Merge pull request #171 from docker/Makefile-changes
Enable GPU if available in Makefile
2 parents 8a2c39f + f741826 commit dafd755

File tree

4 files changed

+42
-15
lines changed

4 files changed

+42
-15
lines changed

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
ARG GO_VERSION=1.24.2
44
ARG LLAMA_SERVER_VERSION=latest
55
ARG LLAMA_SERVER_VARIANT=cpu
6+
ARG TARGETARCH=${BUILDARCH}
67
ARG LLAMA_BINARY_PATH=/com.docker.llama-server.native.linux.${LLAMA_SERVER_VARIANT}.${TARGETARCH}
78
ARG BASE_IMAGE=ubuntu:24.04
89

9-
FROM golang:${GO_VERSION}-bookworm AS builder
10+
FROM docker.io/library/golang:${GO_VERSION}-bookworm AS builder
1011

1112
# Install git for go mod download if needed
1213
RUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/*
@@ -33,7 +34,7 @@ RUN --mount=type=cache,target=/go/pkg/mod \
3334
FROM docker/docker-model-backend-llamacpp:${LLAMA_SERVER_VERSION}-${LLAMA_SERVER_VARIANT} AS llama-server
3435

3536
# --- Final image ---
36-
FROM ${BASE_IMAGE} AS final
37+
FROM docker.io/${BASE_IMAGE} AS final
3738

3839
ARG LLAMA_SERVER_VARIANT
3940

Makefile

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,14 @@ docker-run: docker-build
7070
@echo "Service will be available at: http://localhost:$(PORT)"
7171
@echo "Example usage: curl http://localhost:$(PORT)/models"
7272
@echo ""
73-
mkdir -p $(MODELS_PATH)
74-
docker run --rm \
75-
-p $(PORT):$(PORT) \
76-
-v "$(MODELS_PATH):/models" \
77-
-e MODEL_RUNNER_PORT=$(PORT) \
78-
-e LLAMA_SERVER_PATH=/app/bin \
79-
-e MODELS_PATH=/models \
80-
-e LLAMA_ARGS="$(LLAMA_ARGS)" \
81-
-e DMR_ORIGINS="$(DMR_ORIGINS)" \
82-
-e DO_NOT_TRACK=${DO_NOT_TRACK} \
83-
-e DEBUG=${DEBUG} \
84-
$(DOCKER_IMAGE)
73+
PORT="$(PORT)" \
74+
MODELS_PATH="$(MODELS_PATH)" \
75+
DOCKER_IMAGE="$(DOCKER_IMAGE)" \
76+
LLAMA_ARGS="$(LLAMA_ARGS)" \
77+
DMR_ORIGINS="$(DMR_ORIGINS)" \
78+
DO_NOT_TRACK="${DO_NOT_TRACK}" \
79+
DEBUG="${DEBUG}" \
80+
scripts/docker-run.sh
8581

8682
# Model distribution tool operations
8783
mdl-pull: model-distribution-tool

scripts/apt-install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ main() {
99
packages+=("libvulkan1")
1010
fi
1111

12-
apt-get install -y --no-install-recommends "${packages[@]}"
12+
apt-get install -y "${packages[@]}"
1313
rm -rf /var/lib/apt/lists/*
1414
}
1515

scripts/docker-run.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
main() {
4+
set -eux -o pipefail
5+
6+
local gpu_device_flag=()
7+
for i in /dev/dri /dev/kfd /dev/accel /dev/davinci* /dev/devmm_svm /dev/hisi_hdc; do
8+
if [ -e "$i" ]; then
9+
gpu_device_flag+=("--device" "$i")
10+
fi
11+
done
12+
13+
mkdir -p "$MODELS_PATH"
14+
chmod a+rx "$MODELS_PATH"
15+
docker run --rm \
16+
-p "$PORT:$PORT" \
17+
-v "$MODELS_PATH:/models" \
18+
-e MODEL_RUNNER_PORT="$PORT" \
19+
-e LLAMA_SERVER_PATH=/app/bin \
20+
-e MODELS_PATH=/models \
21+
-e LLAMA_ARGS="$LLAMA_ARGS" \
22+
-e DMR_ORIGINS="$DMR_ORIGINS" \
23+
-e DO_NOT_TRACK="$DO_NOT_TRACK" \
24+
-e DEBUG="$DEBUG" \
25+
"${gpu_device_flag[@]}" \
26+
"$DOCKER_IMAGE"
27+
}
28+
29+
main "$@"
30+

0 commit comments

Comments
 (0)