homepage/Dockerfile
2024-07-02 16:21:57 +02:00

74 lines
1.6 KiB
Docker

FROM --platform=$BUILDPLATFORM ghcr.io/blackdex/rust-musl:x86_64-musl-stable AS build_amd64
FROM --platform=$BUILDPLATFORM ghcr.io/blackdex/rust-musl:aarch64-musl-stable AS build_arm64
# Build image
FROM --platform=$BUILDPLATFORM build_${TARGETARCH} AS build
ARG TARGETARCH
ARG TARGETVARIANT
ARG TARGETPLATFORM
RUN echo "export CARGO_TARGET=${RUST_MUSL_CROSS_TARGET}" > /env-cargo
WORKDIR /usr/src
# Create blank project
RUN cargo new homepage
WORKDIR /usr/src/homepage
RUN source /env-cargo && \
rustup target add "${CARGO_TARGET}"
COPY Cargo.* ./
# Dummy build to cache dependencies
RUN source /env-cargo && \
cargo build --release --target "${CARGO_TARGET}"
RUN curl -Lo tailwindcss https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64 && \
chmod +x tailwindcss
COPY src ./src
COPY config.toml ./config.toml
# Build the actual app
RUN touch src/main.rs && \
source /env-cargo && \
cargo install --path . --target "${CARGO_TARGET}"
# Required for Tailwind to know what classes are used
COPY templates ./templates
COPY tailwind.* ./
RUN ./tailwindcss -i tailwind.css -o index.css --minify
# Runtime image
FROM docker.io/alpine:latest
WORKDIR /etc/homepage
ARG GID=8686
ARG UID=8686
RUN addgroup -g ${GID} homepage && \
adduser -u ${UID} -D -H -G homepage homepage
USER homepage:homepage
EXPOSE 8686
COPY --from=build /root/.cargo/bin/homepage /usr/local/bin/homepage
COPY templates ./templates
COPY assets ./assets
# Copy CSS generated by Tailwind
COPY --from=build /usr/src/homepage/index.css assets/
ENTRYPOINT ["homepage"]