File size: 2,579 Bytes
a49e5c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Stage 1: Build the frontend (Node.js)
FROM node:21.7.2-bookworm-slim AS frontend-builder

WORKDIR /app

# Copy frontend package files and install dependencies
COPY ./frontend/package.json ./frontend/package-lock.json ./
RUN npm install -g [email protected] && npm ci

# Copy frontend source code and build
COPY ./frontend ./
RUN npm run build

# Stage 2: Build the backend dependencies (Python)
FROM python:3.12.3-slim AS backend-builder

WORKDIR /app
ENV PYTHONPATH='/app'

# Set Poetry environment variables for dependency management
ENV POETRY_NO_INTERACTION=1 \
    POETRY_VIRTUALENVS_IN_PROJECT=1 \
    POETRY_VIRTUALENVS_CREATE=1 \
    POETRY_CACHE_DIR=/tmp/poetry_cache

# Install system dependencies and Poetry
RUN apt-get update -y && \
    apt-get install -y curl make git build-essential && \
    python3 -m pip install poetry==1.8.2 --break-system-packages

# Copy Poetry files and install dependencies
COPY ./pyproject.toml ./poetry.lock ./
RUN touch README.md
RUN poetry install --without evaluation,llama-index --no-root && rm -rf $POETRY_CACHE_DIR

# Stage 3: Final runtime image
FROM python:3.12.3-slim AS openhands-app

WORKDIR /app

# Define build argument and environment variables
ARG OPENHANDS_BUILD_VERSION=dev
ENV RUN_AS_OPENHANDS=true \
    OPENHANDS_USER_ID=42420 \
    SANDBOX_LOCAL_RUNTIME_URL=http://host.docker.internal \
    USE_HOST_NETWORK=false \
    WORKSPACE_BASE=/opt/workspace_base \
    OPENHANDS_BUILD_VERSION=$OPENHANDS_BUILD_VERSION \
    SANDBOX_USER_ID=0 \
    FILE_STORE=local \
    FILE_STORE_PATH=/.openhands-state

# Create necessary directories
RUN mkdir -p $FILE_STORE_PATH $WORKSPACE_BASE

# Install runtime dependencies
RUN apt-get update -y && \
    apt-get install -y curl ssh sudo && \
    apt-get clean

# Adjust UID range in login.defs to avoid conflicts
RUN sed -i 's/^UID_MIN.*/UID_MIN 499/' /etc/login.defs && \
    sed -i 's/^UID_MAX.*/UID_MAX 1000000/' /etc/login.defs

# Create user and group for OpenHands
RUN groupadd app && \
    useradd -l -m -u $OPENHANDS_USER_ID -s /bin/bash openhands && \
    usermod -aG app openhands && \
    usermod -aG sudo openhands && \
    echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

# Copy backend dependencies from backend-builder
COPY --from=backend-builder /app/.venv ./.venv

# Copy frontend build artifacts from frontend-builder
COPY --from=frontend-builder /app/dist ./frontend/dist

# Copy the rest of the application code
COPY . .

# Expose port for the application
EXPOSE 3000

# Command to run the application
CMD ["./.venv/bin/python", "-m", "openhands.server.listen"]