80 lines
2.2 KiB
Docker
80 lines
2.2 KiB
Docker
# 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
|
|
|
|
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
|
|
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 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 --from=planner /app/recipe.json recipe.json
|
|
|
|
RUN cargo chef cook \
|
|
--recipe-path recipe.json \
|
|
--release --zigbuild \
|
|
--target x86_64-unknown-linux-musl \
|
|
--target aarch64-unknown-linux-musl
|
|
|
|
COPY . .
|
|
|
|
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
|
|
|
|
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
|
|
|
|
# Create a non-root user & make sure it can write to the data directory
|
|
RUN set -x && \
|
|
adduser -u 82 -D -S -G www-data www-data && \
|
|
mkdir /data && \
|
|
chown -R www-data:www-data /data
|
|
|
|
WORKDIR /data
|
|
|
|
ENV TEMPLATES_DIR=/app/templates \
|
|
STATIC_DIR=/app/static \
|
|
DATA_DIR=/data
|
|
|
|
USER www-data:www-data
|
|
|
|
ENTRYPOINT [ "/app/dumb-init", "--" ]
|
|
CMD [ "/app/calathea", "serve", "0.0.0.0", "8000" ]
|