nxtgauge-backend-rust/Dockerfile.ultrafast

34 lines
966 B
Text
Raw Normal View History

# Ultra-fast Dockerfile using pre-built dependencies
# This requires the base image to be built first!
# Base image build: ./scripts/build-base-image.sh
ARG SERVICE_NAME
# Use the pre-built base image with all dependencies cached
FROM ghcr.io/traceworks2023/nxtgauge-rust-base:latest AS builder
ARG SERVICE_NAME
WORKDIR /app
# Copy ONLY the specific service source code
# Dependencies are already compiled in the base image!
COPY apps/${SERVICE_NAME}/ ./apps/${SERVICE_NAME}/
# Build just this service - dependencies already exist!
# This should take 10-30 seconds, not 15-20 minutes!
RUN cargo build --release \
--bin ${SERVICE_NAME} \
--target x86_64-unknown-linux-musl
# Minimal runtime image
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"]