Skip to content

Commit

Permalink
feat: add docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
catpaladin committed Jul 1, 2024
1 parent d8a17c7 commit ad73310
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
FROM golang:1.22 as build

ENV USER=appuser \
UID=1000 \
GO111MODULE=on \
CGO_ENABLED=1

RUN adduser \
--disabled-password \
--gecos "" \
--home "/tmp" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"

WORKDIR /src

COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN go build \
-o /bin/jenn-ai \
-ldflags "-w -s -linkmode external -extldflags "-static"" \
. && \
chown appuser:appuser /bin/jenn-ai

FROM scratch

# Needed for ssl requirements
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Used for the unprivileged user
COPY --from=build /etc/passwd /etc/passwd
COPY --from=build /etc/group /etc/group

WORKDIR /app
COPY --from=build /bin/jenn-ai /bin/jenn-ai
COPY --from=build /src/templates /app/templates
USER appuser:appuser
ENTRYPOINT ["/bin/jenn-ai", "server"]
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This Makefile is used to easy the commands used

deps:
@go install github.com/air-verse/air@latest

local_dev:
@air

local:
@go install
@jenn-ai server

# default value is set to docker-compose.yaml
# if you have a gpu, you will want to run:
#
# make <command> COMPOSE_FILE=docker-compose-gpu.yaml
COMPOSE_FILE ?= docker-compose.yaml

build_dev: $(COMPOSE_FILE)
@docker-compose -f $< build jenn_ai_dev

up_dev: $(COMPOSE_FILE)
@docker-compose -f $< up -d jenn_ai_dev

build: $(COMPOSE_FILE)
@docker-compose -f $< build jenn_ai

up: $(COMPOSE_FILE)
@docker-compose -f $< up -d jenn_ai

down: $(COMPOSE_FILE)
@docker-compose -f $< down

# exec is used to enter the ollama container to install models
exec:
@docker exec -it ollama bash
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,45 @@ Support for models is currently limited to:
git clone <repo>
go install
```

## Local Development

If you have go installed, ensure that you have air
```bash
make deps
```

Run in development to perform live edits
```bash
make local_dev
```

Run locally
```bash
make local
```

### Docker

Run locally (in development)
```bash
make build_dev
make up_dev
```

Run locally
```bash
make build
make up
```

To bring it down, run
```bash
make down
```

If you have a GPU, then you need to modify the input
```bash
make up COMPOSE_FILE=docker-compose-gpu.yaml
```
Make sure to include the variable when running `down`
27 changes: 27 additions & 0 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM golang:1.22

ENV USER=appuser \
UID=1000 \
GO111MODULE=on \
CGO_ENABLED=1

RUN adduser \
--disabled-password \
--gecos "" \
--home "/tmp" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"

WORKDIR /app

RUN go install github.com/air-verse/air@latest

COPY go.mod go.sum ./
RUN go mod download && \
mkdir -p /.cache/go-build && \
chown -R appuser:appuser /.cache

USER appuser:appuser
CMD ["air", "-c", ".air.toml"]
65 changes: 65 additions & 0 deletions docker-compose-gpu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
version: "3.7"
services:
jenn_ai_dev:
container_name: jenn_ai_dev
build:
context: .
dockerfile: dev.Dockerfile
user: 1000:1000
environment:
- OLLAMA_HOST=ollama:11434
depends_on:
- ollama
ports:
- 3000:31000
networks:
- ollama
volumes:
- ./:/app
# # mount aws credentials for bedrock
# - ~/.aws:/tmp/.aws

jenn_ai:
container_name: jenn_ai
build:
context: .
dockerfile: Dockerfile
user: 1000:1000
environment:
- OLLAMA_HOST=ollama:11434
depends_on:
- ollama
ports:
- 31000:31000
networks:
- ollama
# volumes:
# # mount aws credentials for bedrock
# - ~/.aws:/tmp/.aws

ollama:
container_name: ollama
image: ollama/ollama
healthcheck:
test: ollama --version || exit 1
command: serve
networks:
- ollama
volumes:
- ollama:/root/.ollama
# only used on devices with gpu, otherwise you can comment or delete
deploy:
resources:
reservations:
devices:
- driver: nvidia
device_ids: ['all']
capabilities: [gpu]

volumes:
ollama:

networks:
ollama:
name: ollama_default
external: false
57 changes: 57 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
version: "3.7"
services:
jenn_ai_dev:
container_name: jenn_ai_dev
build:
context: .
dockerfile: dev.Dockerfile
user: 1000:1000
environment:
- OLLAMA_HOST=ollama:11434
depends_on:
- ollama
ports:
- 3000:31000
networks:
- ollama
volumes:
- ./:/app
# # mount aws credentials for bedrock
# - ~/.aws:/tmp/.aws

jenn_ai:
container_name: jenn_ai
build:
context: .
dockerfile: Dockerfile
user: 1000:1000
environment:
- OLLAMA_HOST=ollama:11434
depends_on:
- ollama
ports:
- 31000:31000
networks:
- ollama
# volumes:
# # mount aws credentials for bedrock
# - ~/.aws:/tmp/.aws

ollama:
container_name: ollama
image: ollama/ollama
healthcheck:
test: ollama --version || exit 1
command: serve
networks:
- ollama
volumes:
- ollama:/root/.ollama

volumes:
ollama:

networks:
ollama:
name: ollama_default
external: false

0 comments on commit ad73310

Please sign in to comment.