File size: 4,303 Bytes
f52d137
 
 
 
 
 
 
 
 
 
7ec7056
f52d137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

# ------------------------------------------------------------
# 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"]