From 77655e005eaa00bc1e49246af56b23ae71458fb7 Mon Sep 17 00:00:00 2001 From: Vivek Revankar Date: Tue, 17 Sep 2024 20:08:23 -0700 Subject: [PATCH] add new dockerfiles --- Dockerfile.alpine | 49 +++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile.ubuntu | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 Dockerfile.alpine create mode 100644 Dockerfile.ubuntu diff --git a/Dockerfile.alpine b/Dockerfile.alpine new file mode 100644 index 00000000..65ab6dad --- /dev/null +++ b/Dockerfile.alpine @@ -0,0 +1,49 @@ +# supported versions here: https://github.com/rust-lang/docker-rust/tree/9f287282d513a84cb7c7f38f197838f15d37b6a9/1.81.0 +ARG ALPINE_VERSION=3.20 + +######################## +## builder image +######################## +FROM rust:alpine${ALPINE_VERSION} AS builder + +RUN apk add --no-cache musl-dev + +WORKDIR /redlib + +# download (most) dependencies in their own layer +COPY Cargo.lock Cargo.toml ./ +RUN mkdir src && echo "fn main() { panic!(\"why am i running?\") }" > src/main.rs +RUN cargo fetch +RUN rm ./src/main.rs && rmdir ./src + +# copy the source and build the redlib binary +COPY . ./ +RUN cargo install --path . +RUN echo "finished building redlib!" + +######################## +## release image +######################## +FROM alpine:${ALPINE_VERSION} as release + +# 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 + +# Import redlib binary from builder +COPY --from=builder /usr/local/cargo/bin/redlib /usr/local/bin/redlib + +# Add non-root user for running redlib +RUN adduser --home /nonexistent --no-create-home --disabled-password redlib +USER redlib + +# Document that we intend to expose port 8080 to whoever runs the container +EXPOSE 8080 + +# Run a healthcheck every minute to make sure redlib is functional +HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider --q http://localhost:8080/settings || exit 1 + +# Add container metadata +MAINTAINER sigaloid + +CMD ["redlib"] diff --git a/Dockerfile.ubuntu b/Dockerfile.ubuntu new file mode 100644 index 00000000..749e8411 --- /dev/null +++ b/Dockerfile.ubuntu @@ -0,0 +1,48 @@ +# supported versions here: https://github.com/rust-lang/docker-rust/tree/9f287282d513a84cb7c7f38f197838f15d37b6a9/1.81.0 +ARG RUST_BUILDER_VERSION=bookworm +ARG UBUNTU_RELEASE_VERSION=jammy + +######################## +## builder image +######################## +FROM rust:${RUST_BUILDER_VERSION} AS builder + +WORKDIR /redlib + +# download (most) dependencies in their own layer +COPY Cargo.lock Cargo.toml ./ +RUN mkdir src && echo "fn main() { panic!(\"why am i running?\") }" > src/main.rs +RUN cargo fetch +RUN rm ./src/main.rs && rmdir ./src + +# copy the source and build the redlib binary +COPY . ./ +RUN cargo install --path . +RUN echo "finished building redlib!" + +######################## +## release image +######################## +FROM ubuntu:${UBUNTU_RELEASE_VERSION} as release + +# 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 + +# Import redlib binary from builder +COPY --from=builder /usr/local/cargo/bin/redlib /usr/local/bin/redlib + +# Add non-root user for running redlib +RUN adduser --no-create-home --disabled-password redlib +USER redlib + +# Document that we intend to expose port 8080 to whoever runs the container +EXPOSE 8080 + +# Run a healthcheck every minute to make sure redlib is functional +HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider --q http://localhost:8080/settings || exit 1 + +# Add container metadata +MAINTAINER sigaloid + +CMD ["redlib"]