|
6 | 6 | # Option 2: Used in release workflow with pre-compiled binaries: |
7 | 7 | # docker build --build-context binaries=binaries-amd64 -f docker/build/Dockerfile.prebuilt -t jamals86/kalamdb:latest . |
8 | 8 |
|
9 | | -# Runtime image only (no build stage needed) |
10 | | -FROM debian:bookworm-slim |
11 | | - |
12 | | -# Install runtime dependencies and create user in single layer |
13 | | -# Note: curl is needed for healthcheck |
14 | | -RUN apt-get update && \ |
15 | | - apt-get install -y --no-install-recommends \ |
16 | | - ca-certificates \ |
17 | | - libssl3 \ |
18 | | - curl \ |
19 | | - && rm -rf /var/lib/apt/lists/* /var/cache/apt/* && \ |
20 | | - useradd -m -u 1000 kalamdb && \ |
21 | | - mkdir -p /data/rocksdb /data/storage /data/logs /config && \ |
22 | | - chown -R kalamdb:kalamdb /data /config |
| 9 | +# Prepare runtime assets without pulling a full distro into the final image. |
| 10 | +FROM busybox:1.36.1-musl AS runtime-prep |
| 11 | + |
| 12 | +RUN mkdir -p /runtime/usr/local/bin /runtime/data/rocksdb /runtime/data/storage /runtime/data/logs /runtime/config && \ |
| 13 | + cp /bin/busybox /runtime/usr/local/bin/busybox |
| 14 | + |
| 15 | +# Copy default server configuration and normalize the data path before the final stage. |
| 16 | +COPY backend/server.example.toml /runtime/config/server.toml |
| 17 | +RUN sed -i 's|data_path = "\./data"|data_path = "/data"|g' /runtime/config/server.toml |
| 18 | + |
| 19 | +# Distroless runtime keeps the final image smaller and reduces the attack surface. |
| 20 | +FROM gcr.io/distroless/cc-debian12:nonroot |
23 | 21 |
|
24 | 22 | # Copy pre-built binaries from build context (provided via --build-context binaries=...) |
25 | 23 | # The build context should contain kalamdb-server and kalam binaries |
26 | 24 | COPY --from=binaries --chmod=755 kalamdb-server /usr/local/bin/kalamdb-server |
27 | 25 | COPY --from=binaries --chmod=755 kalam /usr/local/bin/kalam-cli |
| 26 | +COPY --from=binaries --chmod=755 kalam /usr/local/bin/kalam |
| 27 | +COPY --from=runtime-prep --chmod=755 /runtime/usr/local/bin/busybox /usr/local/bin/busybox |
28 | 28 |
|
29 | | -# Create symlink so 'kalam' command works (docs reference this name) |
30 | | -RUN ln -s /usr/local/bin/kalam-cli /usr/local/bin/kalam |
31 | | - |
32 | | -# Copy default server configuration (owned by kalamdb user) and normalize data path |
33 | | -COPY backend/server.example.toml /config/server.toml |
34 | | -RUN sed -i 's|data_path = "\./data"|data_path = "/data"|g' /config/server.toml && \ |
35 | | - chown kalamdb:kalamdb /config/server.toml |
| 29 | +# Copy writable runtime paths and the normalized config with non-root ownership. |
| 30 | +COPY --from=runtime-prep --chown=65532:65532 /runtime/data /data |
| 31 | +COPY --from=runtime-prep --chown=65532:65532 /runtime/config /config |
36 | 32 |
|
37 | | -# Switch to non-root user |
38 | | -USER kalamdb |
| 33 | +# Distroless nonroot uses uid/gid 65532. |
| 34 | +USER 65532:65532 |
39 | 35 |
|
40 | 36 | # Set working directory (server looks for server.toml here) |
41 | 37 | WORKDIR /data |
42 | 38 |
|
43 | 39 | # Expose default port |
44 | 40 | EXPOSE 8080 |
45 | 41 |
|
46 | | -# Health check using curl (more reliable than CLI which needs auth) |
| 42 | +# Health check using busybox to avoid shipping curl in the runtime image. |
47 | 43 | HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ |
48 | | - CMD curl -sf http://localhost:8080/health || exit 1 |
| 44 | + CMD ["/usr/local/bin/busybox", "wget", "--spider", "-q", "http://127.0.0.1:8080/health"] |
49 | 45 |
|
50 | 46 | # Default command: run server (looks for server.toml in current directory) |
51 | 47 | CMD ["/usr/local/bin/kalamdb-server", "/config/server.toml"] |
0 commit comments