Skip to content

Commit 967293c

Browse files
🚀 Feat: dockerization of the application
- Introduces a multi-stage Dockerfile that builds backend with Python 3.10 and frontend with Node 20 - Adds docker-compose configuration with health checks and volume mounts for data persistence and custom blocks - Updates Makefile install commands to use uv sync instead of uv pip install - Adds a /health endpoint for container health monitoring
1 parent 704ccbc commit 967293c

File tree

6 files changed

+260
-2
lines changed

6 files changed

+260
-2
lines changed

‎.dockerignore‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
*.egg-info/
8+
dist/
9+
build/
10+
.venv/
11+
venv/
12+
ENV/
13+
env/
14+
15+
# Node
16+
node_modules/
17+
npm-debug.log*
18+
yarn-debug.log*
19+
yarn-error.log*
20+
frontend/build/
21+
frontend/node_modules/
22+
website/node_modules/
23+
24+
# IDE
25+
.vscode/
26+
.idea/
27+
*.swp
28+
*.swo
29+
*~
30+
31+
# Testing
32+
.pytest_cache/
33+
.coverage
34+
htmlcov/
35+
.tox/
36+
37+
# Documentation
38+
docs/_build/
39+
*.md
40+
!README.md
41+
42+
# Git
43+
.git/
44+
.gitignore
45+
46+
# Docker
47+
Dockerfile*
48+
docker-compose*.yml
49+
.dockerignore
50+
51+
# Data
52+
data/*.db
53+
data/*.db-journal
54+
55+
# Logs
56+
*.log
57+
58+
# Environment
59+
.env
60+
.env.local
61+
.env.*.local
62+
63+
# OS
64+
.DS_Store
65+
Thumbs.db
66+
67+
# Misc
68+
*.bak
69+
*.tmp
70+
.cache/
71+

‎DOCKER.md‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Docker Setup
2+
3+
This document describes how to run DataGenFlow using Docker.
4+
5+
## Quick Start
6+
7+
1. **Build and start the application:**
8+
9+
```bash
10+
docker-compose up -d
11+
```
12+
13+
2. **Access the application:**
14+
- Frontend: <http://localhost:8000>
15+
- API: <http://localhost:8000/api>
16+
17+
3. **Stop the application:**
18+
19+
```bash
20+
docker-compose down
21+
```
22+
23+
## Custom Blocks
24+
25+
Custom blocks can be added to `lib/blocks/custom/` on your host system. They will be automatically available after restarting the backend container:
26+
27+
```bash
28+
docker-compose restart backend
29+
```
30+
31+
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.
32+
33+
## Environment Variables
34+
35+
You can configure the application using environment variables. Create a `.env` file in the project root:
36+
37+
```env
38+
LLM_ENDPOINT=http://localhost:11434/api/generate
39+
LLM_API_KEY=
40+
LLM_MODEL=llama3
41+
DEBUG=false
42+
```
43+
44+
These variables are automatically passed to the container via `docker-compose.yml`.
45+
46+
## Data Persistence
47+
48+
The `data/` directory is mounted as a volume, so your database and other data will persist between container restarts.
49+
50+
## Building Images
51+
52+
To rebuild the images:
53+
54+
```bash
55+
docker-compose build
56+
```
57+
58+
Or rebuild without cache:
59+
60+
```bash
61+
docker-compose build --no-cache
62+
```
63+
64+
## Development
65+
66+
For development, you may want to mount additional directories or use volume mounts for live code reloading. Modify `docker-compose.yml` as needed.
67+
68+
## Architecture
69+
70+
- **Backend**: Python 3.11 with uv, serves both API and frontend
71+
- **Frontend**: Built with yarn/vite, served as static files by the backend
72+
- **Port**: 8000 (both API and frontend)
73+
74+
The backend Dockerfile:
75+
76+
- Uses multi-stage builds for optimization
77+
- Compiles Python bytecode for faster startup
78+
- Builds the frontend and includes it in the final image
79+
- Serves the frontend at the root path via FastAPI

‎Dockerfile‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Backend Dockerfile using uv
2+
FROM python:3.10-slim AS builder
3+
4+
# Install uv
5+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
6+
7+
# Set working directory
8+
WORKDIR /app
9+
10+
# Copy dependency files
11+
COPY pyproject.toml uv.lock ./
12+
13+
# Install dependencies using uv
14+
RUN uv sync --frozen --no-dev
15+
16+
# Copy application code
17+
COPY . .
18+
19+
# Compile Python bytecode for faster startup
20+
# Compile all Python files recursively in lib/ and root
21+
RUN python -m compileall -b -q -r lib/ && \
22+
python -m compileall -b -q app.py config.py models.py mock_llm.py debug_pipeline.py 2>/dev/null || true
23+
24+
# Frontend build stage
25+
FROM node:20-alpine AS frontend-builder
26+
27+
WORKDIR /app
28+
29+
# Copy frontend package files
30+
COPY frontend/package.json frontend/yarn.lock ./
31+
32+
# Install dependencies
33+
RUN yarn install --frozen-lockfile
34+
35+
# Copy frontend source
36+
COPY frontend/ ./
37+
38+
# Build the frontend
39+
RUN yarn build
40+
41+
# Production stage
42+
FROM python:3.10-slim
43+
44+
WORKDIR /app
45+
46+
# Install uv in production image
47+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
48+
49+
# Copy virtual environment from builder
50+
COPY --from=builder /app/.venv /app/.venv
51+
52+
# Copy application code and compiled bytecode
53+
# Copy lib directory (includes templates, blocks, etc. and their .pyc files)
54+
COPY --from=builder /app/lib /app/lib
55+
# Copy main application files (including .pyc files if they exist)
56+
COPY --from=builder /app/app.py* /app/
57+
COPY --from=builder /app/config.py* /app/
58+
COPY --from=builder /app/models.py* /app/
59+
COPY --from=builder /app/pyproject.toml /app/pyproject.toml
60+
61+
# Copy built frontend from frontend-builder
62+
COPY --from=frontend-builder /app/build /app/frontend/build
63+
64+
# Create data directory and ensure custom blocks directory exists
65+
RUN mkdir -p /app/data /app/lib/blocks/custom
66+
67+
# Set environment variables
68+
ENV PATH="/app/.venv/bin:$PATH"
69+
ENV PYTHONUNBUFFERED=1
70+
ENV PYTHONDONTWRITEBYTECODE=1
71+
72+
# Expose port
73+
EXPOSE 8000
74+
75+
# Run the application
76+
CMD ["uv", "run", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
77+

‎Makefile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ check-deps:
2424
@echo "✅ All dependencies are installed"
2525

2626
install: check-deps
27-
uv pip install -e .
27+
uv venv && uv sync
2828
cd frontend && yarn install
2929

3030
dev: check-deps
31-
uv pip install -e ".[dev]"
31+
uv venv && uv sync --extra dev
3232
cd frontend && yarn install
3333

3434
dev-ui:

‎app.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
3535
app = FastAPI(title="DataGenFlow", version="0.1.0", lifespan=lifespan)
3636

3737

38+
@app.get("/health")
39+
async def health() -> dict[str, str]:
40+
return {"status": "healthy"}
41+
42+
3843
@app.post("/generate_from_file")
3944
async def generate_from_file(
4045
file: UploadFile = File(...), pipeline_id: int = Form(...)

‎docker-compose.yml‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
services:
2+
backend:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
container_name: datagenflow
7+
ports:
8+
- "8000:8000"
9+
env_file:
10+
- .env
11+
volumes:
12+
# Mount data directory for persistence
13+
- ./data:/app/data
14+
# Mount custom blocks directory for hot-reloading (restart required for new blocks)
15+
- ./lib/blocks/custom:/app/lib/blocks/custom
16+
restart: unless-stopped
17+
healthcheck:
18+
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/api/health')"]
19+
interval: 30s
20+
timeout: 10s
21+
retries: 3
22+
start_period: 40s
23+
24+
volumes:
25+
data:
26+

0 commit comments

Comments
 (0)