monzo-ingestion/Dockerfile.cache
2024-08-09 09:43:10 +01:00

49 lines
1.6 KiB
Docker

# Setup the base build image, this will be used for planning (to cache dependencies) and axctually building the image
ARG RUST_VERSION=1.76.0
FROM clux/muslrust:${RUST_VERSION}-stable AS chef
USER root
RUN apt-get update && \
apt-get install -y --no-install-recommends \
lld musl-tools clang libclang-dev llvm \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
ARG RUST_TARGET_ARCH=aarch64
ARG RUST_TARGET=${RUST_TARGET_ARCH}-unknown-linux-musl
ENV CC_${RUST_TARGET_ARCH}_unknown_linux_musl=clang
ENV AR_${RUST_TARGET_ARCH}_unknown_linux_musl=llvm-ar
ENV CARGO_TARGET_${RUST_TARGET_ARCH}_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-Clink-self-contained=yes -Clinker=rust-lld"
RUN cargo install cargo-chef
WORKDIR /app
FROM chef as planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
ARG BINARY=monzo-ingestion
ARG RUST_TARGET_ARCH=aarch64
ARG RUST_TARGET=${RUST_TARGET_ARCH}-unknown-linux-musl
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --target "${RUST_TARGET}" --recipe-path recipe.json
COPY . .
RUN cargo build --release --target "${RUST_TARGET}" --bin "${BINARY}"
FROM alpine AS runtime
ARG APP_USER=appuser
RUN addgroup -S ${APP_USER} && adduser -S ${APP_USER} -G ${APP_USER}
RUN apk add --no-cache ca-certificates curl
COPY --from=builder /app/target/${RUST_TARGET}/release/${BINARY} /usr/local/bin/server
EXPOSE 3000
HEALTHCHECK --interval=5s --timeout=3s --retries=3 \
CMD curl -f http://localhost:3000/health || exit 1
USER ${APP_USER}
CMD ["/usr/local/bin/server", "serve", "--addr", "0.0.0.0:3000"]