demo / Dockerfile
Pierre Andrews
no more secrets
7ec7056
# ------------------------------------------------------------
# Stage 0: Pull ARE
# ------------------------------------------------------------
FROM ubuntu:20.04 AS fetch_repo
RUN apt update && \
apt install -y git curl && \
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash && \
apt-get install -y git-lfs
RUN git clone https://$GITHUB_USERNAME:$GITHUB_TOKEN@github.com/facebookresearch/meta-agents-research-environments.git && \
cd meta-agents-research-environments && \
git lfs install && \
git lfs pull && \
rm -rf ./are/simulation/tests && \
rm -rf ./are/simulation/tutorials
# ------------------------------------------------------------
# Stage 1: Build the front end
# ------------------------------------------------------------
FROM node:23 AS frontend-builder
WORKDIR /app
COPY --from=fetch_repo /meta-agents-research-environments/are/simulation/gui/client ./are/simulation/gui/client
WORKDIR /app/are/simulation/gui/client
# Clear npm cache and remove lock file to fix ARM64 rollup issue
RUN npm cache clean --force && rm -f package-lock.json
RUN --mount=type=cache,target=/root/.npm NPM_CONFIG_CACHE=/root/.npm npm install
RUN npm run build
# ------------------------------------------------------------
# Stage 1.5: Build the React frontend
# ------------------------------------------------------------
FROM node:23 AS react-frontend-builder
WORKDIR /app/frontend
COPY frontend/package.json ./
# Clear npm cache and remove lock file to fix ARM64 rollup issue
RUN npm cache clean --force && rm -f package-lock.json
RUN --mount=type=cache,target=/root/.npm NPM_CONFIG_CACHE=/root/.npm npm install
COPY frontend/ ./
RUN npm run build
# ------------------------------------------------------------
# Stage 2: Build the backend and gradio app
# ------------------------------------------------------------
FROM python:3.10.14-slim
## Needed for docker dev mode in spaces
RUN useradd -m -u 1000 user
## Backend
ARG SERVER_VERSION=unknown
RUN apt-get update && apt-get install -y \
curl \
git \
&& rm -rf /var/lib/apt/lists/*
# Needed packages for docker dev mode in spaces
RUN apt-get update && apt-get install -y \
bash git-lfs wget procps \
vim net-tools \
&& rm -rf /var/lib/apt/lists/*
RUN pip install uv
# ARE install
COPY --from=fetch_repo /meta-agents-research-environments/are /app/are
COPY --from=fetch_repo /meta-agents-research-environments/build_hooks /app/build_hooks
COPY --from=fetch_repo /meta-agents-research-environments/pyproject.toml /app/pyproject.toml
COPY --from=fetch_repo /meta-agents-research-environments/uv.lock /app/uv.lock
COPY --from=fetch_repo /meta-agents-research-environments/requirements* /app/
COPY --from=fetch_repo /meta-agents-research-environments/README.md /app/README.md
COPY --from=fetch_repo /meta-agents-research-environments/LICENSE /app/LICENSE
WORKDIR /app
ARG VIRTUAL_ENV /app/.venv
RUN --mount=type=cache,target=/root/.cache/pip uv venv
RUN --mount=type=cache,target=/root/.cache/pip uv pip install '.'
RUN rm -rf /app/are/gui/client
COPY --from=frontend-builder /app/are/simulation/gui/client/build /app/are/simulation/gui/client/build
# Env
ENV PYTHONUNBUFFERED=1
ENV ARE_SERVER_HOSTNAME=0.0.0.0
ENV ARE_SERVER_VERSION=$SERVER_VERSION
ENV HF_HOME=/app/.cache
ENV HF_DATASETS_CACHE=/app/.cache
# For gradio to recognize the env as a space
ENV SYSTEM=spaces
# For uvicorn to allow headers and avoid mixed content in site and iframe
ENV FORWARDED_ALLOW_IPS="*"
# Port React frontend build
COPY --from=react-frontend-builder /app/frontend/build /app/frontend/build
WORKDIR /app
RUN chown 1000 /app
EXPOSE 7860
# Backend deps
RUN uv pip install -U huggingface_hub "datasets==4.0.0" "gradio[oauth]==5.42.0" gradio_modal "jsonschema>=4.0.0" psutil
RUN uv pip install --no-cache-dir flask gunicorn
# Get core code
COPY backend/ /app/backend/
COPY app.py /app/app.py
COPY run.sh /app/run.sh
COPY mcp_demo_prompts.json /app/mcp_demo_prompts.json
# Create data directory with proper permissions
RUN mkdir -p /app/data && chown 1000:1000 /app/data
# Env vars
ENV PORT=7860 FLASK_ENV=production PYTHONUNBUFFERED=1 STORAGE_PATH=/app/data
RUN chmod 755 /app/.venv
USER 1000
# Start Flask (serves static frontend and the API)
CMD ["bash", "run.sh"]