-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (55 loc) · 1.98 KB
/
Dockerfile
File metadata and controls
68 lines (55 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Build stage with cargo-chef for better layer caching
# Native build: each runner builds for its own architecture
FROM lukemathwalker/cargo-chef:latest-rust-1.88.0-slim-bookworm AS chef
WORKDIR /app
# Install system dependencies
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
# Build dependencies
FROM chef AS builder
ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG FEATURES=""
RUN echo "Native build on $BUILDPLATFORM for $TARGETPLATFORM with features: $FEATURES"
# Install build dependencies including lld linker for faster linking
RUN apt-get update && \
apt-get install -y \
pkg-config \
libssl-dev \
clang \
cmake \
make \
lld && \
rm -rf /var/lib/apt/lists/*
# Copy cargo config for build optimizations (lld linker, etc.)
COPY .cargo/config.toml /app/.cargo/config.toml
COPY --from=planner /app/recipe.json recipe.json
# Cook dependencies with features if specified
RUN if [ -n "$FEATURES" ]; then \
cargo chef cook --release --features "$FEATURES" --recipe-path recipe.json; \
else \
cargo chef cook --release --recipe-path recipe.json; \
fi
# Build application with optimizations
# The release profile in .cargo/config.toml handles: thin LTO, strip, opt-level=3
COPY . .
# Set sqlx to offline mode (migrations are in separate SQL files)
ENV SQLX_OFFLINE=true
# Build with features if specified
RUN if [ -n "$FEATURES" ]; then \
cargo build --release --features "$FEATURES" --bin postgres-stream; \
else \
cargo build --release --bin postgres-stream; \
fi && \
strip target/release/postgres-stream
# Runtime stage with distroless for security
FROM gcr.io/distroless/cc-debian12:nonroot
WORKDIR /app
# Create non-root user (distroless already has nonroot user)
USER nonroot:nonroot
# Copy binary and configuration files
COPY --from=builder /app/target/release/postgres-stream ./postgres-stream
COPY configuration/ ./configuration/
# Use exec form for proper signal handling
ENTRYPOINT ["./postgres-stream"]