Skip to content

Commit 4f51bd8

Browse files
dmr: add GHA example (#23136)
Add GHA workflow example for DMR --------- Co-authored-by: Allie Sadler <[email protected]>
1 parent ff93e8d commit 4f51bd8

File tree

2 files changed

+184
-1
lines changed

2 files changed

+184
-1
lines changed

content/manuals/ai/model-runner/_index.md

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ For more details, see the [`docker model package`](/reference/cli/docker/model/p
252252

253253
## Example: Integrate Docker Model Runner into your software development lifecycle
254254

255+
### Sample project
256+
255257
You can now start building your Generative AI application powered by the Docker Model Runner.
256258

257259
If you want to try an existing GenAI application, follow these instructions.
@@ -272,6 +274,187 @@ You'll see the GenAI app's interface where you can start typing your prompts.
272274

273275
You can now interact with your own GenAI app, powered by a local model. Try a few prompts and notice how fast the responses are — all running on your machine with Docker.
274276

277+
### Use Model Runner in GitHub Actions
278+
279+
Here is an example on how to use Model Runner as part of a GitHub workflow.
280+
The example installs Model Runner, tests the installation, pulls and runs a model,
281+
interacts with the model via the API and finally deletes the model.
282+
283+
```yaml {title="dmr-run.yml", collapse=true}
284+
name: Docker Model Runner Example Workflow
285+
286+
permissions:
287+
contents: read
288+
289+
on:
290+
workflow_dispatch:
291+
inputs:
292+
test_model:
293+
description: 'Model to test with (default: ai/smollm2:360M-Q4_K_M)'
294+
required: false
295+
type: string
296+
default: 'ai/smollm2:360M-Q4_K_M'
297+
298+
jobs:
299+
dmr-test:
300+
runs-on: ubuntu-latest
301+
timeout-minutes: 30
302+
303+
steps:
304+
- name: Set up Docker
305+
uses: docker/setup-docker-action@v4
306+
307+
- name: Install docker-model-plugin
308+
run: |
309+
echo "Installing docker-model-plugin..."
310+
# Add Docker's official GPG key:
311+
sudo apt-get update
312+
sudo apt-get install ca-certificates curl
313+
sudo install -m 0755 -d /etc/apt/keyrings
314+
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
315+
sudo chmod a+r /etc/apt/keyrings/docker.asc
316+
317+
# Add the repository to Apt sources:
318+
echo \
319+
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
320+
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
321+
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
322+
sudo apt-get update
323+
sudo apt-get install -y docker-model-plugin
324+
325+
echo "Installation completed successfully"
326+
327+
- name: Test docker model version
328+
run: |
329+
echo "Testing docker model version command..."
330+
sudo docker model version
331+
332+
# Verify the command returns successfully
333+
if [ $? -eq 0 ]; then
334+
echo "✅ docker model version command works correctly"
335+
else
336+
echo "❌ docker model version command failed"
337+
exit 1
338+
fi
339+
340+
- name: Pull the provided model and run it
341+
run: |
342+
MODEL="${{ github.event.inputs.test_model || 'ai/smollm2:360M-Q4_K_M' }}"
343+
echo "Testing with model: $MODEL"
344+
345+
# Test model pull
346+
echo "Pulling model..."
347+
sudo docker model pull "$MODEL"
348+
349+
if [ $? -eq 0 ]; then
350+
echo "✅ Model pull successful"
351+
else
352+
echo "❌ Model pull failed"
353+
exit 1
354+
fi
355+
356+
# Test basic model run (with timeout to avoid hanging)
357+
echo "Testing docker model run..."
358+
timeout 60s sudo docker model run "$MODEL" "Give me a fact about whales." || {
359+
exit_code=$?
360+
if [ $exit_code -eq 124 ]; then
361+
echo "✅ Model run test completed (timed out as expected for non-interactive test)"
362+
else
363+
echo "❌ Model run failed with exit code: $exit_code"
364+
exit 1
365+
fi
366+
}
367+
- name: Test model pull and run
368+
run: |
369+
MODEL="${{ github.event.inputs.test_model || 'ai/smollm2:360M-Q4_K_M' }}"
370+
echo "Testing with model: $MODEL"
371+
372+
# Test model pull
373+
echo "Pulling model..."
374+
sudo docker model pull "$MODEL"
375+
376+
if [ $? -eq 0 ]; then
377+
echo "✅ Model pull successful"
378+
else
379+
echo "❌ Model pull failed"
380+
exit 1
381+
fi
382+
383+
# Test basic model run (with timeout to avoid hanging)
384+
echo "Testing docker model run..."
385+
timeout 60s sudo docker model run "$MODEL" "Give me a fact about whales." || {
386+
exit_code=$?
387+
if [ $exit_code -eq 124 ]; then
388+
echo "✅ Model run test completed (timed out as expected for non-interactive test)"
389+
else
390+
echo "❌ Model run failed with exit code: $exit_code"
391+
exit 1
392+
fi
393+
}
394+
395+
- name: Test API endpoint
396+
run: |
397+
MODEL="${{ github.event.inputs.test_model || 'ai/smollm2:360M-Q4_K_M' }}"
398+
echo "Testing API endpoint with model: $MODEL"
399+
400+
# Test API call with curl
401+
echo "Testing API call..."
402+
RESPONSE=$(curl -s http://localhost:12434/engines/llama.cpp/v1/chat/completions \
403+
-H "Content-Type: application/json" \
404+
-d "{
405+
\"model\": \"$MODEL\",
406+
\"messages\": [
407+
{
408+
\"role\": \"user\",
409+
\"content\": \"Say hello\"
410+
}
411+
],
412+
\"top_k\": 1,
413+
\"temperature\": 0
414+
}")
415+
416+
if [ $? -eq 0 ]; then
417+
echo "✅ API call successful"
418+
echo "Response received: $RESPONSE"
419+
420+
# Check if response contains "hello" (case-insensitive)
421+
if echo "$RESPONSE" | grep -qi "hello"; then
422+
echo "✅ Response contains 'hello' (case-insensitive)"
423+
else
424+
echo "❌ Response does not contain 'hello'"
425+
echo "Full response: $RESPONSE"
426+
exit 1
427+
fi
428+
else
429+
echo "❌ API call failed"
430+
exit 1
431+
fi
432+
433+
- name: Test model cleanup
434+
run: |
435+
MODEL="${{ github.event.inputs.test_model || 'ai/smollm2:360M-Q4_K_M' }}"
436+
437+
echo "Cleaning up test model..."
438+
sudo docker model rm "$MODEL" || echo "Model removal failed or model not found"
439+
440+
# Verify model was removed
441+
echo "Verifying model cleanup..."
442+
sudo docker model ls
443+
444+
echo "✅ Model cleanup completed"
445+
446+
- name: Report success
447+
if: success()
448+
run: |
449+
echo "🎉 Docker Model Runner daily health check completed successfully!"
450+
echo "All tests passed:"
451+
echo " ✅ docker-model-plugin installation successful"
452+
echo " ✅ docker model version command working"
453+
echo " ✅ Model pull and run operations successful"
454+
echo " ✅ API endpoint operations successful"
455+
echo " ✅ Cleanup operations successful"
456+
```
457+
275458
## FAQs
276459
277460
### What models are available?

layouts/_default/_markup/render-codeblock.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<button
6565
@click="collapse = true"
6666
x-show="!collapse"
67-
class="bg-blue mx-auto mt-4 flex items-center rounded-full px-2 text-sm text-white dark:bg-blue-500"
67+
class="chip mx-auto mt-4 flex items-center text-sm"
6868
>
6969
<span>Hide</span>
7070
<span class="icon-svg"

0 commit comments

Comments
 (0)