2023-03-25 21:38:16 +01:00
|
|
|
FROM rust:slim AS chef
|
|
|
|
RUN cargo install cargo-chef
|
2023-03-26 12:01:59 +02:00
|
|
|
WORKDIR /app
|
2023-03-25 21:38:16 +01:00
|
|
|
|
|
|
|
####################################################################################################
|
|
|
|
## Planner
|
|
|
|
####################################################################################################
|
|
|
|
FROM chef AS planner
|
2023-03-26 12:01:59 +02:00
|
|
|
WORKDIR /app
|
|
|
|
COPY ./Cargo.lock ./
|
|
|
|
COPY ./Cargo.toml ./
|
|
|
|
COPY ./src ./src
|
2023-03-25 21:38:16 +01:00
|
|
|
RUN cargo chef prepare --recipe-path recipe.json
|
|
|
|
|
|
|
|
####################################################################################################
|
|
|
|
## Builder
|
|
|
|
####################################################################################################
|
|
|
|
FROM chef AS builder
|
|
|
|
|
|
|
|
RUN rustup target add x86_64-unknown-linux-musl
|
|
|
|
RUN apt update && apt install -y musl-tools musl-dev
|
|
|
|
RUN update-ca-certificates
|
|
|
|
|
|
|
|
# Create appuser
|
|
|
|
ENV USER=website
|
|
|
|
ENV UID=10001
|
|
|
|
|
|
|
|
RUN adduser \
|
|
|
|
--disabled-password \
|
|
|
|
--gecos "" \
|
|
|
|
--home "/nonexistent" \
|
|
|
|
--shell "/sbin/nologin" \
|
|
|
|
--no-create-home \
|
|
|
|
--uid "${UID}" \
|
|
|
|
"${USER}"
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
2023-03-26 12:01:59 +02:00
|
|
|
COPY --from=planner /app/recipe.json ./
|
|
|
|
|
2023-03-26 00:30:21 +01:00
|
|
|
RUN cargo chef cook --target x86_64-unknown-linux-musl --release --recipe-path recipe.json
|
2023-03-25 21:38:16 +01:00
|
|
|
|
2023-03-26 12:01:59 +02:00
|
|
|
COPY ./Cargo.lock ./
|
|
|
|
COPY ./Cargo.toml ./
|
|
|
|
|
|
|
|
COPY ./src ./src
|
2023-03-25 21:38:16 +01:00
|
|
|
|
|
|
|
RUN cargo build --target x86_64-unknown-linux-musl --release
|
|
|
|
|
|
|
|
####################################################################################################
|
|
|
|
## Final image
|
|
|
|
####################################################################################################
|
|
|
|
FROM scratch
|
|
|
|
|
|
|
|
# Import from builder.
|
|
|
|
COPY --from=builder /etc/passwd /etc/passwd
|
|
|
|
COPY --from=builder /etc/group /etc/group
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
# Copy our build
|
|
|
|
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/website ./
|
2023-03-26 12:01:59 +02:00
|
|
|
COPY ./static ./static
|
|
|
|
COPY ./templates ./templates
|
|
|
|
COPY ./posts ./posts
|
2023-03-25 21:38:16 +01:00
|
|
|
|
|
|
|
EXPOSE 8180
|
|
|
|
|
|
|
|
# Use an unprivileged user.
|
|
|
|
USER website:website
|
|
|
|
|
2023-06-18 11:44:53 +02:00
|
|
|
ENV RUST_LOG="debug"
|
|
|
|
|
2023-03-25 21:38:16 +01:00
|
|
|
CMD ["./website"]
|