Backup-bdg commited on
Commit
a49e5c3
·
verified ·
1 Parent(s): 5330c80

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +85 -0
Dockerfile ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Stage 1: Build the frontend (Node.js)
2
+ FROM node:21.7.2-bookworm-slim AS frontend-builder
3
+
4
+ WORKDIR /app
5
+
6
+ # Copy frontend package files and install dependencies
7
+ COPY ./frontend/package.json ./frontend/package-lock.json ./
8
+ RUN npm install -g [email protected] && npm ci
9
+
10
+ # Copy frontend source code and build
11
+ COPY ./frontend ./
12
+ RUN npm run build
13
+
14
+ # Stage 2: Build the backend dependencies (Python)
15
+ FROM python:3.12.3-slim AS backend-builder
16
+
17
+ WORKDIR /app
18
+ ENV PYTHONPATH='/app'
19
+
20
+ # Set Poetry environment variables for dependency management
21
+ ENV POETRY_NO_INTERACTION=1 \
22
+ POETRY_VIRTUALENVS_IN_PROJECT=1 \
23
+ POETRY_VIRTUALENVS_CREATE=1 \
24
+ POETRY_CACHE_DIR=/tmp/poetry_cache
25
+
26
+ # Install system dependencies and Poetry
27
+ RUN apt-get update -y && \
28
+ apt-get install -y curl make git build-essential && \
29
+ python3 -m pip install poetry==1.8.2 --break-system-packages
30
+
31
+ # Copy Poetry files and install dependencies
32
+ COPY ./pyproject.toml ./poetry.lock ./
33
+ RUN touch README.md
34
+ RUN poetry install --without evaluation,llama-index --no-root && rm -rf $POETRY_CACHE_DIR
35
+
36
+ # Stage 3: Final runtime image
37
+ FROM python:3.12.3-slim AS openhands-app
38
+
39
+ WORKDIR /app
40
+
41
+ # Define build argument and environment variables
42
+ ARG OPENHANDS_BUILD_VERSION=dev
43
+ ENV RUN_AS_OPENHANDS=true \
44
+ OPENHANDS_USER_ID=42420 \
45
+ SANDBOX_LOCAL_RUNTIME_URL=http://host.docker.internal \
46
+ USE_HOST_NETWORK=false \
47
+ WORKSPACE_BASE=/opt/workspace_base \
48
+ OPENHANDS_BUILD_VERSION=$OPENHANDS_BUILD_VERSION \
49
+ SANDBOX_USER_ID=0 \
50
+ FILE_STORE=local \
51
+ FILE_STORE_PATH=/.openhands-state
52
+
53
+ # Create necessary directories
54
+ RUN mkdir -p $FILE_STORE_PATH $WORKSPACE_BASE
55
+
56
+ # Install runtime dependencies
57
+ RUN apt-get update -y && \
58
+ apt-get install -y curl ssh sudo && \
59
+ apt-get clean
60
+
61
+ # Adjust UID range in login.defs to avoid conflicts
62
+ RUN sed -i 's/^UID_MIN.*/UID_MIN 499/' /etc/login.defs && \
63
+ sed -i 's/^UID_MAX.*/UID_MAX 1000000/' /etc/login.defs
64
+
65
+ # Create user and group for OpenHands
66
+ RUN groupadd app && \
67
+ useradd -l -m -u $OPENHANDS_USER_ID -s /bin/bash openhands && \
68
+ usermod -aG app openhands && \
69
+ usermod -aG sudo openhands && \
70
+ echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
71
+
72
+ # Copy backend dependencies from backend-builder
73
+ COPY --from=backend-builder /app/.venv ./.venv
74
+
75
+ # Copy frontend build artifacts from frontend-builder
76
+ COPY --from=frontend-builder /app/dist ./frontend/dist
77
+
78
+ # Copy the rest of the application code
79
+ COPY . .
80
+
81
+ # Expose port for the application
82
+ EXPOSE 3000
83
+
84
+ # Command to run the application
85
+ CMD ["./.venv/bin/python", "-m", "openhands.server.listen"]