From 86e64f0cf8a7f9dce055aea343d88d4153d9dc85 Mon Sep 17 00:00:00 2001 From: Fahad Usman Date: Tue, 20 Aug 2024 11:21:06 +0100 Subject: [PATCH 1/3] dockerised fabric --- docker/.env_example | 10 ++++ docker/DockerFile | 20 +++++++ docker/README.md | 47 ++++++++++++++++ docker/docker-compose.yml | 110 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 187 insertions(+) create mode 100644 docker/.env_example create mode 100644 docker/DockerFile create mode 100644 docker/README.md create mode 100644 docker/docker-compose.yml diff --git a/docker/.env_example b/docker/.env_example new file mode 100644 index 000000000..5d3e012cd --- /dev/null +++ b/docker/.env_example @@ -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 \ No newline at end of file diff --git a/docker/DockerFile b/docker/DockerFile new file mode 100644 index 000000000..c67265067 --- /dev/null +++ b/docker/DockerFile @@ -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"] \ No newline at end of file diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 000000000..fbe9d76de --- /dev/null +++ b/docker/README.md @@ -0,0 +1,47 @@ +## 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 fabic: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. + + #### 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.` diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 000000000..3c68dc3d1 --- /dev/null +++ b/docker/docker-compose.yml @@ -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= + # 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 \ No newline at end of file From 6fc7bf4f7b544e26e8e032c35a22d3a01b477189 Mon Sep 17 00:00:00 2001 From: Fahad Usman Date: Tue, 20 Aug 2024 22:46:26 +0100 Subject: [PATCH 2/3] Update README.md Added a section on how to get inside the running container and update the patterns --- docker/README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/docker/README.md b/docker/README.md index fbe9d76de..68baa9f85 100644 --- a/docker/README.md +++ b/docker/README.md @@ -30,6 +30,17 @@ Replace < --network traefik > with a desired name for your docker `network`. I h 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`. @@ -38,10 +49,10 @@ Replace < --network traefik > with a desired name for your docker `network`. I h To check if the container is running, use the command: -`$ docker ps.` +`$ 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.` +`$ docker rm fabric` From 9ffa6ccb78b2a44defb92aec7297bddf5c6c3113 Mon Sep 17 00:00:00 2001 From: Fahad Usman Date: Wed, 28 Aug 2024 12:20:05 +0100 Subject: [PATCH 3/3] Update README.md fixed type when running the container --- docker/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/README.md b/docker/README.md index 68baa9f85..72850216b 100644 --- a/docker/README.md +++ b/docker/README.md @@ -24,7 +24,7 @@ The . at the end of the command indicates that you're building the image using ` 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 fabic:latest +$ 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.