Skip to content

Commit f6fb2b4

Browse files
authored
Merge pull request #12 from SPThole/docker-setup
Implemented Docker setup Implemented UI to edit config Python version issue resolved for WSL users 3.13 -> 3.12
2 parents f702b6b + 33c52e0 commit f6fb2b4

17 files changed

+1528
-194
lines changed

.dockerignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
__pycache__
2+
*.pyc
3+
*.pyo
4+
*.pyd
5+
.pytest_cache
6+
.venv
7+
env/
8+
infinity_env/
9+
coexistaienv/
10+
*.log
11+
artifacts/
12+
output/
13+
downloads/

.env

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copy this file to .env and edit values as needed before running docker-compose
2+
PORT_NUM_APP=8000
3+
HOST_APP=0.0.0.0
4+
PORT_NUM_SEARXNG=8085
5+
HOST_SEARXNG=0.0.0.0
6+
# Example API key environment variable (optional). Set in your .env, NOT in model_config.py
7+
GOOGLE_API_KEY=REPLACE_YOUR_API_KEY
8+
ADMIN_TOKEN=123456

Dockerfile

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
FROM python:3.13-slim
2+
3+
ENV PYTHONDONTWRITEBYTECODE=1
4+
ENV PYTHONUNBUFFERED=1
5+
6+
# Build-time args that will be copied into the image as environment variables.
7+
# Users can pass these via `docker build --build-arg KEY=VALUE` to bake defaults.
8+
ARG LLM_MODEL_NAME=gemini-2.0-flash
9+
ARG LLM_TYPE=google
10+
ARG LLM_TEMPERATURE=0.1
11+
ARG PORT_NUM_APP=8000
12+
ARG PORT_NUM_SEARXNG=8085
13+
ARG HOST_APP=0.0.0.0
14+
ARG HOST_SEARXNG=0.0.0.0
15+
ARG EMBED_MODE=google
16+
ARG EMBEDDING_MODEL_NAME=models/embedding-001
17+
18+
# Export non-secret build args as environment variables so model_config.py can read them at runtime
19+
ENV LLM_MODEL_NAME=${LLM_MODEL_NAME}
20+
ENV LLM_TYPE=${LLM_TYPE}
21+
ENV LLM_TEMPERATURE=${LLM_TEMPERATURE}
22+
ENV PORT_NUM_APP=${PORT_NUM_APP}
23+
ENV PORT_NUM_SEARXNG=${PORT_NUM_SEARXNG}
24+
ENV HOST_APP=${HOST_APP}
25+
ENV HOST_SEARXNG=${HOST_SEARXNG}
26+
ENV EMBED_MODE=${EMBED_MODE}
27+
ENV EMBEDDING_MODEL_NAME=${EMBEDDING_MODEL_NAME}
28+
29+
# Install small set of system deps commonly needed by ML/audio packages
30+
RUN apt-get update && \
31+
apt-get install -y --no-install-recommends \
32+
git \
33+
wget \
34+
ffmpeg \
35+
build-essential \
36+
libsndfile1 \
37+
&& rm -rf /var/lib/apt/lists/*
38+
39+
40+
# Use /app as the workdir so the Dockerfile can be built from the CoexistAI folder
41+
WORKDIR /app
42+
43+
# Copy only requirements first to leverage Docker cache (build context is the CoexistAI folder)
44+
COPY ./requirements.txt ./requirements.txt
45+
46+
RUN python -m pip install --upgrade pip setuptools wheel
47+
48+
# Copy application code (copy the current folder contents into /app)
49+
COPY ./ ./
50+
51+
# Reproduce quick_setup.sh virtualenv installs inside the image (mirrors the script)
52+
# Create a separate infinity_env and install packages there to avoid conflicts as in the script
53+
RUN python3.13 -m venv /opt/infinity_env && \
54+
/opt/infinity_env/bin/pip install --no-cache-dir 'infinity_emb[all]' && \
55+
/opt/infinity_env/bin/pip install --no-cache-dir --upgrade "transformers<4.49" && \
56+
/opt/infinity_env/bin/pip install --no-cache-dir --upgrade "typer==0.19.1" "click>=8.1.3" || true
57+
58+
# Create a second venv similar to coexistaienv and install markitdown[all]
59+
RUN python3.13 -m venv /opt/coexistaienv && \
60+
/opt/coexistaienv/bin/pip install --no-cache-dir 'markitdown[all]' || true
61+
62+
# Now install the project requirements into the coexistaienv (matches quick_setup.sh order)
63+
RUN /opt/coexistaienv/bin/pip install --no-cache-dir -r requirements.txt || true
64+
65+
# Entrypoint will be executed via shell; no need to force executable bit when host may mount files
66+
67+
EXPOSE 8000
68+
69+
# Invoke the entrypoint from the copied project path. The entrypoint lives at CoexistAI/entrypoint.sh
70+
CMD ["sh", "/app/entrypoint.sh"]

README.docker.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# CoexistAI — Docker Quickstart
2+
3+
### Short, step-by-step instructions for two ways to start CoexistAI. Pick either Method A (helper script) or Method B (direct Docker Compose).
4+
5+
## Prerequisites
6+
- Docker Engine installed.
7+
8+
## Before you start (one-time)
9+
1. Open a terminal and change into the repository folder:
10+
11+
```bash
12+
cd /path/to/CoexistAI
13+
```
14+
15+
2. Edit the .env file for keys and admin token (which will be used while editing model params):
16+
17+
18+
## Method A — Helper script (recommended for beginners)
19+
This script automates the compose start and waits until the app reports ready.
20+
21+
1. Run the helper (from repo root):
22+
23+
```bash
24+
./quick_setup_docker.sh
25+
```
26+
or
27+
28+
```bash # default timeout 300s
29+
./quick_setup_docker.sh 600 # pass timeout in seconds (example: 600s = 10min)
30+
```
31+
32+
For subsequent starts, run the script again (it detects the existing image and skips building/installing).
33+
34+
2. What the script does (so you know what to expect):
35+
- Checks if the Docker image 'coexistai-app' already exists; if yes, runs `docker compose up -d` (no build); if not, runs `docker compose up -d --build` to start containers detached.
36+
- Polls `http://localhost:8000/status` every few seconds and prints a spinner.
37+
- Exits with code 0 when the app reports `{"status":"ready"}`.
38+
- Exits non-zero if the app reports `error` or the timeout is reached.
39+
40+
3. After the script finishes successfully, open:
41+
42+
- http://localhost:8000/admin
43+
44+
![Admin ui](./artifacts/admin_ui.png)
45+
46+
- If using local models ignore api_keys fields
47+
48+
- By default ADMIN_TOKEN=123456, you can change it via .env
49+
50+
This opens the Admin UI, where you can edit model configurations, API keys, and reload settings without rebuilding the container.
51+
52+
When to use Method A: you're new to Docker or want a simple way to wait until the app is ready.
53+
54+
55+
## Method B — Direct Docker Compose (fast, manual)
56+
1. Start the stack:
57+
58+
- **First time** (builds the image):
59+
```bash
60+
docker compose up -d --build
61+
```
62+
63+
- **Subsequent times** (uses existing image):
64+
```bash
65+
docker compose up -d
66+
```
67+
68+
To stop: `docker compose down`
69+
70+
To restart: `docker compose restart`
71+
72+
2. Wait for ready signal in terminal where you ran docker compose, then open the admin UI:
73+
74+
- http://localhost:8000/admin
75+
76+
3. Verify status from the host:
77+
78+
```bash
79+
curl http://localhost:8000/status
80+
# expected JSON: {"status":"starting"} or {"status":"ready"}
81+
```
82+
83+
4. Edit configuration:
84+
- Use the Admin UI `/admin` and click "Save & Reload" to apply changes without rebuilding.
85+
- Or from the host (curl):
86+
87+
```bash
88+
curl -X POST -H "X-Admin-Token: $ADMIN_TOKEN" http://localhost:8000/admin/reload-config
89+
```
90+
91+
When to use Method A: you prefer to run compose directly and watch logs yourself.
92+
93+
Secrets (recommended pattern)
94+
- Do not store API keys in the repo. Use `.env` or file-backed secrets.
95+
- Recommended: create `CoexistAI/config/keys/` on the host, place key files there, and mount that folder into the container. Reference them in `config/model_config.json` with `llm_api_key_file` / `embed_api_key_file`.
96+
97+
Quick troubleshooting
98+
- App unreachable? Check app logs:
99+
100+
```bash
101+
docker compose logs app --tail=200
102+
```
103+
104+
- App timed out in `quick_setup_docker.sh` or reports `error`? Inspect logs and increase timeout:
105+
106+
```bash
107+
docker compose logs app --tail=400
108+
./quick_setup_docker.sh 600
109+
```
110+
111+
- Long model downloads or HF errors: allow more time on first start or mount `artifacts/` (HF cache) into the container to avoid repeated downloads.
112+
113+
Helpful commands
114+
115+
```bash
116+
# Check status
117+
curl http://localhost:8000/status
118+
119+
# Ask app to reload config (from host)
120+
curl -X POST -H "X-Admin-Token: $ADMIN_TOKEN" http://localhost:8000/admin/reload-config
121+
122+
# Follow logs interactively
123+
docker compose logs -f app --tail=200
124+
```
125+

0 commit comments

Comments
 (0)