-
Notifications
You must be signed in to change notification settings - Fork 9
Feat/docker #28
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
Merged
nicofretti
merged 4 commits into
nicofretti:develop
from
giuseppeambrosio97:feat/docker
Nov 10, 2025
Merged
Feat/docker #28
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e9be07f
fix: update installation commands in Makefile for virtual environment…
giuseppeambrosio97 f79fed4
feat: add health check endpoint to FastAPI application
giuseppeambrosio97 a8d5386
feat: add Docker support with Dockerfile, docker-compose, and documen…
giuseppeambrosio97 73a73e2
Merge branch 'develop' into feat/docker
giuseppeambrosio97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # Python | ||
| __pycache__/ | ||
| *.py[cod] | ||
| *$py.class | ||
| *.so | ||
| .Python | ||
| *.egg-info/ | ||
| dist/ | ||
| build/ | ||
| .venv/ | ||
| venv/ | ||
| ENV/ | ||
| env/ | ||
|
|
||
| # Node | ||
| node_modules/ | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| frontend/build/ | ||
| frontend/node_modules/ | ||
| website/node_modules/ | ||
|
|
||
| # IDE | ||
| .vscode/ | ||
| .idea/ | ||
| *.swp | ||
| *.swo | ||
| *~ | ||
|
|
||
| # Testing | ||
| .pytest_cache/ | ||
| .coverage | ||
| htmlcov/ | ||
| .tox/ | ||
|
|
||
| # Documentation | ||
| docs/_build/ | ||
| *.md | ||
| !README.md | ||
|
|
||
| # Git | ||
| .git/ | ||
| .gitignore | ||
|
|
||
| # Docker | ||
| Dockerfile* | ||
| docker-compose*.yml | ||
| .dockerignore | ||
|
|
||
| # Data | ||
| data/*.db | ||
| data/*.db-journal | ||
|
|
||
| # Logs | ||
| *.log | ||
|
|
||
| # Environment | ||
| .env | ||
| .env.local | ||
| .env.*.local | ||
|
|
||
| # OS | ||
| .DS_Store | ||
| Thumbs.db | ||
|
|
||
| # Misc | ||
| *.bak | ||
| *.tmp | ||
| .cache/ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # Docker Setup | ||
|
|
||
| This document describes how to run DataGenFlow using Docker. | ||
|
|
||
| ## Quick Start | ||
|
|
||
| 1. **Build and start the application:** | ||
|
|
||
| ```bash | ||
| docker-compose up -d | ||
| ``` | ||
|
|
||
| 2. **Access the application:** | ||
| - Frontend: <http://localhost:8000> | ||
| - API: <http://localhost:8000/api> | ||
|
|
||
| 3. **Stop the application:** | ||
|
|
||
| ```bash | ||
| docker-compose down | ||
| ``` | ||
|
|
||
| ## Custom Blocks | ||
|
|
||
| Custom blocks can be added to `lib/blocks/custom/` on your host system. They will be automatically available after restarting the backend container: | ||
|
|
||
| ```bash | ||
| docker-compose restart backend | ||
| ``` | ||
|
|
||
| The `lib/blocks/custom/` directory is mounted as a volume, so you can add new block files directly from your host system without rebuilding the image. | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| You can configure the application using environment variables. Create a `.env` file in the project root: | ||
|
|
||
| ```env | ||
| LLM_ENDPOINT=http://localhost:11434/api/generate | ||
| LLM_API_KEY= | ||
| LLM_MODEL=llama3 | ||
| DEBUG=false | ||
| ``` | ||
|
|
||
| These variables are automatically passed to the container via `docker-compose.yml`. | ||
|
|
||
| ## Data Persistence | ||
|
|
||
| The `data/` directory is mounted as a volume, so your database and other data will persist between container restarts. | ||
|
|
||
| ## Building Images | ||
|
|
||
| To rebuild the images: | ||
|
|
||
| ```bash | ||
| docker-compose build | ||
| ``` | ||
|
|
||
| Or rebuild without cache: | ||
|
|
||
| ```bash | ||
| docker-compose build --no-cache | ||
| ``` | ||
|
|
||
| ## Development | ||
|
|
||
| For development, you may want to mount additional directories or use volume mounts for live code reloading. Modify `docker-compose.yml` as needed. | ||
|
|
||
| ## Architecture | ||
|
|
||
| - **Backend**: Python 3.11 with uv, serves both API and frontend | ||
| - **Frontend**: Built with yarn/vite, served as static files by the backend | ||
| - **Port**: 8000 (both API and frontend) | ||
|
|
||
| The backend Dockerfile: | ||
|
|
||
| - Uses multi-stage builds for optimization | ||
| - Compiles Python bytecode for faster startup | ||
| - Builds the frontend and includes it in the final image | ||
| - Serves the frontend at the root path via FastAPI | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # Backend Dockerfile using uv | ||
| FROM python:3.10-slim AS builder | ||
|
|
||
| # Install uv | ||
| COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv | ||
|
|
||
| # Set working directory | ||
| WORKDIR /app | ||
|
|
||
| # Copy dependency files | ||
| COPY pyproject.toml uv.lock ./ | ||
|
|
||
| # Install dependencies using uv | ||
| RUN uv sync --frozen --no-dev | ||
|
|
||
| # Copy application code | ||
| COPY . . | ||
|
|
||
| # Compile Python bytecode for faster startup | ||
| # Compile all Python files recursively in lib/ and root | ||
| RUN python -m compileall -b -q -r lib/ && \ | ||
| python -m compileall -b -q app.py config.py models.py mock_llm.py debug_pipeline.py 2>/dev/null || true | ||
|
|
||
| # Frontend build stage | ||
| FROM node:20-alpine AS frontend-builder | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Copy frontend package files | ||
| COPY frontend/package.json frontend/yarn.lock ./ | ||
|
|
||
| # Install dependencies | ||
| RUN yarn install --frozen-lockfile | ||
|
|
||
| # Copy frontend source | ||
| COPY frontend/ ./ | ||
|
|
||
| # Build the frontend | ||
| RUN yarn build | ||
|
|
||
| # Production stage | ||
| FROM python:3.10-slim | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Install uv in production image | ||
| COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv | ||
|
|
||
| # Copy virtual environment from builder | ||
| COPY --from=builder /app/.venv /app/.venv | ||
|
|
||
| # Copy application code and compiled bytecode | ||
| # Copy lib directory (includes templates, blocks, etc. and their .pyc files) | ||
| COPY --from=builder /app/lib /app/lib | ||
| # Copy main application files (including .pyc files if they exist) | ||
| COPY --from=builder /app/app.py* /app/ | ||
| COPY --from=builder /app/config.py* /app/ | ||
| COPY --from=builder /app/models.py* /app/ | ||
| COPY --from=builder /app/pyproject.toml /app/pyproject.toml | ||
|
|
||
| # Copy built frontend from frontend-builder | ||
| COPY --from=frontend-builder /app/build /app/frontend/build | ||
|
|
||
| # Create data directory and ensure custom blocks directory exists | ||
| RUN mkdir -p /app/data /app/lib/blocks/custom | ||
|
|
||
| # Set environment variables | ||
| ENV PATH="/app/.venv/bin:$PATH" | ||
| ENV PYTHONUNBUFFERED=1 | ||
| ENV PYTHONDONTWRITEBYTECODE=1 | ||
|
|
||
| # Expose port | ||
| EXPOSE 8000 | ||
|
|
||
| # Run the application | ||
| CMD ["uv", "run", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"] | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| services: | ||
| backend: | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile | ||
| container_name: datagenflow | ||
| ports: | ||
| - "8000:8000" | ||
| env_file: | ||
| - .env | ||
| volumes: | ||
| # Mount data directory for persistence | ||
| - ./data:/app/data | ||
| # Mount custom blocks directory for hot-reloading (restart required for new blocks) | ||
| - ./lib/blocks/custom:/app/lib/blocks/custom | ||
| restart: unless-stopped | ||
| healthcheck: | ||
| test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/api/health')"] | ||
nicofretti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| interval: 30s | ||
| timeout: 10s | ||
| retries: 3 | ||
| start_period: 40s | ||
|
|
||
| volumes: | ||
| data: | ||
nicofretti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.