1
- # Use Node.js 23.3.0 as specified in package.json
1
+ # Build stage
2
2
FROM node:23.3.0-slim AS builder
3
3
4
4
# Playwright environment variables
@@ -7,11 +7,13 @@ ENV PLAYWRIGHT_BROWSERS_PATH=/usr/bin \
7
7
PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium \
8
8
PLAYWRIGHT_SKIP_BROWSER_VALIDATION=1
9
9
10
- # Install pnpm globally and install necessary build tools
10
+ # Install pnpm and build dependencies in a single layer
11
11
RUN npm install -g pnpm@9.4.0 && \
12
12
apt-get update && \
13
- apt-get install -y git python3 make g++ curl \
13
+ apt-get install -y --no-install-recommends \
14
+ git python3 make g++ curl \
14
15
chromium \
16
+ dbus \
15
17
libglib2.0-0 \
16
18
libnss3 \
17
19
libnspr4 \
@@ -31,17 +33,28 @@ RUN npm install -g pnpm@9.4.0 && \
31
33
libasound2 \
32
34
libatspi2.0-0 && \
33
35
apt-get clean && \
34
- rm -rf /var/lib/apt/lists/*
35
-
36
- # Set Python 3 as the default python
37
- RUN ln -s /usr/bin/python3 /usr/bin/python
36
+ rm -rf /var/lib/apt/lists/* && \
37
+ # Set up D-Bus configuration
38
+ mkdir -p /var/run/dbus && \
39
+ dbus-uuidgen > /var/lib/dbus/machine-id && \
40
+ mkdir -p /usr/share/dbus-1/services && \
41
+ # Create D-Bus service file for Chrome Session Manager
42
+ echo "[D-BUS Service]\
43
+ Name=org.chromium.SessionManager\
44
+ Exec=/usr/bin/chromium --no-sandbox\
45
+ User=root" > /usr/share/dbus-1/services/org.chromium.SessionManager.service && \
46
+ # Set Python 3 as the default python
47
+ ln -s /usr/bin/python3 /usr/bin/python
38
48
39
49
WORKDIR /app
40
50
41
- # Copy all files
42
- COPY . .
51
+ # Copy package files first to leverage Docker cache
52
+ COPY package.json pnpm-workspace.yaml .npmrc turbo.json ./
53
+ COPY agent/package.json ./agent/
54
+ COPY client/package.json ./client/
55
+ COPY packages/*/package.json ./packages/
43
56
44
- # Install dependencies with improved error handling and debugging
57
+ # Install dependencies with improved caching
45
58
RUN pnpm install --frozen-lockfile || \
46
59
(echo "Frozen lockfile install failed, trying without..." && \
47
60
pnpm install --no-frozen-lockfile) && \
@@ -50,27 +63,24 @@ RUN pnpm install --frozen-lockfile || \
50
63
# Debug workspace packages
51
64
pnpm list -r | grep "@elizaos" || echo "No workspace packages found!"
52
65
53
- # Build with detailed logging
66
+ # Copy the rest of the files after dependency installation
67
+ COPY . .
68
+
69
+ # Build with detailed logging but cleaner approach
54
70
RUN set -ex && \
55
71
for i in 1 2 3; do \
56
72
echo "Build attempt $i" && \
57
- (PNPM_DEBUG=1 DEBUG=* TURBO_LOG_VERBOSITY=verbose pnpm build-docker 2>&1 | tee build_attempt_${i}.log) && exit 0 || \
58
- (echo "=== Build Failure Details for Attempt ${i} ===" && \
59
- cat build_attempt_${i}.log && \
60
- echo "=== End of Build Failure Details ===" && \
61
- echo "Build failed, retrying..." && \
73
+ (PNPM_DEBUG=1 DEBUG=* TURBO_LOG_VERBOSITY=verbose pnpm build-docker 2>&1) && break || \
74
+ (echo "Build failed, retrying..." && \
62
75
sleep 5) \
63
76
done && \
64
- echo "All build attempts failed" && \
65
- echo "=== All Build Logs ===" && \
66
- cat build_attempt_*.log && \
67
- exit 1
68
-
69
- # Prune for production
70
- RUN pnpm prune --prod && \
71
- echo "Production pruning completed"
77
+ # Prune for production
78
+ pnpm prune --prod && \
79
+ echo "Production pruning completed" && \
80
+ # Remove build logs to reduce image size
81
+ rm -rf build_attempt_*.log || true
72
82
73
- # Final stage
83
+ # Runtime stage
74
84
FROM node:23.3.0-slim
75
85
76
86
# Playwright environment variables
@@ -79,13 +89,14 @@ ENV PLAYWRIGHT_BROWSERS_PATH=/usr/bin \
79
89
PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium \
80
90
PLAYWRIGHT_SKIP_BROWSER_VALIDATION=1
81
91
82
- # Install runtime dependencies and certificates first
92
+ # Install runtime dependencies in a single layer
83
93
RUN apt-get update && \
84
94
apt-get upgrade -y && \
85
95
apt-get install -y --no-install-recommends \
86
96
git \
87
97
python3 \
88
98
python3-pip \
99
+ dbus \
89
100
curl \
90
101
node-gyp \
91
102
ffmpeg \
@@ -127,26 +138,23 @@ RUN apt-get update && \
127
138
libcairo2 \
128
139
libasound2 \
129
140
libatspi2.0-0 && \
130
- apt-get clean && \
131
- rm -rf /var/lib/apt/lists/*
132
-
133
- # Install pnpm, PM2, and Google Cloud SDK
134
- RUN npm install -g pnpm@9.4.0 pm2@latest && \
135
- apt-get update && \
136
- apt-get install -y git python3 curl gnupg && \
141
+ # Install Google Cloud SDK in same layer
137
142
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \
138
143
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && \
139
144
apt-get update && \
140
145
apt-get install -y google-cloud-sdk && \
146
+ # Install pnpm and PM2
147
+ npm install -g pnpm@9.4.0 pm2@latest && \
148
+ # Clean up
141
149
apt-get clean && \
142
- rm -rf /var/lib/apt/lists/*
143
-
144
- RUN mkdir -p /app/logs && \
150
+ rm -rf /var/lib/apt/lists/* && \
151
+ # Set up directories
152
+ mkdir -p /app/logs && \
145
153
chmod 755 /app/logs
146
154
147
155
WORKDIR /app
148
156
149
- # Copy necessary files from builder
157
+ # Copy only necessary files from builder
150
158
COPY --from=builder /app/package.json ./
151
159
COPY --from=builder /app/pnpm-workspace.yaml ./
152
160
COPY --from=builder /app/.npmrc ./
@@ -157,6 +165,10 @@ COPY --from=builder /app/client ./client
157
165
COPY --from=builder /app/packages ./packages
158
166
COPY --from=builder /app/scripts ./scripts
159
167
168
+ # Copy D-Bus configuration from builder
169
+ COPY --from=builder /var/lib/dbus/machine-id /var/lib/dbus/
170
+ COPY --from=builder /usr/share/dbus-1/services/org.chromium.SessionManager.service /usr/share/dbus-1/services/
171
+
160
172
# Create necessary directories
161
173
RUN mkdir -p characters && \
162
174
mkdir -p characters/knowledge
@@ -171,7 +183,7 @@ RUN service cron start
171
183
EXPOSE 3000 5173
172
184
173
185
# CMD that fetches and runs the entrypoint script
174
- CMD sh -c 'echo "Fetching latest container entrypoint script..." && \
186
+ CMD dbus-daemon --system --fork && sh -c 'echo "Fetching latest container entrypoint script..." && \
175
187
gsutil cp "gs://${AGENTS_BUCKET_NAME}/_project-files/container-entrypoint.sh" /app/container-entrypoint.sh && \
176
188
chmod +x /app/container-entrypoint.sh && \
177
189
/app/container-entrypoint.sh'
0 commit comments