|
| 1 | +# supported versions here: https://github.com/rust-lang/docker-rust/tree/9f287282d513a84cb7c7f38f197838f15d37b6a9/1.81.0 |
| 2 | +ARG RUST_BUILDER_VERSION=bookworm |
| 3 | +ARG UBUNTU_RELEASE_VERSION=jammy |
| 4 | + |
| 5 | +######################## |
| 6 | +## builder image |
| 7 | +######################## |
| 8 | +FROM rust:${RUST_BUILDER_VERSION} AS builder |
| 9 | + |
| 10 | +WORKDIR /redlib |
| 11 | + |
| 12 | +# download (most) dependencies in their own layer |
| 13 | +COPY Cargo.lock Cargo.toml ./ |
| 14 | +RUN mkdir src && echo "fn main() { panic!(\"why am i running?\") }" > src/main.rs |
| 15 | +RUN cargo fetch |
| 16 | +RUN rm ./src/main.rs && rmdir ./src |
| 17 | + |
| 18 | +# copy the source and build the redlib binary |
| 19 | +COPY . ./ |
| 20 | +RUN cargo install --path . |
| 21 | +RUN echo "finished building redlib!" |
| 22 | + |
| 23 | +######################## |
| 24 | +## release image |
| 25 | +######################## |
| 26 | +FROM ubuntu:${UBUNTU_RELEASE_VERSION} AS release |
| 27 | + |
| 28 | +# Import ca-certificates from builder |
| 29 | +COPY --from=builder /usr/share/ca-certificates /usr/share/ca-certificates |
| 30 | +COPY --from=builder /etc/ssl/certs /etc/ssl/certs |
| 31 | + |
| 32 | +# Import redlib binary from builder |
| 33 | +COPY --from=builder /usr/local/cargo/bin/redlib /usr/local/bin/redlib |
| 34 | + |
| 35 | +# Add non-root user for running redlib |
| 36 | +RUN adduser --no-create-home --disabled-password redlib |
| 37 | +USER redlib |
| 38 | + |
| 39 | +# Document that we intend to expose port 8080 to whoever runs the container |
| 40 | +EXPOSE 8080 |
| 41 | + |
| 42 | +# Run a healthcheck every minute to make sure redlib is functional |
| 43 | +HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider --q http://localhost:8080/settings || exit 1 |
| 44 | + |
| 45 | +# Add container metadata |
| 46 | +MAINTAINER sigaloid |
| 47 | + |
| 48 | +CMD ["redlib"] |
0 commit comments