Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
FROM rust:1-alpine AS builder
RUN apk add --no-cache musl-dev
FROM --platform=$BUILDPLATFORM rust:1-alpine AS builder

# xx provides cross-compilation helpers that auto-detect the target
# architecture from TARGETPLATFORM and configure the sysroot.
COPY --from=tonistiigi/xx / /

RUN apk add --no-cache musl-dev clang lld llvm && \
xx-apk add --no-cache musl-dev

RUN rustup target add $(xx-cargo --print-target-triple)

COPY . /sources
WORKDIR /sources
RUN cargo build --release
RUN chown nobody:nogroup /sources/target/release/bin

# Build the project. xx-cargo automatically configures cross-compilation and linkers.
RUN xx-cargo build --release && \
cp "target/$(xx-cargo --print-target-triple)/release/bin" /pastebin && \
chown nobody:nogroup /pastebin

# Verify the binary is for the correct architecture.
RUN xx-verify /pastebin

FROM scratch
COPY --from=builder /sources/target/release/bin /pastebin
COPY --from=builder /pastebin /pastebin
COPY --from=builder /etc/passwd /etc/passwd

USER nobody
Expand Down