Skip to content

Commit f160995

Browse files
committed
Update Dockerfile.prebuilt
1 parent 68d92f7 commit f160995

1 file changed

Lines changed: 21 additions & 25 deletions

File tree

docker/build/Dockerfile.prebuilt

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,42 @@
66
# Option 2: Used in release workflow with pre-compiled binaries:
77
# docker build --build-context binaries=binaries-amd64 -f docker/build/Dockerfile.prebuilt -t jamals86/kalamdb:latest .
88

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
2321

2422
# Copy pre-built binaries from build context (provided via --build-context binaries=...)
2523
# The build context should contain kalamdb-server and kalam binaries
2624
COPY --from=binaries --chmod=755 kalamdb-server /usr/local/bin/kalamdb-server
2725
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
2828

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
3632

37-
# Switch to non-root user
38-
USER kalamdb
33+
# Distroless nonroot uses uid/gid 65532.
34+
USER 65532:65532
3935

4036
# Set working directory (server looks for server.toml here)
4137
WORKDIR /data
4238

4339
# Expose default port
4440
EXPOSE 8080
4541

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.
4743
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"]
4945

5046
# Default command: run server (looks for server.toml in current directory)
5147
CMD ["/usr/local/bin/kalamdb-server", "/config/server.toml"]

0 commit comments

Comments
 (0)