|
| 1 | +# Development Dockerfile - builds debug version for faster iteration |
| 2 | +# supported versions here: https://hub.docker.com/_/rust |
| 3 | +ARG ALPINE_VERSION=3.20 |
| 4 | + |
| 5 | +######################## |
| 6 | +## builder image |
| 7 | +######################## |
| 8 | +FROM rust:alpine${ALPINE_VERSION} AS builder |
| 9 | + |
| 10 | +RUN apk add --no-cache musl-dev |
| 11 | + |
| 12 | +WORKDIR /redlib |
| 13 | + |
| 14 | +# download (most) dependencies in their own layer |
| 15 | +COPY Cargo.lock Cargo.toml ./ |
| 16 | +RUN mkdir src && echo "fn main() { panic!(\"why am i running?\") }" > src/main.rs |
| 17 | +RUN cargo build --locked --bin redlib |
| 18 | +RUN rm ./src/main.rs && rmdir ./src |
| 19 | + |
| 20 | +# copy the source and build the redlib binary |
| 21 | +COPY . ./ |
| 22 | +RUN cargo build --locked --bin redlib |
| 23 | +RUN echo "finished building redlib!" |
| 24 | + |
| 25 | +######################## |
| 26 | +## runtime image |
| 27 | +######################## |
| 28 | +FROM alpine:${ALPINE_VERSION} AS runtime |
| 29 | + |
| 30 | +# Import redlib binary from builder (debug build) |
| 31 | +COPY --from=builder /redlib/target/debug/redlib /usr/local/bin/redlib |
| 32 | + |
| 33 | +# Add non-root user for running redlib |
| 34 | +RUN adduser --home /nonexistent --no-create-home --disabled-password redlib |
| 35 | +USER redlib |
| 36 | + |
| 37 | +# Document that we intend to expose port 8080 to whoever runs the container |
| 38 | +EXPOSE 8080 |
| 39 | + |
| 40 | +# Run a healthcheck every minute to make sure redlib is functional |
| 41 | +HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider -q http://localhost:8080/settings || exit 1 |
| 42 | + |
| 43 | +# Add container metadata |
| 44 | +LABEL org.opencontainers.image.authors="sigaloid" |
| 45 | + |
| 46 | +CMD ["redlib"] |
| 47 | + |
0 commit comments