openclaw/Dockerfile.prod

73 lines
2.0 KiB
Docker

# Stage 1: Build clawdbot from source
FROM node:22-bookworm AS clawdbot-builder
# Install Bun (required for build scripts)
RUN curl -fsSL https://bun.sh/install | bash
ENV PATH="/root/.bun/bin:${PATH}"
RUN corepack enable
WORKDIR /app
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc ./
COPY ui/package.json ./ui/package.json
COPY patches ./patches
COPY scripts ./scripts
RUN pnpm install --frozen-lockfile
COPY . .
RUN pnpm build
# Skip UI build - gateway-only deploy doesn't need it
# (Also avoids extensions/memory-core requiring unreleased clawdbot version)
# Stage 2: Build checkins extension
FROM node:22-slim AS extension-builder
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
WORKDIR /build
COPY extensions/checkins ./
RUN npm install && npm run build
# Stage 3: Production image
FROM node:22-bookworm-slim
WORKDIR /app
# Copy built clawdbot
COPY --from=clawdbot-builder /app/dist ./dist
COPY --from=clawdbot-builder /app/node_modules ./node_modules
COPY --from=clawdbot-builder /app/package.json ./package.json
# UI not built - gateway-only deploy
# Copy the pre-built extension to staging (PVC will mount over /root/.clawdbot)
COPY --from=extension-builder /build /app/bundled-plugins/checkins
# Copy default config
COPY deploy/prod/clawdbot.json /app/clawdbot.default.json
# Install production dependencies for extension
WORKDIR /app/bundled-plugins/checkins
RUN rm -rf node_modules && npm install --omit=dev
# Create entrypoint script
RUN echo '#!/bin/sh\n\
if [ ! -f "/root/.clawdbot/clawdbot.json" ]; then\n\
echo "Creating default config..."\n\
mkdir -p /root/.clawdbot\n\
cp /app/clawdbot.default.json /root/.clawdbot/clawdbot.json\n\
fi\n\
echo "Installing checkins plugin..."\n\
mkdir -p /root/.clawdbot/extensions\n\
cp -r /app/bundled-plugins/checkins /root/.clawdbot/extensions/\n\
exec node /app/dist/entry.js gateway run\n\
' > /app/entrypoint.sh && chmod +x /app/entrypoint.sh
ENV NODE_ENV=production
WORKDIR /root/.clawdbot
ENTRYPOINT ["/bin/sh", "/app/entrypoint.sh"]