68 lines
2.7 KiB
Docker
68 lines
2.7 KiB
Docker
FROM rust:1.96.1-bookworm AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
COPY Cargo.toml Cargo.lock ./
|
|
COPY vendor ./vendor
|
|
COPY .sqlx ./.sqlx
|
|
COPY apps ./apps
|
|
COPY crates ./crates
|
|
|
|
RUN --mount=type=cache,id=crank-admin-cargo-registry,target=/usr/local/cargo/registry \
|
|
--mount=type=cache,id=crank-admin-cargo-git,target=/usr/local/cargo/git/db \
|
|
--mount=type=cache,id=crank-admin-target,target=/app/target \
|
|
SQLX_OFFLINE=true cargo build --release -p admin-api \
|
|
&& cp /app/target/release/admin-api /tmp/admin-api \
|
|
&& cp /app/target/release/crank-migrate /tmp/crank-migrate
|
|
|
|
# Trusted CA bundle source for the package stage. The slim image ships no CA
|
|
# certificates, so the HTTPS Debian mirror can only be reached after seeding
|
|
# them; the Rust base image provides the bundle without rebuilding the app.
|
|
FROM rust:1.96.1-bookworm AS ca-bundle
|
|
|
|
RUN test -s /etc/ssl/certs/ca-certificates.crt
|
|
|
|
# Package stage: install the security-refreshed Debian packages, then assemble
|
|
# the minimal runtime rootfs. Kept independent of the Rust builder so it can be
|
|
# built and reviewed on its own.
|
|
FROM debian:bookworm-slim AS runtime-rootfs
|
|
|
|
ARG CRANK_SECURITY_REFRESH
|
|
|
|
COPY --from=ca-bundle /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
|
COPY scripts/prepare-runtime-rootfs.sh /usr/local/bin/prepare-runtime-rootfs
|
|
|
|
RUN sed -i 's|http://deb.debian.org|https://deb.debian.org|g' /etc/apt/sources.list.d/debian.sources \
|
|
&& apt-get update \
|
|
&& apt-get install -y --no-install-recommends --only-upgrade \
|
|
base-files libc6 libgcc-s1 gcc-12-base bash dash libtinfo6 libselinux1 libpcre2-8-0 coreutils \
|
|
&& rm -rf /var/lib/apt/lists/* \
|
|
&& dpkg --compare-versions "$(dpkg-query -W -f='${Version}' libpcre2-8-0)" ge '10.42-1+deb12u2' \
|
|
&& sh /usr/local/bin/prepare-runtime-rootfs /runtime \
|
|
&& echo "crank-security-refresh=${CRANK_SECURITY_REFRESH}"
|
|
|
|
COPY apps/admin-api/docker-entrypoint.sh /runtime/usr/local/bin/crank-admin-entrypoint
|
|
COPY scripts/docker-http-healthcheck.sh /runtime/usr/local/bin/crank-http-healthcheck
|
|
|
|
RUN chmod 0755 /runtime/usr/local/bin/crank-admin-entrypoint \
|
|
&& chmod 0755 /runtime/usr/local/bin/crank-http-healthcheck
|
|
|
|
FROM scratch
|
|
|
|
COPY --from=ca-bundle /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
|
COPY --from=runtime-rootfs /runtime /
|
|
|
|
COPY --from=builder /tmp/admin-api /usr/local/bin/admin-api
|
|
COPY --from=builder /tmp/crank-migrate /usr/local/bin/crank-migrate
|
|
|
|
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
|
ENV CRANK_ADMIN_BIND=0.0.0.0:3001
|
|
ENV CRANK_STORAGE_ROOT=/var/lib/crank/storage
|
|
|
|
WORKDIR /app
|
|
|
|
EXPOSE 3001
|
|
|
|
ENTRYPOINT ["/usr/local/bin/crank-admin-entrypoint"]
|
|
CMD ["admin-api"]
|