Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dockerised or containerised fabric #845

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docker/.env_example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
OPENAI_API_KEY=
GEMINI_API_KEY=
GROQ_API_KEY=
ANTHROPIC_API_KEY=
DEFAULT_VENDOR=Ollama
DEFAULT_MODEL=llama3.1:latest
PATTERNS_LOADER_GIT_REPO_URL=https://github.com/danielmiessler/fabric.git
PATTERNS_LOADER_GIT_REPO_PATTERNS_FOLDER=patterns
OLLAMA_API_URL="http://{{ollama_server_ip}}:11434"
YOUTUBE_API_KEY=YOUR_YOUTUBE_API_KEY
20 changes: 20 additions & 0 deletions docker/DockerFile
Copy link

@nloadholtes nloadholtes Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick note: following the instructions in the README.md did not work on an ubuntu system: the dockerfile is named DockerFile but my docker was looking for Dockerfile. (Running with -f DockerFile let it build, but most dockerfiles I've seen only have the D capitalized.)

Thank you for making this PR!

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM golang:1.22.5-alpine3.20

# Install required packages
RUN apk add --no-cache git ffmpeg util-linux sudo bash

# Create a non-root user
RUN adduser -D appuser && echo "appuser ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/appuser \
&& chmod 0440 /etc/sudoers.d/appuser

# Use a least privileged user
USER appuser

# Install YouTube transcription tool
RUN go install github.com/danielmiessler/yt@latest

# Install fabric with go install command
RUN go install github.com/danielmiessler/fabric@latest

# Set the entrypoint to run the fabric command directly within the container
ENTRYPOINT ["/bin/bash"]
58 changes: 58 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
## Building and Running the Fabric Application with Docker

This guide provides step-by-step instructions on how to build a Fabric image and run inside a docker container. The image is built using a provided Dockerfile.

### Prerequisites:

Ensure you have Docker installed on your system.
Navigate to the Fabric project directory containing the `Dockerfile` and other required files such as `.env`.

Make sure to copy the `.env_example` file to `.env` and add your API keys in the `.env` file or run `fabric --setup and add your API keys once the container is up and running. This will automatically generate the .env file for you.

### Building the Image:

Execute the following command in your terminal (Linux or Mac or wsl on Windows):

``` $ docker build -t fabric:latest .```

Replace < latest tag > with any version identifier, like v1.0 from fabric project.

The . at the end of the command indicates that you're building the image using `DockerFile` available in the current directory.

### Running the Container:

After building the image, run the container using the following command:

```
$ docker run --rm -i -t -d --name fabric -v ./fabric/:/home/appuser/.config/fabric --network traefik fabric:latest
```
Replace < --network traefik > with a desired name for your docker `network`. I have `ollama`, `open-webui`, `whisper` etc. running in the same network called `traefik` so I am using that. You can delete it if you don't want `fabric` to be in a specific network.

Docker should create a network for you automatically. The container will be detached and run in the background (with the -d flag). Container will be named as `fabric`. The volume mount is used to share the config folder with the container. This will be useful when you want to add your own `.env` file or save container files/folders such as `pattern`. The `-i` flag keeps the container open for interactive commands. The `-t` flag allocates a `pseudo-tty` to the container. `--rm` flag removes the container when it exits.

### Getting inside the Container:

Once the container is up and running, you need to get into the container and update the `patterns` by:
```
docker exec -it fabric /bin/bash

Then run:
ad6796740b6c:/go$ fabric --updatepatterns
```


#### Docker Compose:

I have provided a `docker-compose.yml` file as well. You can use it to run the container using `docker compose up`.

#### Tips:

To check if the container is running, use the command:

`$ docker ps`

To stop the container, use the command: `$ docker stop fabric`.

To remove the container and its associated resources, use the command:

`$ docker rm fabric`
110 changes: 110 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
services:

# uncomment if deploying ollama, open-webui, searxng using docker with Fabric.
# Please make sure you have traefik installed and working

# ollama:
# image: ollama/ollama:latest
# container_name: ollama
# restart: unless-stopped
# environment:
# - PUID=${PUID:-1000}
# - PGID=${PGID:-1000}
# - OLLAMA_KEEP_ALIVE=24h
# - ENABLE_IMAGE_GENERATION=True
# - COMFYUI_BASE_URL=http://stable-diffusion-webui:7860
# networks:
# - traefik
# volumes:
# - /etc/localtime:/etc/localtime:ro
# - /etc/timezone:/etc/timezone:ro
# - ./ollama:/root/.ollama
# labels:
# - "traefik.enable=true"
# - "traefik.http.routers.ollama.rule=Host(`ollama.local.example.com`)"
# - "traefik.http.routers.ollama.entrypoints=https"
# - "traefik.http.routers.ollama.tls=true"
# - "traefik.http.routers.ollama.tls.certresolver=cloudflare"
# - "traefik.http.routers.ollama.middlewares=default-headers@file"
# - "traefik.http.routers.ollama.middlewares=ollama-auth"
# - "traefik.http.services.ollama.loadbalancer.server.port=11434"
# - "traefik.http.routers.ollama.middlewares=auth"
# - "traefik.http.middlewares.auth.basicauth.users=${OLLAMA_API_CREDENTIALS}"
# deploy:
# resources:
# reservations:
# devices:
# - driver: nvidia
# count: 1
# capabilities: [gpu]

# open web ui

# open-webui:
# image: ghcr.io/open-webui/open-webui:latest
# container_name: open-webui
# restart: unless-stopped
# networks:
# - traefik
# environment:
# - PUID=${PUID:-1000}
# - PGID=${PGID:-1000}
# - 'OLLAMA_BASE_URL=http://ollama:11434'
# - ENABLE_RAG_WEB_SEARCH=True
# - RAG_WEB_SEARCH_ENGINE=searxng
# - RAG_WEB_SEARCH_RESULT_COUNT=3
# - RAG_WEB_SEARCH_CONCURRENT_REQUESTS=10
# - SEARXNG_QUERY_URL=http://searxng:8080/search?q=<query>
# volumes:
# - /etc/localtime:/etc/localtime:ro
# - /etc/timezone:/etc/timezone:ro
# - ./open-webui:/app/backend/data
# labels:
# - "traefik.enable=true"
# - "traefik.http.routers.open-webui.rule=Host(`chat.local.example.com`)"
# - "traefik.http.routers.open-webui.entrypoints=https"
# - "traefik.http.routers.open-webui.tls=true"
# - "traefik.http.routers.open-webui.tls.certresolver=cloudflare"
# - "traefik.http.routers.open-webui.middlewares=default-headers@file"
# - "traefik.http.services.open-webui.loadbalancer.server.port=8080"
# depends_on:
# - ollama
# extra_hosts:
# - host.docker.internal:host-gateway

# searxng:
# image: searxng/searxng:latest
# container_name: searxng
# networks:
# - traefik
# environment:
# - PUID=${PUID:-1000}
# - PGID=${PGID:-1000}
# volumes:
# - /etc/localtime:/etc/localtime:ro
# - /etc/timezone:/etc/timezone:ro
# - ./searxng:/etc/searxng
# depends_on:
# - ollama
# - open-webui
# restart: unless-stopped

# Fabric

fabric:
build: ./fabric
image: fabric
environment:
- PUID=${PUID:-1000}
- PGID=${PGID:-1000}
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./fabric:/home/appuser/.config/fabric
# depends_on:
# - ollama
# - open-webui
tty: true
restart: unless-stopped
networks:
- traefik