Skip to content

Commit 0940150

Browse files
committed
Add Docker support, API security, and OpenAPI documentation
* .env.example: Added security section with OPENCLAW_API_KEY and CORS origin configuration, reorganized with section headers * Dockerfile: New multi-stage build with builder and runtime stages, includes healthcheck and native module support for better-sqlite3 * docker-compose.yml: Added service definition with volume persistence, environment variable passthrough, and healthcheck configuration * package.json: Added @fastify/cors, @fastify/swagger, @
1 parent bc8bf34 commit 0940150

10 files changed

Lines changed: 1281 additions & 75 deletions

File tree

.env.example

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# OpenClaw Runtime Configuration
22
# Copy this file to .env and adjust values as needed.
3-
# All variables are optional — defaults shown below.
3+
4+
# ── Database ──────────────────────────────────────────────────────────────────
45

56
# Directory where runtime data (SQLite DB) is stored.
67
# Default: ./runtime
@@ -10,10 +11,27 @@ OPENCLAW_RUNTIME_DIR=./runtime
1011
# Default: ./runtime/openclaw.db
1112
OPENCLAW_DB_PATH=./runtime/openclaw.db
1213

14+
# ── Server ────────────────────────────────────────────────────────────────────
15+
1316
# Server host binding.
14-
# Default: 127.0.0.1 (localhost only)
17+
# Default: 127.0.0.1 (localhost only). Use 0.0.0.0 to expose on the network.
1518
OPENCLAW_HOST=127.0.0.1
1619

1720
# Server port.
1821
# Default: 8787
1922
OPENCLAW_PORT=8787
23+
24+
# ── Security ──────────────────────────────────────────────────────────────────
25+
26+
# API key required on every request as the `x-api-key` header.
27+
# Leave unset (or empty) to disable auth — for local dev only.
28+
# PRODUCTION: always set a strong random key.
29+
# Example: node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
30+
OPENCLAW_API_KEY=
31+
32+
# ── CORS ─────────────────────────────────────────────────────────────────────
33+
34+
# Allowed CORS origin for browser clients.
35+
# Use * to allow all origins (dev), or specify your frontend domain for production.
36+
# Example: https://my-app.example.com
37+
OPENCLAW_CORS_ORIGIN=*

Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# ── Stage 1: Build ────────────────────────────────────────────────────────────
2+
FROM node:22-alpine AS builder
3+
4+
WORKDIR /app
5+
6+
# Install build dependencies for native modules (better-sqlite3)
7+
RUN apk add --no-cache python3 make g++
8+
9+
COPY package*.json tsconfig.json ./
10+
RUN npm ci
11+
12+
COPY src ./src
13+
RUN npm run build
14+
15+
# ── Stage 2: Runtime ─────────────────────────────────────────────────────────
16+
FROM node:22-alpine AS runtime
17+
18+
WORKDIR /app
19+
20+
ENV NODE_ENV=production
21+
22+
# Install native runtime libs
23+
RUN apk add --no-cache python3 make g++
24+
25+
# Copy only what's needed
26+
COPY package*.json ./
27+
RUN npm ci --omit=dev
28+
29+
COPY --from=builder /app/dist ./dist
30+
31+
# Runtime data directory (mount a volume here for persistence)
32+
RUN mkdir -p /app/runtime
33+
34+
EXPOSE 8787
35+
36+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
37+
CMD wget -qO- http://localhost:8787/health || exit 1
38+
39+
CMD ["node", "dist/src/server.js"]

docker-compose.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
services:
2+
memorycore:
3+
build: .
4+
container_name: memorycore
5+
restart: unless-stopped
6+
ports:
7+
- "${OPENCLAW_PORT:-8787}:8787"
8+
environment:
9+
- NODE_ENV=production
10+
- OPENCLAW_HOST=0.0.0.0
11+
- OPENCLAW_PORT=8787
12+
- OPENCLAW_RUNTIME_DIR=/app/runtime
13+
- OPENCLAW_DB_PATH=/app/runtime/openclaw.db
14+
- OPENCLAW_API_KEY=${OPENCLAW_API_KEY}
15+
- OPENCLAW_CORS_ORIGIN=${OPENCLAW_CORS_ORIGIN:-*}
16+
volumes:
17+
# Persist the SQLite DB across container restarts
18+
- ./runtime:/app/runtime
19+
healthcheck:
20+
test: [ "CMD", "wget", "-qO-", "http://localhost:8787/health" ]
21+
interval: 30s
22+
timeout: 5s
23+
retries: 3
24+
start_period: 10s

0 commit comments

Comments
 (0)