From 93ed1c6f0cbdb4c945ba219eade681227ce55fab Mon Sep 17 00:00:00 2001 From: spikecodes <19519553+spikecodes@users.noreply.github.com> Date: Fri, 9 Apr 2021 22:38:13 -0700 Subject: [PATCH] Fix Dockerfile healthchecks --- Dockerfile | 21 +++++++-------------- Dockerfile.arm64 | 4 +--- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index a308152..0820de4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,11 @@ #################################################################################################### ## Builder #################################################################################################### -FROM rust:latest AS builder +FROM rust:alpine 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 +RUN apk add --no-cache musl-dev -RUN adduser --home /nonexistent --no-create-home --disabled-password libreddit - -WORKDIR /usr/src/libreddit +WORKDIR /libreddit COPY . . @@ -18,26 +14,23 @@ RUN cargo build --target x86_64-unknown-linux-musl --release #################################################################################################### ## Final image #################################################################################################### -FROM scratch - -# Import user information from builder. -COPY --from=builder /etc/passwd /etc/passwd -COPY --from=builder /etc/group /etc/group +FROM alpine:latest # 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 # Copy our build -COPY --from=builder /usr/src/libreddit/target/x86_64-unknown-linux-musl/release/libreddit /usr/local/bin/libreddit +COPY --from=builder /libreddit/target/x86_64-unknown-linux-musl/release/libreddit /usr/local/bin/libreddit # Use an unprivileged user. +RUN adduser --home /nonexistent --no-create-home --disabled-password libreddit 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 +HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider --q http://localhost:8080/settings || exit 1 CMD ["libreddit"] \ No newline at end of file diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 index c3afd88..d01de0b 100644 --- a/Dockerfile.arm64 +++ b/Dockerfile.arm64 @@ -16,8 +16,6 @@ RUN cargo install --path . #################################################################################################### FROM alpine:latest -RUN apk add --no-cache curl - # Copy our build COPY --from=builder /usr/local/cargo/bin/libreddit /usr/local/bin/libreddit @@ -29,6 +27,6 @@ USER libreddit 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 +HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider --q http://localhost:8080/settings || exit 1 CMD ["libreddit"] \ No newline at end of file