Skip to content
Merged
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
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
__pycache__
*.pyc
*.pyo
*.pyd
.pytest_cache
.venv
env/
infinity_env/
coexistaienv/
*.log
artifacts/
output/
downloads/
8 changes: 8 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copy this file to .env and edit values as needed before running docker-compose
PORT_NUM_APP=8000
HOST_APP=0.0.0.0
PORT_NUM_SEARXNG=8085
HOST_SEARXNG=0.0.0.0
# Example API key environment variable (optional). Set in your .env, NOT in model_config.py
GOOGLE_API_KEY=REPLACE_YOUR_API_KEY
ADMIN_TOKEN=123456
70 changes: 70 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
FROM python:3.13-slim

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

# Build-time args that will be copied into the image as environment variables.
# Users can pass these via `docker build --build-arg KEY=VALUE` to bake defaults.
ARG LLM_MODEL_NAME=gemini-2.0-flash
ARG LLM_TYPE=google
ARG LLM_TEMPERATURE=0.1
ARG PORT_NUM_APP=8000
ARG PORT_NUM_SEARXNG=8085
ARG HOST_APP=0.0.0.0
ARG HOST_SEARXNG=0.0.0.0
ARG EMBED_MODE=google
ARG EMBEDDING_MODEL_NAME=models/embedding-001

# Export non-secret build args as environment variables so model_config.py can read them at runtime
ENV LLM_MODEL_NAME=${LLM_MODEL_NAME}
ENV LLM_TYPE=${LLM_TYPE}
ENV LLM_TEMPERATURE=${LLM_TEMPERATURE}
ENV PORT_NUM_APP=${PORT_NUM_APP}
ENV PORT_NUM_SEARXNG=${PORT_NUM_SEARXNG}
ENV HOST_APP=${HOST_APP}
ENV HOST_SEARXNG=${HOST_SEARXNG}
ENV EMBED_MODE=${EMBED_MODE}
ENV EMBEDDING_MODEL_NAME=${EMBEDDING_MODEL_NAME}

# Install small set of system deps commonly needed by ML/audio packages
RUN apt-get update && \
apt-get install -y --no-install-recommends \
git \
wget \
ffmpeg \
build-essential \
libsndfile1 \
&& rm -rf /var/lib/apt/lists/*


# Use /app as the workdir so the Dockerfile can be built from the CoexistAI folder
WORKDIR /app

# Copy only requirements first to leverage Docker cache (build context is the CoexistAI folder)
COPY ./requirements.txt ./requirements.txt

RUN python -m pip install --upgrade pip setuptools wheel

# Copy application code (copy the current folder contents into /app)
COPY ./ ./

# Reproduce quick_setup.sh virtualenv installs inside the image (mirrors the script)
# Create a separate infinity_env and install packages there to avoid conflicts as in the script
RUN python3.13 -m venv /opt/infinity_env && \
/opt/infinity_env/bin/pip install --no-cache-dir 'infinity_emb[all]' && \
/opt/infinity_env/bin/pip install --no-cache-dir --upgrade "transformers<4.49" && \
/opt/infinity_env/bin/pip install --no-cache-dir --upgrade "typer==0.19.1" "click>=8.1.3" || true

# Create a second venv similar to coexistaienv and install markitdown[all]
RUN python3.13 -m venv /opt/coexistaienv && \
/opt/coexistaienv/bin/pip install --no-cache-dir 'markitdown[all]' || true

# Now install the project requirements into the coexistaienv (matches quick_setup.sh order)
RUN /opt/coexistaienv/bin/pip install --no-cache-dir -r requirements.txt || true

# Entrypoint will be executed via shell; no need to force executable bit when host may mount files

EXPOSE 8000

# Invoke the entrypoint from the copied project path. The entrypoint lives at CoexistAI/entrypoint.sh
CMD ["sh", "/app/entrypoint.sh"]
125 changes: 125 additions & 0 deletions README.docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# CoexistAI — Docker Quickstart

### Short, step-by-step instructions for two ways to start CoexistAI. Pick either Method A (helper script) or Method B (direct Docker Compose).

## Prerequisites
- Docker Engine installed.

## Before you start (one-time)
1. Open a terminal and change into the repository folder:

```bash
cd /path/to/CoexistAI
```

2. Edit the .env file for keys and admin token (which will be used while editing model params):


## Method A — Helper script (recommended for beginners)
This script automates the compose start and waits until the app reports ready.

1. Run the helper (from repo root):

```bash
./quick_setup_docker.sh
```
or

```bash # default timeout 300s
./quick_setup_docker.sh 600 # pass timeout in seconds (example: 600s = 10min)
```

For subsequent starts, run the script again (it detects the existing image and skips building/installing).

2. What the script does (so you know what to expect):
- 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.
- Polls `http://localhost:8000/status` every few seconds and prints a spinner.
- Exits with code 0 when the app reports `{"status":"ready"}`.
- Exits non-zero if the app reports `error` or the timeout is reached.

3. After the script finishes successfully, open:

- http://localhost:8000/admin

![Admin ui](./artifacts/admin_ui.png)

- If using local models ignore api_keys fields

- By default ADMIN_TOKEN=123456, you can change it via .env

This opens the Admin UI, where you can edit model configurations, API keys, and reload settings without rebuilding the container.

When to use Method A: you're new to Docker or want a simple way to wait until the app is ready.


## Method B — Direct Docker Compose (fast, manual)
1. Start the stack:

- **First time** (builds the image):
```bash
docker compose up -d --build
```

- **Subsequent times** (uses existing image):
```bash
docker compose up -d
```

To stop: `docker compose down`

To restart: `docker compose restart`

2. Wait for ready signal in terminal where you ran docker compose, then open the admin UI:

- http://localhost:8000/admin

3. Verify status from the host:

```bash
curl http://localhost:8000/status
# expected JSON: {"status":"starting"} or {"status":"ready"}
```

4. Edit configuration:
- Use the Admin UI `/admin` and click "Save & Reload" to apply changes without rebuilding.
- Or from the host (curl):

```bash
curl -X POST -H "X-Admin-Token: $ADMIN_TOKEN" http://localhost:8000/admin/reload-config
```

When to use Method A: you prefer to run compose directly and watch logs yourself.

Secrets (recommended pattern)
- Do not store API keys in the repo. Use `.env` or file-backed secrets.
- 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`.

Quick troubleshooting
- App unreachable? Check app logs:

```bash
docker compose logs app --tail=200
```

- App timed out in `quick_setup_docker.sh` or reports `error`? Inspect logs and increase timeout:

```bash
docker compose logs app --tail=400
./quick_setup_docker.sh 600
```

- Long model downloads or HF errors: allow more time on first start or mount `artifacts/` (HF cache) into the container to avoid repeated downloads.

Helpful commands

```bash
# Check status
curl http://localhost:8000/status

# Ask app to reload config (from host)
curl -X POST -H "X-Admin-Token: $ADMIN_TOKEN" http://localhost:8000/admin/reload-config

# Follow logs interactively
docker compose logs -f app --tail=200
```

Loading