Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

update

zzhtx25826a82e77d34a
diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml
new file mode 100644
index 000000000..005e88856
--- /dev/null
+++ b/.github/workflows/docker-release.yml
@@ -0,0 +1,70 @@
+name: Docker Release
+
+# Triggered when a GitHub Release is published.
+# Builds a multi-platform Docker image and pushes it to GitHub Container Registry (GHCR).
+#
+# Image: ghcr.io/hkuds/deeptutor
+# Tags:
+# - Version tag stripped of 'v' prefix (e.g. release v1.2.3 → image tag 1.2.3)
+# - latest (always points to the most recently published release)
+#
+# Platforms: linux/amd64, linux/arm64
+
+on:
+ release:
+ types: [published]
+
+permissions:
+ contents: read
+ packages: write
+
+jobs:
+ build-and-push:
+ name: Build and Push Multi-Platform Docker Image
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ # Required for linux/arm64 cross-compilation on GitHub-hosted ubuntu runners
+ - name: Set up QEMU
+ uses: docker/setup-qemu-action@v3
+
+ # Enable BuildKit with multi-platform build support
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v3
+
+ - name: Log in to GitHub Container Registry
+ uses: docker/login-action@v3
+ with:
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ # Extract tags from the release:
+ # type=semver strips the leading 'v' (v1.2.3 → 1.2.3)
+ # type=raw adds a 'latest' tag on every published release
+ - name: Extract Docker metadata
+ id: meta
+ uses: docker/metadata-action@v5
+ with:
+ images: ghcr.io/hkuds/deeptutor
+ tags: |
+ type=semver,pattern={{version}}
+ type=raw,value=latest
+
+ - name: Build and push
+ uses: docker/build-push-action@v6
+ with:
+ context: .
+ file: ./Dockerfile
+ target: production
+ platforms: linux/amd64,linux/arm64
+ push: true
+ tags: ${{ steps.meta.outputs.tags }}
+ labels: ${{ steps.meta.outputs.labels }}
+ # Use GitHub Actions cache to speed up repeated builds
+ # mode=max caches all intermediate layers (frontend-builder and python-base are expensive)
+ cache-from: type=gha
+ cache-to: type=gha,mode=max
diff --git a/Dockerfile b/Dockerfile
index 66de183d4..1df8d5896 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -125,12 +125,12 @@ RUN ln -sf /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
COPY --from=python-base /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=python-base /usr/local/bin /usr/local/bin
-# Copy built frontend from frontend-builder stage
-COPY --from=frontend-builder /app/web/.next ./web/.next
-COPY --from=frontend-builder /app/web/public ./web/public
-COPY --from=frontend-builder /app/web/package.json ./web/package.json
-COPY --from=frontend-builder /app/web/next.config.js ./web/next.config.js
-COPY --from=frontend-builder /app/web/node_modules ./web/node_modules
+# Copy built frontend from frontend-builder stage (standalone mode)
+# The standalone output contains a self-contained server.js + minimal node_modules
+# Static assets and public/ must be copied alongside standalone manually
+COPY --from=frontend-builder /app/web/.next/standalone/ ./web/
+COPY --from=frontend-builder /app/web/.next/static/ ./web/.next/static/
+COPY --from=frontend-builder /app/web/public/ ./web/public/
# Copy application source code
COPY deeptutor/ ./deeptutor/
@@ -248,11 +248,11 @@ echo "[Frontend] 🚀 Starting Next.js frontend on port ${FRONTEND_PORT}..."
find /app/web/.next -type f \( -name "*.js" -o -name "*.json" \) -exec \
sed -i "s|__NEXT_PUBLIC_API_BASE_PLACEHOLDER__|${API_BASE}|g" {} \; 2>/dev/null || true
-# Also update .env.local for any runtime reads
-echo "NEXT_PUBLIC_API_BASE=${API_BASE}" > /app/web/.env.local
-
-# Start Next.js
-cd /app/web && exec node node_modules/next/dist/bin/next start -H 0.0.0.0 -p ${FRONTEND_PORT}
+# Start Next.js standalone server
+# The standalone server reads PORT and HOSTNAME from environment variables
+export PORT=${FRONTEND_PORT}
+export HOSTNAME=0.0.0.0
+exec node /app/web/server.js
EOF
RUN sed -i 's/\r$//' /app/start-frontend.sh && chmod +x /app/start-frontend.sh
@@ -321,6 +321,12 @@ ENTRYPOINT ["/app/entrypoint.sh"]
# ============================================
FROM production AS development
+# Re-add full node_modules for development hot-reload
+# (Production uses standalone output which doesn't include full node_modules)
+COPY --from=frontend-builder /app/web/node_modules ./web/node_modules
+COPY --from=frontend-builder /app/web/package.json ./web/package.json
+COPY --from=frontend-builder /app/web/next.config.js ./web/next.config.js
+
# Install development tools
RUN apt-get update && apt-get install -y --no-install-recommends \
vim \
diff --git a/docker-compose.ghcr.yml b/docker-compose.ghcr.yml
new file mode 100644
index 000000000..e8e30acc0
--- /dev/null
+++ b/docker-compose.ghcr.yml
@@ -0,0 +1,92 @@
+# ============================================
+# DeepTutor Docker Compose — Pre-built GHCR Image
+# ============================================
+# Run DeepTutor using the official pre-built image from GitHub Container Registry.
+# No local build required — the image is pulled automatically.
+#
+# Usage:
+# docker compose -f docker-compose.ghcr.yml up -d
+#
+# To pin a specific version:
+# Edit the image tag below, e.g. ghcr.io/hkuds/deeptutor:1.0.0
+#
+# Prerequisites:
+# 1. Copy .env.example to .env and fill in your API keys
+# 2. Read the API URL note below before starting
+#
+# ============================================
+# IMPORTANT: Frontend-to-Backend API URL
+# ============================================
+# The frontend (Next.js) runs entirely in the user's browser — not in the container.
+# This means "localhost" in the browser refers to the USER'S MACHINE, not the Docker host.
+#
+# LOCAL deployment (Docker on the same machine you browse from):
+# Leave NEXT_PUBLIC_API_BASE_EXTERNAL blank. The default http://localhost:8001 works
+# because Docker maps port 8001 from the container to your local machine.
+#
+# REMOTE SERVER deployment (Docker on a server, accessed from another machine):
+# Set NEXT_PUBLIC_API_BASE_EXTERNAL to your server's public IP or hostname, e.g.:
+# NEXT_PUBLIC_API_BASE_EXTERNAL=http://203.0.113.10:8001
+# Without this, the browser will try to reach localhost:8001 on the USER'S laptop
+# (not the server), and all API calls will fail.
+# ============================================
+
+services:
+ deeptutor:
+ image: ghcr.io/hkuds/deeptutor:latest
+ container_name: deeptutor
+ restart: unless-stopped
+ ports:
+ - "${BACKEND_PORT:-8001}:${BACKEND_PORT:-8001}"
+ - "${FRONTEND_PORT:-3782}:${FRONTEND_PORT:-3782}"
+
+ # Load environment variables from .env file
+ env_file:
+ - .env
+
+ environment:
+ # LLM Configuration (Required)
+ - LLM_BINDING=${LLM_BINDING:-openai}
+ - LLM_MODEL=${LLM_MODEL}
+ - LLM_API_KEY=${LLM_API_KEY}
+ - LLM_HOST=${LLM_HOST}
+ - LLM_API_VERSION=${LLM_API_VERSION:-}
+ - DISABLE_SSL_VERIFY=${DISABLE_SSL_VERIFY:-false}
+ # Embedding Configuration (Required for Knowledge Base)
+ - EMBEDDING_BINDING=${EMBEDDING_BINDING:-openai}
+ - EMBEDDING_MODEL=${EMBEDDING_MODEL:-text-embedding-3-large}
+ - EMBEDDING_API_KEY=${EMBEDDING_API_KEY}
+ - EMBEDDING_HOST=${EMBEDDING_HOST}
+ - EMBEDDING_DIMENSION=${EMBEDDING_DIMENSION:-3072}
+ - EMBEDDING_API_VERSION=${EMBEDDING_API_VERSION:-}
+ # Web Search Configuration (Optional)
+ - SEARCH_PROVIDER=${SEARCH_PROVIDER:-}
+ - SEARCH_API_KEY=${SEARCH_API_KEY:-}
+ - SEARCH_BASE_URL=${SEARCH_BASE_URL:-}
+ # Service Ports
+ - BACKEND_PORT=${BACKEND_PORT:-8001}
+ - FRONTEND_PORT=${FRONTEND_PORT:-3782}
+ # API URL for remote/cloud deployment (see note above)
+ # LOCAL: leave blank
+ # REMOTE: set to http://<your-server-ip>:8001 or https://your-domain.com:8001
+ - NEXT_PUBLIC_API_BASE_EXTERNAL=${NEXT_PUBLIC_API_BASE_EXTERNAL:-}
+ - NEXT_PUBLIC_API_BASE=${NEXT_PUBLIC_API_BASE:-}
+
+ volumes:
+ # Persistent data (created automatically on first start)
+ - ./data/user:/app/data/user
+ - ./data/knowledge_bases:/app/data/knowledge_bases
+
+ healthcheck:
+ test: ["CMD", "curl", "-f", "http://localhost:${BACKEND_PORT:-8001}/"]
+ interval: 30s
+ timeout: 10s
+ retries: 3
+ start_period: 60s
+
+ networks:
+ - deeptutor-network
+
+networks:
+ deeptutor-network:
+ driver: bridge
diff --git a/docker-compose.yml b/docker-compose.yml
index d0713aef7..6345115d0 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -62,11 +62,19 @@ services:
# Frontend web port (default: 3782)
- FRONTEND_PORT=${FRONTEND_PORT:-3782}
# ============================================
- # API URL Configuration (Important for Cloud Deployment)
+ # API URL Configuration (Important for Remote Deployment)
# ============================================
- # For CLOUD/REMOTE deployment: Set this to your server's public URL
- # Example: https://your-server.com:8001 or https://api.yourdomain.com
- # If not set, defaults to http://localhost:${BACKEND_PORT} (only works locally)
+ # The frontend runs in the USER'S BROWSER — "localhost" means the user's machine,
+ # not the Docker host. This matters when Docker runs on a remote server.
+ #
+ # LOCAL (browsing from the same machine running Docker):
+ # Leave blank — defaults to http://localhost:8001, which works via port mapping.
+ #
+ # REMOTE SERVER (Docker on a server, accessed from another machine):
+ # Set to the server's public IP or hostname, e.g.:
+ # NEXT_PUBLIC_API_BASE_EXTERNAL=http://203.0.113.10:8001
+ # Without this the browser tries localhost:8001 on the user's laptop and all
+ # API calls (including WebSocket) will fail.
- NEXT_PUBLIC_API_BASE_EXTERNAL=${NEXT_PUBLIC_API_BASE_EXTERNAL:-}
# Alternative: Direct API base URL (same priority as NEXT_PUBLIC_API_BASE_EXTERNAL)
- NEXT_PUBLIC_API_BASE=${NEXT_PUBLIC_API_BASE:-}
diff --git a/web/next.config.js b/web/next.config.js
index a7ff219b7..dfff4146c 100644
--- a/web/next.config.js
+++ b/web/next.config.js
@@ -1,6 +1,10 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
+ // Standalone output: self-contained server.js + minimal node_modules
+ // This eliminates the need to copy the full node_modules into Docker production images
+ output: "standalone",
+
// Move dev indicator to bottom-right corner
devIndicators: {
position: "bottom-right",