celld/Dockerfile
| 1 | # syntax=docker/dockerfile:1.7 |
| 2 | |
| 3 | ARG RUST_VERSION=1.97.1 |
| 4 | ARG GO_VERSION=1.25.12 |
| 5 | ARG CELLD_COMMIT=unknown |
| 6 | |
| 7 | FROM rust:${RUST_VERSION}-bookworm AS build |
| 8 | ARG TARGETARCH |
| 9 | WORKDIR /src |
| 10 | COPY Cargo.toml Cargo.lock ./ |
| 11 | COPY crates ./crates |
| 12 | RUN --mount=type=cache,id=celld-cargo-registry,target=/usr/local/cargo/registry,sharing=locked \ |
| 13 | --mount=type=cache,id=celld-cargo-git,target=/usr/local/cargo/git,sharing=locked \ |
| 14 | --mount=type=cache,id=celld-target-${TARGETARCH},target=/src/target,sharing=locked \ |
| 15 | mkdir -p /out && \ |
| 16 | cargo build --release --locked -p celld && \ |
| 17 | install -m 755 target/release/celld /out/celld |
| 18 | |
| 19 | # The release workflow builds this stage on every candidate push, so a |
| 20 | # break in the engine's own tests or lints stops a release before any |
| 21 | # artifact is drafted. |
| 22 | FROM build AS test |
| 23 | ARG TARGETARCH |
| 24 | RUN rustup component add clippy |
| 25 | RUN --mount=type=cache,id=celld-cargo-registry,target=/usr/local/cargo/registry,sharing=locked \ |
| 26 | --mount=type=cache,id=celld-cargo-git,target=/usr/local/cargo/git,sharing=locked \ |
| 27 | --mount=type=cache,id=celld-target-${TARGETARCH},target=/src/target,sharing=locked \ |
| 28 | cargo test --release --locked && \ |
| 29 | cargo clippy --release --all-targets --locked -- -D warnings |
| 30 | |
| 31 | FROM golang:${GO_VERSION}-bookworm AS litestream-build |
| 32 | RUN apt-get update && \ |
| 33 | apt-get install -y --no-install-recommends ca-certificates git && \ |
| 34 | rm -rf /var/lib/apt/lists/* |
| 35 | WORKDIR /src |
| 36 | COPY crates/celld/Cargo.toml /tmp/celld-Cargo.toml |
| 37 | RUN --mount=type=cache,id=celld-litestream-source,target=/var/cache/litestream,sharing=locked \ |
| 38 | LITESTREAM_SHA=$(sed -n \ |
| 39 | 's/^litestream-commit = "\(.*\)"$/\1/p' /tmp/celld-Cargo.toml) && \ |
| 40 | test -n "${LITESTREAM_SHA}" && \ |
| 41 | if ! test -d /var/cache/litestream/.git; then \ |
| 42 | git -C /var/cache/litestream init && \ |
| 43 | git -C /var/cache/litestream remote add origin \ |
| 44 | https://github.com/benbjohnson/litestream.git; \ |
| 45 | fi && \ |
| 46 | if ! git -C /var/cache/litestream cat-file -e "${LITESTREAM_SHA}^{commit}"; then \ |
| 47 | git -C /var/cache/litestream fetch --depth=1 origin "${LITESTREAM_SHA}"; \ |
| 48 | fi && \ |
| 49 | git -C /var/cache/litestream archive "${LITESTREAM_SHA}" | tar -xf - -C /src |
| 50 | RUN --mount=type=cache,id=celld-litestream-go-build,target=/root/.cache/go-build,sharing=locked \ |
| 51 | --mount=type=cache,id=celld-litestream-go-mod,target=/go/pkg/mod,sharing=locked \ |
| 52 | LITESTREAM_VERSION=$(sed -n \ |
| 53 | 's/^litestream-version = "\(.*\)"$/\1/p' /tmp/celld-Cargo.toml) && \ |
| 54 | test -n "${LITESTREAM_VERSION}" && \ |
| 55 | mkdir -p /out && \ |
| 56 | go build -trimpath \ |
| 57 | -ldflags "-X main.Version=${LITESTREAM_VERSION}" \ |
| 58 | -o /out/litestream \ |
| 59 | ./cmd/litestream && \ |
| 60 | test "$(/out/litestream version)" = "${LITESTREAM_VERSION}" |
| 61 | |
| 62 | FROM debian:bookworm-slim |
| 63 | RUN apt-get update && \ |
| 64 | apt-get install -y --no-install-recommends ca-certificates && \ |
| 65 | rm -rf /var/lib/apt/lists/* |
| 66 | ARG CELLD_COMMIT |
| 67 | ARG CELLD_VERSION=unknown |
| 68 | LABEL org.opencontainers.image.title="celld" \ |
| 69 | org.opencontainers.image.revision="${CELLD_COMMIT}" \ |
| 70 | org.opencontainers.image.version="${CELLD_VERSION}" |
| 71 | COPY --from=build /out/celld /usr/local/bin/celld |
| 72 | COPY --from=litestream-build /out/litestream /usr/local/bin/litestream |
| 73 | ENV LITESTREAM_BIN=/usr/local/bin/litestream |
| 74 | ENTRYPOINT ["/usr/local/bin/celld"] |