zeroclaw/Dockerfile
Argenis ebdcee3a5d
fix(build): remove OpenSSL dependency to prevent build failures
This fixes issue #271 where cargo build fails due to openssl-sys dependency
being pulled in even though the project uses rustls-tls for all TLS connections.

**Problem:**
- The Dockerfile installed `libssl-dev` in the builder stage
- This caused `openssl-sys` to be activated as a dependency
- Users without OpenSSL installed would get build failures:
  ```
  error: failed to run custom build command for openssl-sys v0.9.111
  Could not find directory of OpenSSL installation
  ```

**Solution:**
- Remove `libssl-dev` from Dockerfile build dependencies
- ZeroClaw uses `rustls-tls` exclusively for all TLS connections:
  - reqwest: `features = ["rustls-tls"]`
  - lettre: `features = ["rustls-tls"]`
  - tokio-tungstenite: `features = ["rustls-tls-webpki-roots"]`

**Benefits:**
- Smaller Docker images (no OpenSSL headers/libs needed)
- Faster builds (fewer dependencies to compile)
- Consistent builds regardless of system OpenSSL availability
- True pure-Rust TLS stack without C dependencies

**Affected platforms:**
- Users without OpenSSL dev packages can now build directly
- Docker builds are more portable and reproducible
- Binary distributions don't depend on system OpenSSL version

All tests pass.

Related to #271

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 01:58:40 -05:00

108 lines
3.4 KiB
Docker

# syntax=docker/dockerfile:1
# ── Stage 1: Build ────────────────────────────────────────────
FROM rust:1.93-slim-trixie AS builder
WORKDIR /app
# Install build dependencies
RUN apt-get update && apt-get install -y \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
# 1. Copy manifests to cache dependencies
COPY Cargo.toml Cargo.lock ./
# Create dummy main.rs to build dependencies
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo build --release --locked
RUN rm -rf src
# 2. Copy source code
COPY . .
# Touch main.rs to force rebuild
RUN touch src/main.rs
RUN cargo build --release --locked && \
strip target/release/zeroclaw
# ── Stage 2: Permissions & Config Prep ───────────────────────
FROM busybox:latest AS permissions
# Create directory structure (simplified workspace path)
RUN mkdir -p /zeroclaw-data/.zeroclaw /zeroclaw-data/workspace
# Create minimal config for PRODUCTION (allows binding to public interfaces)
# NOTE: Provider configuration must be done via environment variables at runtime
RUN cat > /zeroclaw-data/.zeroclaw/config.toml << 'EOF'
workspace_dir = "/zeroclaw-data/workspace"
config_path = "/zeroclaw-data/.zeroclaw/config.toml"
api_key = ""
default_provider = "openrouter"
default_model = "anthropic/claude-sonnet-4-20250514"
default_temperature = 0.7
[gateway]
port = 3000
host = "[::]"
allow_public_bind = true
EOF
RUN chown -R 65534:65534 /zeroclaw-data
# ── Stage 3: Development Runtime (Debian) ────────────────────
FROM debian:trixie-slim AS dev
# Install runtime dependencies + basic debug tools
RUN apt-get update && apt-get install -y \
ca-certificates \
openssl \
curl \
git \
iputils-ping \
vim \
&& rm -rf /var/lib/apt/lists/*
COPY --from=permissions /zeroclaw-data /zeroclaw-data
COPY --from=builder /app/target/release/zeroclaw /usr/local/bin/zeroclaw
# Overwrite minimal config with DEV template (Ollama defaults)
COPY dev/config.template.toml /zeroclaw-data/.zeroclaw/config.toml
RUN chown 65534:65534 /zeroclaw-data/.zeroclaw/config.toml
# Environment setup
# Use consistent workspace path
ENV ZEROCLAW_WORKSPACE=/zeroclaw-data/workspace
ENV HOME=/zeroclaw-data
# Defaults for local dev (Ollama) - matches config.template.toml
ENV PROVIDER="ollama"
ENV ZEROCLAW_MODEL="llama3.2"
ENV ZEROCLAW_GATEWAY_PORT=3000
# Note: API_KEY is intentionally NOT set here to avoid confusion.
# It is set in config.toml as the Ollama URL.
WORKDIR /zeroclaw-data
USER 65534:65534
EXPOSE 3000
ENTRYPOINT ["zeroclaw"]
CMD ["gateway", "--port", "3000", "--host", "[::]"]
# ── Stage 4: Production Runtime (Distroless) ─────────────────
FROM gcr.io/distroless/cc-debian13:nonroot AS release
COPY --from=builder /app/target/release/zeroclaw /usr/local/bin/zeroclaw
COPY --from=permissions /zeroclaw-data /zeroclaw-data
# Environment setup
ENV ZEROCLAW_WORKSPACE=/zeroclaw-data/workspace
ENV HOME=/zeroclaw-data
# Defaults for prod (OpenRouter)
ENV PROVIDER="openrouter"
ENV ZEROCLAW_MODEL="anthropic/claude-sonnet-4-20250514"
ENV ZEROCLAW_GATEWAY_PORT=3000
# API_KEY must be provided at runtime!
WORKDIR /zeroclaw-data
USER 65534:65534
EXPOSE 3000
ENTRYPOINT ["zeroclaw"]
CMD ["gateway", "--port", "3000", "--host", "[::]"]