Skip to content

Commit 82b4395

Browse files
committed
working ollama sample
1 parent 7028ff8 commit 82b4395

29 files changed

+7352
-45
lines changed

samples/ollama/.devcontainer/devcontainer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
},
66
"features": {
77
"ghcr.io/defanglabs/devcontainer-feature/defang-cli:1.0.4": {},
8-
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
8+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
9+
"ghcr.io/devcontainers/features/node:1": {}
910
}
1011
}

samples/ollama/.github/workflows/deploy.yaml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,4 @@ jobs:
1717
uses: actions/checkout@v4
1818

1919
- name: Deploy
20-
uses: DefangLabs/[email protected]
21-
#REMOVE_ME_AFTER_EDITING - Replace the following line with the list of environment variables you want to pass to the action
22-
# or remove the lines if you don't need to pass any environment variables/secrets to the action
23-
with:
24-
config-env-vars: ENV1 ENV2
25-
env:
26-
ENV1: ${{ secrets.ENV1 }}
27-
ENV2: ${{ secrets.ENV2 }}
20+
uses: DefangLabs/[email protected]

samples/ollama/README.md

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Starter Sample #REMOVE_ME_AFTER_EDITING
1+
# Ollama
22

3-
[1-click deploy](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-<YOUR_SAMPLE_DIR#REMOVE_ME_AFTER_EDITING>-template%26template_owner%3DDefangSamples)
3+
[1-click deploy](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-ollama-template%26template_owner%3DDefangSamples)
44

5-
This is a sample that shows the rough structure of an actual Defang sample. This top paragraph should give a bit of context about the project and what it does. The rest of the README should be a guide on how to use the sample. #REMOVE_ME_AFTER_EDITING
5+
This sample demonstrates how to deploy [Ollama](https://ollama.com/) with Defang, along with a Next.js frontend using the [AI SDK](https://www.npmjs.com/package/ai) for smooth streaming conversations. By default it runs a very small model (`llama3.2:1b`) which can perform well with just a CPU, but we've included lines that you can uncomment in the compose file to enable GPU support and run a larger model like `gemma:7b`. If you want to deploy to a GPU powered instance, you will need to use your own AWS account with [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc).
66

77
## Prerequisites
88

@@ -15,18 +15,9 @@ This is a sample that shows the rough structure of an actual Defang sample. This
1515
To run the application locally, you can use the following command:
1616

1717
```bash
18-
# This might be `docker compose -f compose.dev.yaml up` depending on the project. #REMOVE_ME_AFTER_EDITING
19-
docker compose up
18+
docker compose -f compose.dev.yaml up
2019
```
2120

22-
## Configuration
23-
#REMOVE_ME_AFTER_EDITING - this section should be removed if there are no configuration values needed. The intro text can probably stay, but the list of configuration values should be updated/removed if there are none.
24-
25-
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration). Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
26-
27-
### `API_KEY` #REMOVE_ME_AFTER_EDITING
28-
An explanation of what the env var (`API_KEY`) is, etc.
29-
3021
## Deployment
3122

3223
> [!NOTE]
@@ -36,6 +27,8 @@ An explanation of what the env var (`API_KEY`) is, etc.
3627

3728
Deploy your application to the defang playground by opening up your terminal and typing `defang up`.
3829

30+
**Keep in mind that the playground does not support GPU instances.**
31+
3932
### BYOC (AWS)
4033

4134
If you want to deploy to your own cloud account, you can use Defang BYOC:
@@ -45,10 +38,10 @@ If you want to deploy to your own cloud account, you can use Defang BYOC:
4538

4639
---
4740

48-
Title: Sample Title #REMOVE_ME_AFTER_EDITING
41+
Title: Ollama
4942

50-
Short Description: A short sentence or two describing the sample. #REMOVE_ME_AFTER_EDITING
43+
Short Description: Ollama is a tool that lets you easily run large language models.
5144

52-
Tags: Tags, That, Are, Not, Programming, Languages #REMOVE_ME_AFTER_EDITING
45+
Tags: AI, LLM, ML, Llama, Mistral, Next.js, AI SDK,
5346

54-
Languages: Programming, Languages, Used #REMOVE_ME_AFTER_EDITING
47+
Languages: Typescript

samples/ollama/app/.dockerignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

samples/ollama/app/run.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

samples/ollama/compose.dev.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
app:
3+
extends:
4+
file: compose.yaml
5+
service: app
6+
7+
ui:
8+
extends:
9+
file: compose.yaml
10+
service: ui
11+
volumes:
12+
- type: bind
13+
source: ./ui
14+
target: /app
15+
command: ["npm", "run", "dev"]

samples/ollama/compose.yaml

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,52 @@
11
services:
2-
app:
2+
ollama:
33
# uncomment to add your own domain
44
# domainname: example.com
55
build:
6-
context: ./app
6+
context: ./ollama
77
dockerfile: Dockerfile
8+
shm_size: "16gb"
89
ports:
910
- target: 8000
10-
published: 8000
11-
mode: ingress
11+
mode: host
1212
deploy:
1313
resources:
14-
limits:
15-
cpus: '2'
16-
memory: 4G
14+
reservations:
15+
cpus: '2.0'
16+
memory: 8192M
17+
# Uncomment the next two lines to enable GPU support, for example to use gemma:7b
18+
# NOTE: this is only supported in [BYOC](https://docs.defang.io/docs/concepts/defang-byoc)
19+
# devices:
20+
# - capabilities: ["gpu"]
21+
# By Default we load llama3.2:1b because it can run efficiently on a CPU, but you can select
22+
# a different model by setting the LOAD_MODEL environment variable. Check the [list](https://ollama.com/library)
23+
# for more models. For example, to load gemma:7b, set the LOAD_MODEL environment variable to gemma:7b below.
24+
environment:
25+
- LOAD_MODEL=llama3.2:1b
26+
# - LOAD_MODEL=gemma:7b
1727
healthcheck:
1828
# wget or curl required for healthchecks on services with a published port
1929
# this gets parsed by Defang and provided to the load balancers as well
2030
test: [ "CMD", "curl", "-s", "http://localhost:8000/" ]
31+
32+
ui:
33+
build:
34+
context: ui
35+
dockerfile: Dockerfile
36+
ports:
37+
- mode: ingress
38+
target: 3000
39+
published: 3000
40+
deploy:
41+
resources:
42+
reservations:
43+
memory: 256M
44+
healthcheck:
45+
# wget or curl required for healthchecks on services with a published port
46+
# this gets parsed by Defang and provided to the load balancers as well
47+
test: [ "CMD", "curl", "-s", "http://localhost:3000/" ]
48+
environment:
49+
- OLLAMA_ENDPOINT=http://ollama:8000
50+
# Make sure the LOAD_MODEL is the same as the app service
51+
- LOAD_MODEL=llama3.2:1b
52+
# - LOAD_MODEL=gemma:7b

samples/ollama/ollama/.dockerignore

Whitespace-only changes.

samples/ollama/ollama/.gitignore

Whitespace-only changes.

samples/ollama/app/Dockerfile renamed to samples/ollama/ollama/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ARG OLLAMA_MODELS=/usr/share/ollama/.ollama/models
1010
# Use the build-time arguments to set environment variables
1111
ENV OLLAMA_HOST=${OLLAMA_HOST}
1212
ENV OLLAMA_MODELS=${OLLAMA_MODELS}
13+
ENV LOAD_MODEL=llama3.2:1b
1314

1415
RUN curl -fsSL https://ollama.com/install.sh | sh
1516

0 commit comments

Comments
 (0)