2021-04-10 10:50:43 +12:00
|
|
|
####################################################################################################
|
|
|
|
## Builder
|
|
|
|
####################################################################################################
|
2021-04-10 13:27:12 +12:00
|
|
|
FROM rust:latest AS builder
|
2021-04-10 10:50:43 +12:00
|
|
|
|
2021-04-10 13:27:12 +12:00
|
|
|
RUN rustup target add aarch64-unknown-linux-musl
|
|
|
|
RUN apt update && apt install -y musl-tools musl-dev
|
|
|
|
RUN update-ca-certificates
|
|
|
|
|
|
|
|
RUN adduser --home /nonexistent --no-create-home --disabled-password libreddit
|
2021-04-10 10:50:43 +12:00
|
|
|
|
|
|
|
WORKDIR /usr/src/libreddit
|
|
|
|
|
|
|
|
COPY . .
|
|
|
|
|
2021-04-10 13:27:12 +12:00
|
|
|
RUN cargo build --target aarch64-unknown-linux-musl --release
|
2021-04-10 10:50:43 +12:00
|
|
|
|
|
|
|
####################################################################################################
|
|
|
|
## Final image
|
|
|
|
####################################################################################################
|
2021-04-10 13:27:12 +12:00
|
|
|
FROM scratch
|
2021-04-10 10:50:43 +12:00
|
|
|
|
2021-04-10 13:27:12 +12:00
|
|
|
# Import user information from builder.
|
|
|
|
COPY --from=builder /etc/passwd /etc/passwd
|
|
|
|
COPY --from=builder /etc/group /etc/group
|
|
|
|
|
|
|
|
# Import ca-certificates from builder
|
|
|
|
COPY --from=builder /usr/share/ca-certificates /usr/share/ca-certificates
|
|
|
|
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
|
2021-04-10 10:50:43 +12:00
|
|
|
|
|
|
|
# Copy our build
|
2021-04-10 13:27:12 +12:00
|
|
|
COPY --from=builder /usr/src/libreddit/target/aarch64-unknown-linux-musl/release/libreddit /usr/local/bin/libreddit
|
2021-04-10 10:50:43 +12:00
|
|
|
|
|
|
|
# Use an unprivileged user.
|
|
|
|
USER libreddit
|
|
|
|
|
|
|
|
# Tell Docker to expose port 8080
|
|
|
|
EXPOSE 8080
|
|
|
|
|
|
|
|
# Run a healthcheck every minute to make sure Libreddit is functional
|
|
|
|
HEALTHCHECK --interval=1m --timeout=3s CMD curl -f http://localhost:8080/settings || exit 1
|
|
|
|
|
|
|
|
CMD ["libreddit"]
|