From 19b4ac53fcdc3f5bc3ab71d09abef7aed465cd36 Mon Sep 17 00:00:00 2001 From: Kunthawat Greethong Date: Mon, 15 Jun 2026 10:40:16 +0700 Subject: [PATCH] Add Dockerfile for EasyPanel deployment --- .dockerignore | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..af7027c6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,68 @@ +# Git +.git +.gitignore + +# Node modules (rebuilt inside Docker) +frontend/node_modules + +# Python cache +__pycache__ +*.pyc +*.pyo +*.pyd +.Python +*.so +*.egg +*.egg-info +dist +build + +# Virtual envs +.venv +venv/ +ENV/ + +# IDE +.idea/ +.vscode/ +*.swp +*.swo + +# OS +.DS_Store +Thumbs.db + +# Docs & markdown (not needed in container) +docs/ +docs-site/ +*.md + +# GitHub meta +.github/ + +# Frontend build is copied separately via --from +# so exclude the local build dir to keep context small +frontend/build/ +frontend/.env +frontend/.env.local +frontend/.env.production + +# Backend env +.env +.env.* +!backend/env_template.txt + +# Test files +**/test/ +**/tests/ +*.test.py +*.spec.py + +# Logs +*.log +logs/ + +# Temp +tmp/ +temp/ +*.tmp diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..554d8493 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,72 @@ +# ============================================================ +# ALwrity Dockerfile — for EasyPanel deployment +# ============================================================ +# Stage 1: Build frontend +FROM node:20-alpine AS frontend-builder + +WORKDIR /app/frontend + +# Copy package files +COPY frontend/package.json frontend/package-lock.json* ./ + +# Install deps (--legacy-peer-deps needed for react-scripts 5) +RUN npm install --legacy-peer-deps + +# Copy frontend source +COPY frontend/ ./ + +# Build static assets +RUN npm run build + +# ============================================================ +# Stage 2: Python backend +FROM python:3.11-slim AS backend + +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 +ENV PORT=8000 + +WORKDIR /app + +# Install build deps for some Python packages +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + libpq-dev \ + curl \ + && rm -rf /var/lib/apt/lists/* + +# Copy requirements first (for caching) +COPY backend/requirements.txt . + +# Install Python deps +RUN pip install --no-cache-dir -r requirements.txt + +# Copy backend source +COPY backend/ ./backend/ + +# Copy frontend build artifacts from Stage 1 +COPY --from=frontend-builder /app/frontend/build ./frontend/build + +# Create workspace directories (created by start_alwrity_backend.py but ensure they exist) +RUN mkdir -p /app/lib/workspace/alwrity_content \ + /app/lib/workspace/alwrity_web_research \ + /app/lib/workspace/alwrity_prompts \ + /app/lib/workspace/alwrity_config + +# Expose port +EXPOSE 8000 + +# Health check +HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ + CMD curl -f http://localhost:8000/health || exit 1 + +# Run with gunicorn + uvicorn workers (recommended for production) +# Fallback to plain uvicorn if gunicorn not installed +CMD python -m gunicorn backend.app:app \ + --worker-class uvicorn.workers.UvicornWorker \ + --bind 0.0.0.0:8000 \ + --workers 2 \ + --timeout 120 \ + --access-logfile - \ + --error-logfile - \ + --log-level info