Skip to content

Commit 9195d6a

Browse files
committed
fix dockerfile
1 parent ab3f4ad commit 9195d6a

File tree

1 file changed

+49
-48
lines changed

1 file changed

+49
-48
lines changed

Dockerfile

+49-48
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Build stage
1+
# Use Node.js 23.3.0 as specified in package.json
22
FROM node:23.3.0-slim AS builder
33

44
# Playwright environment variables
@@ -7,11 +7,10 @@ ENV PLAYWRIGHT_BROWSERS_PATH=/usr/bin \
77
PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium \
88
PLAYWRIGHT_SKIP_BROWSER_VALIDATION=1
99

10-
# Install pnpm and build dependencies in a single layer
10+
# Install pnpm globally and install necessary build tools
1111
RUN npm install -g pnpm@9.4.0 && \
1212
apt-get update && \
13-
apt-get install -y --no-install-recommends \
14-
git python3 make g++ curl \
13+
apt-get install -y git python3 make g++ curl \
1514
chromium \
1615
dbus \
1716
libglib2.0-0 \
@@ -33,28 +32,28 @@ RUN npm install -g pnpm@9.4.0 && \
3332
libasound2 \
3433
libatspi2.0-0 && \
3534
apt-get clean && \
36-
rm -rf /var/lib/apt/lists/* && \
37-
# Set up D-Bus configuration
38-
mkdir -p /var/run/dbus && \
35+
rm -rf /var/lib/apt/lists/*
36+
37+
# Set up D-Bus configuration
38+
RUN mkdir -p /var/run/dbus && \
3939
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]\
40+
mkdir -p /usr/share/dbus-1/services
41+
42+
# Create D-Bus service file for Chrome Session Manager
43+
RUN echo "[D-BUS Service]\
4344
Name=org.chromium.SessionManager\
4445
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
46+
User=root" > /usr/share/dbus-1/services/org.chromium.SessionManager.service
47+
48+
# Set Python 3 as the default python
49+
RUN ln -s /usr/bin/python3 /usr/bin/python
4850

4951
WORKDIR /app
5052

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/
53+
# Copy all files
54+
COPY . .
5655

57-
# Install dependencies with improved caching
56+
# Install dependencies with improved error handling and debugging
5857
RUN pnpm install --frozen-lockfile || \
5958
(echo "Frozen lockfile install failed, trying without..." && \
6059
pnpm install --no-frozen-lockfile) && \
@@ -63,24 +62,27 @@ RUN pnpm install --frozen-lockfile || \
6362
# Debug workspace packages
6463
pnpm list -r | grep "@elizaos" || echo "No workspace packages found!"
6564

66-
# Copy the rest of the files after dependency installation
67-
COPY . .
68-
69-
# Build with detailed logging but cleaner approach
65+
# Build with detailed logging
7066
RUN set -ex && \
7167
for i in 1 2 3; do \
7268
echo "Build attempt $i" && \
73-
(PNPM_DEBUG=1 DEBUG=* TURBO_LOG_VERBOSITY=verbose pnpm build-docker 2>&1) && break || \
74-
(echo "Build failed, retrying..." && \
69+
(PNPM_DEBUG=1 DEBUG=* TURBO_LOG_VERBOSITY=verbose pnpm build-docker 2>&1 | tee build_attempt_${i}.log) && exit 0 || \
70+
(echo "=== Build Failure Details for Attempt ${i} ===" && \
71+
cat build_attempt_${i}.log && \
72+
echo "=== End of Build Failure Details ===" && \
73+
echo "Build failed, retrying..." && \
7574
sleep 5) \
7675
done && \
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
76+
echo "All build attempts failed" && \
77+
echo "=== All Build Logs ===" && \
78+
cat build_attempt_*.log && \
79+
exit 1
80+
81+
# Prune for production
82+
RUN pnpm prune --prod && \
83+
echo "Production pruning completed"
8284

83-
# Runtime stage
85+
# Final stage
8486
FROM node:23.3.0-slim
8587

8688
# Playwright environment variables
@@ -89,7 +91,7 @@ ENV PLAYWRIGHT_BROWSERS_PATH=/usr/bin \
8991
PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium \
9092
PLAYWRIGHT_SKIP_BROWSER_VALIDATION=1
9193

92-
# Install runtime dependencies in a single layer
94+
# Install runtime dependencies and certificates first
9395
RUN apt-get update && \
9496
apt-get upgrade -y && \
9597
apt-get install -y --no-install-recommends \
@@ -138,23 +140,26 @@ RUN apt-get update && \
138140
libcairo2 \
139141
libasound2 \
140142
libatspi2.0-0 && \
141-
# Install Google Cloud SDK in same layer
143+
apt-get clean && \
144+
rm -rf /var/lib/apt/lists/*
145+
146+
# Install pnpm, PM2, and Google Cloud SDK
147+
RUN npm install -g pnpm@9.4.0 pm2@latest && \
148+
apt-get update && \
149+
apt-get install -y git python3 curl gnupg && \
142150
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 && \
143151
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && \
144152
apt-get update && \
145153
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
149154
apt-get clean && \
150-
rm -rf /var/lib/apt/lists/* && \
151-
# Set up directories
152-
mkdir -p /app/logs && \
155+
rm -rf /var/lib/apt/lists/*
156+
157+
RUN mkdir -p /app/logs && \
153158
chmod 755 /app/logs
154159

155160
WORKDIR /app
156161

157-
# Copy only necessary files from builder
162+
# Copy necessary files from builder
158163
COPY --from=builder /app/package.json ./
159164
COPY --from=builder /app/pnpm-workspace.yaml ./
160165
COPY --from=builder /app/.npmrc ./
@@ -183,11 +188,7 @@ RUN service cron start
183188
EXPOSE 3000 5173
184189

185190
# CMD that fetches and runs the entrypoint script
186-
CMD sh -c 'if [ ! -f /run/dbus/pid ] || ! ps -p $(cat /run/dbus/pid) > /dev/null; then \
187-
rm -f /run/dbus/pid; \
188-
dbus-daemon --system --fork; \
189-
fi && \
190-
echo "Fetching latest container entrypoint script..." && \
191-
gsutil cp "gs://${AGENTS_BUCKET_NAME}/_project-files/container-entrypoint.sh" /app/container-entrypoint.sh && \
192-
chmod +x /app/container-entrypoint.sh && \
193-
/app/container-entrypoint.sh'
191+
CMD dbus-daemon --system --fork && sh -c 'echo "Fetching latest container entrypoint script..." && \
192+
gsutil cp "gs://${AGENTS_BUCKET_NAME}/_project-files/container-entrypoint.sh" /app/container-entrypoint.sh && \
193+
chmod +x /app/container-entrypoint.sh && \
194+
/app/container-entrypoint.sh'

0 commit comments

Comments
 (0)