homepage/Dockerfile

75 lines
1.6 KiB
Text
Raw Permalink Normal View History

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