nxtgauge-backend-rust/Dockerfile.superfast
Ashwin Kumar c221173172 perf(build): ultra-fast builds with caching and optimized Dockerfiles
- Add Dockerfile.fast with cargo-chef and symbol stripping

- Add Dockerfile.superfast using pre-built base image

- Add Dockerfile.base for dependency caching

- Update Woodpecker with registry cache (cache_from/cache_to)

- Add fast-build.sh for local ultra-fast builds

- Add build-base-image.sh for one-time dependency build

- Enable BuildKit layer caching in CI
2026-04-10 05:43:34 +02:00

38 lines
1.1 KiB
Text

# Super-fast Dockerfile using pre-compiled dependencies
# This requires building a base image first with: cargo chef cook
ARG SERVICE_NAME
# Stage 1: Use pre-built base with all dependencies cached
# Build base with: docker build -f Dockerfile.base -t nxtgauge-rust-base:latest .
FROM ghcr.io/traceworks2023/nxtgauge-rust-base:latest AS builder
ARG SERVICE_NAME
WORKDIR /app
# Copy ONLY the service source code (fast!)
COPY Cargo.toml Cargo.lock ./
COPY crates/ ./crates/
COPY apps/${SERVICE_NAME}/ ./apps/${SERVICE_NAME}/
# Build with optimizations for size and speed
ENV RUSTFLAGS="-C target-feature=+crt-static -C link-arg=-s -C opt-level=z"
ENV CARGO_NET_OFFLINE=true
# Build just this service - dependencies already compiled!
RUN cargo build --release \
--bin ${SERVICE_NAME} \
--target x86_64-unknown-linux-musl \
2>&1 | tail -20
# Stage 2: Minimal runtime
FROM scratch
ARG SERVICE_NAME
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/${SERVICE_NAME} /app/service
USER 65532:65532
EXPOSE 8000
ENTRYPOINT ["/app/service"]