Skip to content

Commit 488e545

Browse files
committed
add new dockerfiles
1 parent 793047f commit 488e545

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

Dockerfile.alpine

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

Dockerfile.ubuntu

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

Comments
 (0)