Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
feat(deploy): add full-stack Docker Compose for self-hosting
Jiayuan Zhangec71a41d8f2c
diff --git a/.dockerignore b/.dockerignorenew file mode 100644index 0000000000..4988d0bd11--- /dev/null+++ b/.dockerignore@@ -0,0 +1,38 @@+# Dependencies+node_modules+.pnpm-store++# Build outputs+.next+dist+server/bin+server/tmp++# Git+.git+.gitignore++# Environment+.env+.env.*+!.env.example++# IDE+.idea+.vscode+*.swp+*.swo++# OS+.DS_Store+Thumbs.db++# Test+e2e/test-results+coverage++# Docs+docs/++# Desktop app (not needed for web self-hosting)+apps/desktopdiff --git a/Dockerfile b/Dockerfileindex 2cb60ad298..cfbd979087 100644--- a/Dockerfile+++ b/Dockerfile@@ -30,7 +30,9 @@ COPY --from=builder /src/server/bin/server .COPY --from=builder /src/server/bin/multica .COPY --from=builder /src/server/bin/migrate .COPY server/migrations/ ./migrations/+COPY docker/entrypoint.sh .+RUN chmod +x entrypoint.shEXPOSE 8080-ENTRYPOINT ["./server"]+ENTRYPOINT ["./entrypoint.sh"]diff --git a/Dockerfile.web b/Dockerfile.webnew file mode 100644index 0000000000..2df2f1e0f1--- /dev/null+++ b/Dockerfile.web@@ -0,0 +1,70 @@+# --- Dependencies ---+FROM node:22-alpine AS deps++RUN corepack enable && corepack prepare [email protected] --activate++WORKDIR /app++# Copy workspace config and all package.json files for dependency resolution+COPY pnpm-lock.yaml pnpm-workspace.yaml package.json turbo.json ./+COPY apps/web/package.json apps/web/+COPY packages/core/package.json packages/core/+COPY packages/ui/package.json packages/ui/+COPY packages/views/package.json packages/views/+COPY packages/tsconfig/package.json packages/tsconfig/+COPY packages/eslint-config/package.json packages/eslint-config/++RUN pnpm install --frozen-lockfile++# --- Build ---+FROM node:22-alpine AS builder++RUN corepack enable && corepack prepare [email protected] --activate++WORKDIR /app++COPY --from=deps /app/node_modules ./node_modules+COPY --from=deps /app/apps/web/node_modules ./apps/web/node_modules+COPY --from=deps /app/packages/core/node_modules ./packages/core/node_modules+COPY --from=deps /app/packages/ui/node_modules ./packages/ui/node_modules+COPY --from=deps /app/packages/views/node_modules ./packages/views/node_modules+COPY --from=deps /app/packages/tsconfig/node_modules ./packages/tsconfig/node_modules+COPY --from=deps /app/packages/eslint-config/node_modules ./packages/eslint-config/node_modules++# Copy source+COPY package.json turbo.json pnpm-workspace.yaml ./+COPY apps/web/ apps/web/+COPY packages/ packages/++# Set build-time env: tells Next.js rewrites to proxy API calls to the backend service+ARG REMOTE_API_URL=http://backend:8080+ENV REMOTE_API_URL=$REMOTE_API_URL+ENV STANDALONE=true++# Build the web app (standalone output for minimal runtime)+RUN pnpm --filter @multica/web build++# --- Runtime ---+FROM node:22-alpine AS runner++WORKDIR /app++ENV NODE_ENV=production++RUN addgroup --system --gid 1001 nodejs && \+ adduser --system --uid 1001 nextjs++# Copy standalone output (includes traced node_modules)+COPY --from=builder /app/apps/web/.next/standalone ./+# Copy static files (not included in standalone)+COPY --from=builder /app/apps/web/.next/static ./apps/web/.next/static+# Copy public assets+COPY --from=builder /app/apps/web/public ./apps/web/public++USER nextjs++EXPOSE 3000+ENV PORT=3000+ENV HOSTNAME=0.0.0.0++CMD ["node", "apps/web/server.js"]diff --git a/README.md b/README.mdindex 8c2d024e29..5d15e1d6f9 100644--- a/README.md+++ b/README.md@@ -55,15 +55,19 @@ The fastest way to get started — no setup required: **[multica.ai](https://mul### Self-Host with Docker+**Prerequisites:** Docker and Docker Compose.+```bashgit clone https://github.com/multica-ai/multica.gitcd multica-make dev # auto-creates .env, installs deps, starts DB + migrations, launches app+cp .env.example .env+# Edit .env — change JWT_SECRET at minimum+docker compose -f docker-compose.selfhost.yml up -d```-That's it — `make dev` handles environment setup, dependency installation, database creation, migrations, and starts both the backend and frontend. Edit `.env` afterward to customize settings (e.g. `JWT_SECRET`).+This builds and starts PostgreSQL, the backend (with auto-migration), and the frontend. Open http://localhost:3000 when ready.-For explicit control over each step, see the [Self-Hosting Guide](SELF_HOSTING.md).+See the [Self-Hosting Guide](SELF_HOSTING.md) for full configuration, reverse proxy setup, and CLI/daemon instructions.## CLIdiff --git a/SELF_HOSTING.md b/SELF_HOSTING.mdindex f688444198..fceecb25c2 100644--- a/SELF_HOSTING.md+++ b/SELF_HOSTING.md@@ -14,48 +14,44 @@ Multica has three components:Additionally, each user who wants to run AI agents locally installs the **`multica` CLI** and runs the **agent daemon** on their own machine.-## Prerequisites--- Docker and Docker Compose (recommended), or:- - Go 1.26+ (to build from source)- - Node.js 20+ and pnpm 10.28+ (to build the frontend)- - PostgreSQL 17 with the pgvector extension-## Quick Start (Docker Compose)+**Prerequisites:** Docker and Docker Compose.+```bashgit clone https://github.com/multica-ai/multica.gitcd multicacp .env.example .env```-Edit `.env` with your production values (see [Configuration](#configuration) below), then:+Edit `.env` — at minimum, change `JWT_SECRET`:```bash-# Start PostgreSQL-docker compose up -d--# Build the backend-make build+JWT_SECRET=$(openssl rand -hex 32)+```-# Run database migrations-DATABASE_URL="your-database-url" ./server/bin/migrate up+Then start everything:-# Start the backend server-DATABASE_URL="your-database-url" PORT=8080 ./server/bin/server+```bash+docker compose -f docker-compose.selfhost.yml up -d```-For the frontend:+That's it. This builds and starts PostgreSQL, the backend (with auto-migration), and the frontend:-```bash-pnpm install-pnpm build+- **Frontend:** http://localhost:3000+- **Backend API:** http://localhost:8080-# Start the frontend (production mode)-cd apps/web-REMOTE_API_URL=http://localhost:8080 pnpm start+The backend automatically runs database migrations on startup — no manual migration step needed.++### Rebuilding After Updates++```bash+git pull+docker compose -f docker-compose.selfhost.yml up -d --build```+Migrations run automatically on each backend startup.+## ConfigurationAll configuration is done via environment variables. Copy `.env.example` as a starting point.@@ -122,25 +118,23 @@ These are configured on each user's machine, not on the server:Multica requires PostgreSQL 17 with the pgvector extension.-### Using the Included Docker Compose--```bash-docker compose up -d postgres-```+### Using Docker Compose (Recommended)-This starts a `pgvector/pgvector:pg17` container on port 5432 with default credentials (`multica`/`multica`).+The `docker-compose.selfhost.yml` includes PostgreSQL. No separate setup needed.### Using Your Own PostgreSQL-Ensure the pgvector extension is available:+If you prefer to use an existing PostgreSQL instance, ensure the pgvector extension is available:```sqlCREATE EXTENSION IF NOT EXISTS vector;```-### Running Migrations+Set `DATABASE_URL` in your `.env` and remove the `postgres` service from the compose file.++### Running Migrations Manually-Migrations must be run before starting the server:+The Docker Compose setup runs migrations automatically. If you need to run them manually:```bash# Using the built binary@@ -150,6 +144,36 @@ Migrations must be run before starting the server:cd server && go run ./cmd/migrate up```+## Manual Setup (Without Docker Compose)++If you prefer to build and run services manually:++**Prerequisites:** Go 1.26+, Node.js 20+, pnpm 10.28+, PostgreSQL 17 with pgvector.++```bash+# Start your PostgreSQL (or use: docker compose up -d postgres)++# Build the backend+make build++# Run database migrations+DATABASE_URL="your-database-url" ./server/bin/migrate up++# Start the backend server+DATABASE_URL="your-database-url" PORT=8080 JWT_SECRET="your-secret" ./server/bin/server+```++For the frontend:++```bash+pnpm install+pnpm build++# Start the frontend (production mode)+cd apps/web+REMOTE_API_URL=http://localhost:8080 pnpm start+```+## Reverse ProxyIn production, put a reverse proxy in front of both the backend and frontend to handle TLS and routing.@@ -221,7 +245,7 @@ When using separate domains for frontend and backend, set these environment variFRONTEND_ORIGIN=https://app.example.comCORS_ALLOWED_ORIGINS=https://app.example.com-# Frontend+# Frontend (set before building the frontend image)REMOTE_API_URL=https://api.example.comNEXT_PUBLIC_API_URL=https://api.example.comNEXT_PUBLIC_WS_URL=wss://api.example.com/ws@@ -279,8 +303,9 @@ The daemon auto-detects installed agent CLIs and registers itself with the serve## Upgrading-1. Pull the latest code or image-2. Run migrations: `./server/bin/migrate up`-3. Restart the backend and frontend+```bash+git pull+docker compose -f docker-compose.selfhost.yml up -d --build+```-Migrations are forward-only and safe to run on a live database. They are idempotent — running them multiple times has no effect.+Migrations run automatically on backend startup. They are idempotent — running them multiple times has no effect.diff --git a/apps/web/next.config.ts b/apps/web/next.config.tsindex 7ad1a5ae5a..548b211710 100644--- a/apps/web/next.config.ts+++ b/apps/web/next.config.ts@@ -22,6 +22,7 @@ const allowedDevOrigins = process.env.CORS_ALLOWED_ORIGINS: undefined;const nextConfig: NextConfig = {+ ...(process.env.STANDALONE === "true" ? { output: "standalone" as const } : {}),transpilePackages: ["@multica/core", "@multica/ui", "@multica/views"],...(allowedDevOrigins && allowedDevOrigins.length > 0? { allowedDevOrigins }diff --git a/docker-compose.selfhost.yml b/docker-compose.selfhost.ymlnew file mode 100644index 0000000000..55b3f82eb3--- /dev/null+++ b/docker-compose.selfhost.yml@@ -0,0 +1,72 @@+# Self-hosting Docker Compose — starts PostgreSQL, backend, and frontend.+#+# Usage:+# cp .env.example .env+# # Edit .env — change JWT_SECRET at minimum+# docker compose -f docker-compose.selfhost.yml up -d+#+# Frontend: http://localhost:3000+# Backend: http://localhost:8080 (also used by CLI/daemon)++name: multica++services:+ postgres:+ image: pgvector/pgvector:pg17+ environment:+ POSTGRES_DB: ${POSTGRES_DB:-multica}+ POSTGRES_USER: ${POSTGRES_USER:-multica}+ POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-multica}+ ports:+ - "${POSTGRES_PORT:-5432}:5432"+ volumes:+ - pgdata:/var/lib/postgresql/data+ healthcheck:+ test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-multica} -d ${POSTGRES_DB:-multica}"]+ interval: 5s+ timeout: 5s+ retries: 5++ backend:+ build:+ context: .+ dockerfile: Dockerfile+ depends_on:+ postgres:+ condition: service_healthy+ ports:+ - "${PORT:-8080}:8080"+ environment:+ DATABASE_URL: postgres://${POSTGRES_USER:-multica}:${POSTGRES_PASSWORD:-multica}@postgres:5432/${POSTGRES_DB:-multica}?sslmode=disable+ PORT: "8080"+ JWT_SECRET: ${JWT_SECRET:-change-me-in-production}+ FRONTEND_ORIGIN: ${FRONTEND_ORIGIN:-http://localhost:3000}+ CORS_ALLOWED_ORIGINS: ${CORS_ALLOWED_ORIGINS:-}+ RESEND_API_KEY: ${RESEND_API_KEY:-}+ RESEND_FROM_EMAIL: ${RESEND_FROM_EMAIL:[email protected]}+ GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID:-}+ GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET:-}+ GOOGLE_REDIRECT_URI: ${GOOGLE_REDIRECT_URI:-http://localhost:3000/auth/callback}+ S3_BUCKET: ${S3_BUCKET:-}+ S3_REGION: ${S3_REGION:-us-west-2}+ CLOUDFRONT_DOMAIN: ${CLOUDFRONT_DOMAIN:-}+ CLOUDFRONT_KEY_PAIR_ID: ${CLOUDFRONT_KEY_PAIR_ID:-}+ CLOUDFRONT_PRIVATE_KEY: ${CLOUDFRONT_PRIVATE_KEY:-}+ COOKIE_DOMAIN: ${COOKIE_DOMAIN:-}+ MULTICA_APP_URL: ${MULTICA_APP_URL:-http://localhost:3000}++ frontend:+ build:+ context: .+ dockerfile: Dockerfile.web+ args:+ REMOTE_API_URL: http://backend:8080+ depends_on:+ - backend+ ports:+ - "${FRONTEND_PORT:-3000}:3000"+ environment:+ HOSTNAME: "0.0.0.0"++volumes:+ pgdata:diff --git a/docker/entrypoint.sh b/docker/entrypoint.shnew file mode 100644index 0000000000..6af5eabd21--- /dev/null+++ b/docker/entrypoint.sh@@ -0,0 +1,8 @@+#!/bin/sh+set -e++echo "Running database migrations..."+./migrate up++echo "Starting server..."+exec ./server