-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3625fdf
commit 77655e0
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |