feat: support proper arm64 docker cross compilation using zig-cc
parent
28d0a2cc14
commit
faeebf8376
58
Dockerfile
58
Dockerfile
|
@ -1,31 +1,63 @@
|
|||
FROM rust:1.83-alpine3.21 AS builder
|
||||
|
||||
ARG DI_VER=1.2.5
|
||||
# This article showed me everything I needed to get this running
|
||||
# https://dev.to/vladkens/fast-multi-arch-docker-build-for-rust-projects-an1
|
||||
FROM --platform=$BUILDPLATFORM rust:1.83-alpine3.21 AS chef
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN apk update && apk add --no-cache build-base
|
||||
ENV PKGCONFIG_SYSROOTDIR=/
|
||||
|
||||
RUN apk update && \
|
||||
apk add --no-cache build-base musl-dev openssl-dev zig && \
|
||||
cargo install --locked cargo-zigbuild cargo-chef@0.1.68 && \
|
||||
rustup target add x86_64-unknown-linux-musl aarch64-unknown-linux-musl
|
||||
|
||||
|
||||
FROM chef AS planner
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN cargo chef prepare --recipe-path recipe.json
|
||||
|
||||
|
||||
FROM chef AS builder
|
||||
|
||||
# Build dumb-init
|
||||
RUN wget -O - "https://github.com/Yelp/dumb-init/archive/refs/tags/v${DI_VER}.tar.gz" | tar -xzf - && \
|
||||
ARG DI_VER=1.2.5
|
||||
|
||||
RUN mkdir -p /app/linux/arm64 /app/linux/amd64 && \
|
||||
wget -O - "https://github.com/Yelp/dumb-init/archive/refs/tags/v${DI_VER}.tar.gz" | tar -xzf - && \
|
||||
cd "dumb-init-${DI_VER}" && \
|
||||
make SHELL=/bin/sh && \
|
||||
mv dumb-init .. && \
|
||||
make CC='zig cc -target x86_64-linux-musl' SHELL=/bin/sh && \
|
||||
ls && \
|
||||
mv dumb-init /app/linux/amd64/dumb-init && \
|
||||
make CC='zig cc -target aarch64-linux-musl' SHELL=/bin/sh && \
|
||||
mv dumb-init /app/linux/arm64/dumb-init && \
|
||||
cd ..
|
||||
|
||||
COPY Cargo.toml Cargo.lock ./
|
||||
COPY --from=planner /app/recipe.json recipe.json
|
||||
|
||||
RUN cargo fetch --locked
|
||||
RUN cargo chef cook \
|
||||
--recipe-path recipe.json \
|
||||
--release --zigbuild \
|
||||
--target x86_64-unknown-linux-musl \
|
||||
--target aarch64-unknown-linux-musl
|
||||
|
||||
COPY . ./
|
||||
COPY . .
|
||||
|
||||
RUN cargo build --release --frozen
|
||||
RUN cargo zigbuild \
|
||||
--release \
|
||||
--target x86_64-unknown-linux-musl \
|
||||
--target aarch64-unknown-linux-musl && \
|
||||
cp target/aarch64-unknown-linux-musl/release/calathea /app/linux/arm64/calathea && \
|
||||
cp target/x86_64-unknown-linux-musl/release/calathea /app/linux/amd64/calathea
|
||||
|
||||
|
||||
FROM alpine:3.21
|
||||
|
||||
COPY --from=builder /app/target/release/calathea /app/calathea
|
||||
COPY --from=builder /app/dumb-init /app/dumb-init
|
||||
ARG TARGETPLATFORM
|
||||
|
||||
COPY --from=builder /app/${TARGETPLATFORM}/calathea /app/calathea
|
||||
COPY --from=builder /app/${TARGETPLATFORM}/dumb-init /app/dumb-init
|
||||
COPY templates /app/templates
|
||||
COPY static /app/static
|
||||
|
||||
|
|
Loading…
Reference in New Issue