openclaw/Dockerfile.prod

96 lines
3.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 checkins-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 2b: Build memory-core extension
FROM node:22-slim AS memory-core-builder
WORKDIR /build
COPY extensions/memory-core ./
# Add esbuild and build (skip peer deps to avoid unreleased clawdbot version)
RUN npm install --legacy-peer-deps esbuild && \
npx esbuild index.ts --bundle --platform=node --format=esm --outfile=dist/index.js --external:clawdbot --external:clawdbot/*
# Stage 2c: Build discord extension
FROM node:22-slim AS discord-builder
WORKDIR /build
COPY extensions/discord ./
# Add esbuild and build (skip peer deps to avoid unreleased clawdbot version)
RUN npm install --legacy-peer-deps esbuild && \
npx esbuild index.ts --bundle --platform=node --format=esm --outfile=dist/index.js --external:clawdbot --external:clawdbot/*
# 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
COPY --from=clawdbot-builder /app/docs/reference/templates ./docs/reference/templates
# UI not built - gateway-only deploy
# Copy the pre-built extensions to staging (PVC will mount over /root/.clawdbot)
COPY --from=checkins-builder /build /app/bundled-plugins/checkins
COPY --from=memory-core-builder /build /app/bundled-plugins/memory-core
COPY --from=discord-builder /build /app/bundled-plugins/discord
# Copy default config
COPY deploy/prod/clawdbot.json /app/clawdbot.default.json
# Install production dependencies for extensions
WORKDIR /app/bundled-plugins/checkins
RUN rm -rf node_modules && npm install --omit=dev
# Create entrypoint script
RUN echo '#!/bin/sh\n\
mkdir -p /root/.clawdbot\n\
echo "Deploying config from repo..."\n\
cp /app/clawdbot.default.json /root/.clawdbot/clawdbot.json\n\
echo "Installing plugins..."\n\
mkdir -p /root/.clawdbot/extensions\n\
cp -r /app/bundled-plugins/checkins /root/.clawdbot/extensions/\n\
cp -r /app/bundled-plugins/memory-core /root/.clawdbot/extensions/\n\
cp -r /app/bundled-plugins/discord /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"]