calathea/Dockerfile

80 lines
2.2 KiB
Docker
Raw Normal View History

# 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
2025-01-10 12:22:33 +00:00
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
2025-01-10 12:22:33 +00:00
# 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 - && \
2025-01-10 12:22:33 +00:00
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 && \
2025-01-10 12:22:33 +00:00
cd ..
COPY --from=planner /app/recipe.json recipe.json
2025-01-10 12:22:33 +00:00
RUN cargo chef cook \
--recipe-path recipe.json \
--release --zigbuild \
--target x86_64-unknown-linux-musl \
--target aarch64-unknown-linux-musl
2025-01-10 12:22:33 +00:00
COPY . .
2025-01-10 12:22:33 +00:00
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
2025-01-10 12:22:33 +00:00
FROM alpine:3.21
ARG TARGETPLATFORM
COPY --from=builder /app/${TARGETPLATFORM}/calathea /app/calathea
COPY --from=builder /app/${TARGETPLATFORM}/dumb-init /app/dumb-init
2025-01-10 14:29:45 +00:00
COPY templates /app/templates
2025-01-10 14:45:46 +00:00
COPY static /app/static
2025-01-10 12:22:33 +00:00
# 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
2025-01-12 20:06:45 +00:00
ENV TEMPLATES_DIR=/app/templates \
STATIC_DIR=/app/static \
DATA_DIR=/data
2025-01-10 12:22:33 +00:00
2025-01-10 14:29:45 +00:00
USER www-data:www-data
2025-01-10 12:22:33 +00:00
2025-01-10 14:29:45 +00:00
ENTRYPOINT [ "/app/dumb-init", "--" ]
2025-01-12 20:06:45 +00:00
CMD [ "/app/calathea", "serve", "0.0.0.0", "8000" ]