Spaces:
Running
Running
Upload Dockerfile with huggingface_hub
Browse files- Dockerfile +35 -33
Dockerfile
CHANGED
|
@@ -1,9 +1,19 @@
|
|
| 1 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 2 |
-
# MicProtocol
|
| 3 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 5 |
|
| 6 |
# βββ Stage 0: mic-realtime (Erlang/OTP) release ββββββββββββββββ
|
|
|
|
|
|
|
|
|
|
| 7 |
FROM erlang:27 AS realtime-build
|
| 8 |
WORKDIR /opt/mic-realtime
|
| 9 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
@@ -28,21 +38,20 @@ RUN uv venv --python /usr/bin/python3 /opt/venv \
|
|
| 28 |
&& VIRTUAL_ENV=/opt/venv uv pip install --index-url https://download.pytorch.org/whl/cpu "torch>=2.0.0" "torchvision>=0.15.0" \
|
| 29 |
&& VIRTUAL_ENV=/opt/venv uv pip install "open-clip-torch>=2.20.0" "transformers>=4.30.0" "Pillow>=10.0.0" "soundfile>=0.12.0" "pyloudnorm>=0.1.0" "numpy>=1.24.0"
|
| 30 |
|
| 31 |
-
# βββ Stage 2: Builder β
|
|
|
|
|
|
|
| 32 |
FROM node:20-slim AS builder
|
| 33 |
WORKDIR /app
|
| 34 |
-
RUN
|
| 35 |
-
libc6-dev sqlite3 libsqlite3-dev g++ make python3 openssl \
|
| 36 |
-
&& rm -rf /var/lib/apt/lists/* \
|
| 37 |
-
&& npm install -g turbo@2.8.12 pnpm@10.30.3
|
| 38 |
COPY . .
|
| 39 |
RUN pnpm install --frozen-lockfile
|
|
|
|
| 40 |
RUN cd apps/api && npx prisma generate
|
| 41 |
-
|
| 42 |
-
RUN pnpm --filter @micprotocol/ui build
|
| 43 |
-
RUN NODE_OPTIONS="--max-old-space-size=4096" pnpm build --filter @micprotocol/api
|
| 44 |
RUN DOCKER_BUILD=true pnpm --filter @micprotocol/web build
|
| 45 |
RUN DOCKER_BUILD=true pnpm --filter @micprotocol/admin build
|
|
|
|
| 46 |
RUN CI=true pnpm install --prod --frozen-lockfile
|
| 47 |
|
| 48 |
# βββ Stage 3: Runner (all-in-one) ββββββββββββββββββββββββββββββ
|
|
@@ -52,54 +61,47 @@ ENV NODE_ENV=production \
|
|
| 52 |
APP_PORT=7860 \
|
| 53 |
API_PORT=4000 WEB_PORT=3000 ADMIN_PORT=3006 \
|
| 54 |
MIC_REALTIME_PORT=4001 \
|
| 55 |
-
POSTGRES_PORT=5432 REDIS_PORT=6379 MEILISEARCH_PORT=7700
|
| 56 |
-
MINIO_PORT=9000 MINIO_CONSOLE_PORT=9090 \
|
| 57 |
-
MAILHOG_PORT=1025 MAILHOG_UI_PORT=8025 \
|
| 58 |
-
LISTMONK_PORT=9000 UMAMI_PORT=3003 \
|
| 59 |
-
COTURN_PORT=3478 LIVEKIT_PORT=7880
|
| 60 |
|
| 61 |
-
# System services
|
|
|
|
| 62 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 63 |
postgresql postgresql-contrib redis-server \
|
| 64 |
ca-certificates curl wget gnupg tini netcat-openbsd python3 \
|
| 65 |
-
openssl libpq5 libssl3
|
|
|
|
| 66 |
&& rm -rf /var/lib/apt/lists/* \
|
| 67 |
-
&& mkdir -p /var/run/postgresql /var/log/nginx /var/lib/nginx/body
|
| 68 |
-
&& mkdir -p /data/minio /data/listmonk/uploads \
|
| 69 |
-
# Download MinIO binary (optional)
|
| 70 |
-
&& curl -fsSL -o /usr/local/bin/minio https://dl.min.io/server/minio/release/linux-amd64/minio 2>/dev/null && chmod +x /usr/local/bin/minio || true \
|
| 71 |
-
# Download Mailhog binary (optional)
|
| 72 |
-
&& curl -fsSL -o /usr/local/bin/mailhog https://github.com/mailhog/MailHog/releases/download/v1.0.1/MailHog_linux_amd64 2>/dev/null && chmod +x /usr/local/bin/mailhog || true
|
| 73 |
|
| 74 |
# Meilisearch binary
|
| 75 |
COPY --from=getmeili/meilisearch:v1.9.0 /bin/meilisearch /usr/local/bin/meilisearch
|
| 76 |
|
| 77 |
-
# mic-realtime release
|
| 78 |
COPY --from=realtime-build /opt/mic-realtime/_build /opt/mic-realtime/_build
|
| 79 |
COPY services/mic-realtime/config /opt/mic-realtime/config
|
| 80 |
|
| 81 |
-
# Python venv + clip-scorer
|
| 82 |
COPY --from=python-build --chown=root:root /opt/venv /opt/venv
|
| 83 |
COPY --from=python-build /app/services/clip-scorer /app/services/clip-scorer
|
| 84 |
ENV PATH="/opt/venv/bin:$PATH" HF_HOME=/app/.hf-cache
|
| 85 |
|
| 86 |
-
# Built application artifacts
|
| 87 |
COPY --from=builder --chown=root:root /app /app
|
| 88 |
|
| 89 |
-
# Restructure Next.js standalone output
|
|
|
|
|
|
|
|
|
|
| 90 |
RUN cp -r apps/web/.next/standalone/apps/web/. apps/web/ \
|
| 91 |
&& cp -r apps/admin/.next/standalone/apps/admin/. apps/admin/ \
|
| 92 |
&& rm -rf apps/web/.next/standalone apps/admin/.next/standalone
|
| 93 |
|
| 94 |
-
#
|
| 95 |
-
COPY
|
| 96 |
-
|
| 97 |
-
# Nginx config: single public port with integration routing
|
| 98 |
-
COPY deploy/nginx-full.conf /etc/nginx/nginx.conf
|
| 99 |
RUN sed -i "s/__APP_PORT__/${APP_PORT}/" /etc/nginx/nginx.conf
|
| 100 |
|
| 101 |
# Startup script
|
| 102 |
-
COPY deploy/start
|
| 103 |
RUN chmod +x /app/start.sh \
|
| 104 |
&& chown -R postgres:postgres /var/run/postgresql /var/lib/postgresql
|
| 105 |
|
|
|
|
| 1 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 2 |
+
# MicProtocol β Hugging Face Space (Docker SDK) all-in-one image
|
| 3 |
+
# Single container running the core stack behind nginx on APP_PORT
|
| 4 |
+
# (HF maps the public domain to this port). Postgres, Redis,
|
| 5 |
+
# Meilisearch, mic-realtime, API + BullMQ workers, Web and Admin
|
| 6 |
+
# all run as processes launched by deploy/start.sh.
|
| 7 |
+
# NOTE: The full integrations suite (Formbricks, Cal.com, Chatwoot,
|
| 8 |
+
# Documenso, Listmonk, Umami, Pretix, MinIO, LiveKit, Coturn, Mailhog)
|
| 9 |
+
# cannot fit in a single free HF cpu-basic container (16 GB RAM).
|
| 10 |
+
# They are omitted here; deploy them elsewhere if needed.
|
| 11 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 12 |
|
| 13 |
# βββ Stage 0: mic-realtime (Erlang/OTP) release ββββββββββββββββ
|
| 14 |
+
# Use Debian-based erlang so the release is glibc-compatible with the
|
| 15 |
+
# node:20-slim runner (a rebar3 release is self-contained; no Erlang
|
| 16 |
+
# system packages needed at runtime).
|
| 17 |
FROM erlang:27 AS realtime-build
|
| 18 |
WORKDIR /opt/mic-realtime
|
| 19 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
|
|
| 38 |
&& VIRTUAL_ENV=/opt/venv uv pip install --index-url https://download.pytorch.org/whl/cpu "torch>=2.0.0" "torchvision>=0.15.0" \
|
| 39 |
&& VIRTUAL_ENV=/opt/venv uv pip install "open-clip-torch>=2.20.0" "transformers>=4.30.0" "Pillow>=10.0.0" "soundfile>=0.12.0" "pyloudnorm>=0.1.0" "numpy>=1.24.0"
|
| 40 |
|
| 41 |
+
# βββ Stage 2: Builder (install deps + prisma generate + web + admin builds) β
|
| 42 |
+
# shared-types and api are pre-built locally (nest build needs >4GB heap,
|
| 43 |
+
# which exceeds HF free-tier container limits). Web and admin build fine on HF.
|
| 44 |
FROM node:20-slim AS builder
|
| 45 |
WORKDIR /app
|
| 46 |
+
RUN npm install -g pnpm@10.30.3
|
|
|
|
|
|
|
|
|
|
| 47 |
COPY . .
|
| 48 |
RUN pnpm install --frozen-lockfile
|
| 49 |
+
# Generate Prisma client (API needs it at runtime)
|
| 50 |
RUN cd apps/api && npx prisma generate
|
| 51 |
+
# Build Web and Admin on HF (these complete successfully)
|
|
|
|
|
|
|
| 52 |
RUN DOCKER_BUILD=true pnpm --filter @micprotocol/web build
|
| 53 |
RUN DOCKER_BUILD=true pnpm --filter @micprotocol/admin build
|
| 54 |
+
# Prune to production deps for a smaller runner image
|
| 55 |
RUN CI=true pnpm install --prod --frozen-lockfile
|
| 56 |
|
| 57 |
# βββ Stage 3: Runner (all-in-one) ββββββββββββββββββββββββββββββ
|
|
|
|
| 61 |
APP_PORT=7860 \
|
| 62 |
API_PORT=4000 WEB_PORT=3000 ADMIN_PORT=3006 \
|
| 63 |
MIC_REALTIME_PORT=4001 \
|
| 64 |
+
POSTGRES_PORT=5432 REDIS_PORT=6379 MEILISEARCH_PORT=7700
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
+
# System services: postgres, redis, nginx, python, tini
|
| 67 |
+
# (No Erlang packages needed β mic-realtime release is self-contained.)
|
| 68 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 69 |
postgresql postgresql-contrib redis-server \
|
| 70 |
ca-certificates curl wget gnupg tini netcat-openbsd python3 \
|
| 71 |
+
openssl libpq5 libssl3 \
|
| 72 |
+
nginx \
|
| 73 |
&& rm -rf /var/lib/apt/lists/* \
|
| 74 |
+
&& mkdir -p /var/run/postgresql /var/log/nginx /var/lib/nginx/body
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
# Meilisearch binary
|
| 77 |
COPY --from=getmeili/meilisearch:v1.9.0 /bin/meilisearch /usr/local/bin/meilisearch
|
| 78 |
|
| 79 |
+
# mic-realtime release (self-contained, ERTS included)
|
| 80 |
COPY --from=realtime-build /opt/mic-realtime/_build /opt/mic-realtime/_build
|
| 81 |
COPY services/mic-realtime/config /opt/mic-realtime/config
|
| 82 |
|
| 83 |
+
# Python venv + clip-scorer source + HF cache
|
| 84 |
COPY --from=python-build --chown=root:root /opt/venv /opt/venv
|
| 85 |
COPY --from=python-build /app/services/clip-scorer /app/services/clip-scorer
|
| 86 |
ENV PATH="/opt/venv/bin:$PATH" HF_HOME=/app/.hf-cache
|
| 87 |
|
| 88 |
+
# Built application artifacts from builder
|
| 89 |
COPY --from=builder --chown=root:root /app /app
|
| 90 |
|
| 91 |
+
# Restructure Next.js standalone output so start.sh paths work:
|
| 92 |
+
# standalone puts server.js under apps/web/.next/standalone/apps/web/,
|
| 93 |
+
# but start.sh expects apps/web/server.js with .next/static and public
|
| 94 |
+
# alongside it.
|
| 95 |
RUN cp -r apps/web/.next/standalone/apps/web/. apps/web/ \
|
| 96 |
&& cp -r apps/admin/.next/standalone/apps/admin/. apps/admin/ \
|
| 97 |
&& rm -rf apps/web/.next/standalone apps/admin/.next/standalone
|
| 98 |
|
| 99 |
+
# Nginx config: single public port -> path-based routing
|
| 100 |
+
COPY deploy/nginx.conf /etc/nginx/nginx.conf
|
|
|
|
|
|
|
|
|
|
| 101 |
RUN sed -i "s/__APP_PORT__/${APP_PORT}/" /etc/nginx/nginx.conf
|
| 102 |
|
| 103 |
# Startup script
|
| 104 |
+
COPY deploy/start.sh /app/start.sh
|
| 105 |
RUN chmod +x /app/start.sh \
|
| 106 |
&& chown -R postgres:postgres /var/run/postgresql /var/lib/postgresql
|
| 107 |
|