1FROM --platform=$BUILDPLATFORM rust:slim AS builder
2SHELL ["/bin/bash", "-uo", "pipefail", "-c"]
3
4RUN apt-get update -y && apt-get install -y cmake curl xz-utils tar
5ARG ZIG_VERSION=0.15.2
6RUN curl -L "https://ziglang.org/download/${ZIG_VERSION}/zig-$(uname -m)-linux-${ZIG_VERSION}.tar.xz" | tar -J -x -C /usr/local && \
7 ln -s "/usr/local/zig-$(uname -m)-linux-${ZIG_VERSION}/zig" /usr/local/bin/zig
8
9RUN cargo install --locked cargo-zigbuild
10
11WORKDIR /nailpit
12COPY ./src ./src
13COPY ./crates ./crates
14COPY ./Cargo.lock .
15COPY ./Cargo.toml .
16RUN cargo fetch --locked
17
18ARG TARGETPLATFORM
19
20# add the rust target for the target architecture
21RUN if [ "$TARGETPLATFORM" == "linux/amd64" ]; then echo "x86_64-unknown-linux-musl" >/.target; \
22 elif [ "$TARGETPLATFORM" == "linux/arm64" ]; then echo "aarch64-unknown-linux-musl" >/.target; \
23 elif [ "$TARGETPLATFORM" == "linux/arm/v7" ]; then echo "armv7-unknown-linux-musleabihf" >/.target; \
24 elif [ "$TARGETPLATFORM" == "linux/riscv64" ]; then echo "riscv64gc-unknown-linux-musl" >/.target; \
25 else echo "Unsupported architecture $TARGETPLATFORM"; exit 1; \
26 fi
27RUN rustup target add "$(cat /.target)"
28
29RUN if [ "$TARGETPLATFORM" == "linux/amd64" ]; then echo "-C target-cpu=x86-64-v3" >/.target-cpu; \
30 elif [ "$TARGETPLATFORM" == "linux/arm64" ]; then echo "-C target-cpu=cortex-a53" >/.target-cpu; \
31 elif [ "$TARGETPLATFORM" == "linux/arm/v7" ]; then echo "" >/.target-cpu; \
32 elif [ "$TARGETPLATFORM" == "linux/riscv64" ]; then echo "" >/.target-cpu; \
33 else echo "Unsupported architecture $TARGETPLATFORM"; exit 1; \
34 fi
35
36RUN RUSTFLAGS="$(cat /.target-cpu)" cargo zigbuild --release --locked --target "$(cat /.target)" && \
37 mv ./target/$(cat /.target)/release/nailpit .
38
39FROM gcr.io/distroless/static-debian13:latest AS runtime
40WORKDIR /app
41COPY ./defaults/pit.default.toml ./defaults/
42COPY --from=builder /nailpit/nailpit .
43VOLUME /app/configuration
44VOLUME /app/input
45COPY ./templates/* ./templates/
46VOLUME /app/templates
47
48STOPSIGNAL SIGINT
49
50ENTRYPOINT ["/app/nailpit"]