Skip to content

Commit

Permalink
initial ollama
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaeltm committed Sep 26, 2024
1 parent 30e09cc commit 1ce0ef8
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 0 deletions.
1 change: 1 addition & 0 deletions samples/ollama/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM mcr.microsoft.com/devcontainers/python:3.12-bookworm
10 changes: 10 additions & 0 deletions samples/ollama/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
"features": {
"ghcr.io/defanglabs/devcontainer-feature/defang-cli:1.0.4": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
}
}
27 changes: 27 additions & 0 deletions samples/ollama/.github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Deploy

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Deploy
uses: DefangLabs/[email protected]
#REMOVE_ME_AFTER_EDITING - Replace the following line with the list of environment variables you want to pass to the action
# or remove the lines if you don't need to pass any environment variables/secrets to the action
with:
config-env-vars: ENV1 ENV2
env:
ENV1: ${{ secrets.ENV1 }}
ENV2: ${{ secrets.ENV2 }}
54 changes: 54 additions & 0 deletions samples/ollama/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Starter Sample #REMOVE_ME_AFTER_EDITING

[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)

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

## Prerequisites

1. [!NOTE] Download [Defang CLI](https://github.com/DefangLabs/defang)
2. (Optional) If you are using [Defang BYOC](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) authenticated with your AWS account
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)

## Development

To run the application locally, you can use the following command:

```bash
# This might be `docker compose -f compose.dev.yaml up` depending on the project. #REMOVE_ME_AFTER_EDITING
docker compose up
```

## Configuration
#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.

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.

### `API_KEY` #REMOVE_ME_AFTER_EDITING
An explanation of what the env var (`API_KEY`) is, etc.

## Deployment

> [!NOTE]
> Download [Defang CLI](https://github.com/DefangLabs/defang)
### Defang Playground

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

### BYOC (AWS)

If you want to deploy to your own cloud account, you can use Defang BYOC:

1. [Authenticate your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), and that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`.
2. Run `defang up` in a terminal that has access to your AWS environment variables.

---

Title: Sample Title #REMOVE_ME_AFTER_EDITING

Short Description: A short sentence or two describing the sample. #REMOVE_ME_AFTER_EDITING

Tags: Tags, That, Are, Not, Programming, Languages #REMOVE_ME_AFTER_EDITING

Languages: Programming, Languages, Used #REMOVE_ME_AFTER_EDITING
2 changes: 2 additions & 0 deletions samples/ollama/app/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
1 change: 1 addition & 0 deletions samples/ollama/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
15 changes: 15 additions & 0 deletions samples/ollama/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM ubuntu:22.04

# install curl
RUN apt-get update && apt-get install -y curl && apt-get clean

# create ollama user and group
RUN groupadd -r ollama && useradd -r -g ollama ollama

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

COPY ./run /run

USER ollama

CMD ["/run"]
4 changes: 4 additions & 0 deletions samples/ollama/app/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

ollama pull llama3.2:1b

17 changes: 17 additions & 0 deletions samples/ollama/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Sample compose file. #REMOVE_ME_AFTER_EDITING

services:
app:
# uncomment to add your own domain
# domainname: example.com
build:
context: ./app
dockerfile: Dockerfile
ports:
- target: 3000
published: 3000
mode: ingress
healthcheck:
# wget or curl required for healthchecks on services with a published port
# this gets parsed by Defang and provided to the load balancers as well
test: [ "CMD", "curl", "-s", "http://localhost:3000/" ]

0 comments on commit 1ce0ef8

Please sign in to comment.