-
-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathDockerfile.ubuntu
51 lines (39 loc) · 1.44 KB
/
Dockerfile.ubuntu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# supported versions here: https://hub.docker.com/_/rust
ARG RUST_BUILDER_VERSION=slim-bookworm
ARG UBUNTU_RELEASE_VERSION=noble
########################
## 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 build --release --locked --bin redlib
RUN rm ./src/main.rs && rmdir ./src
# copy the source and build the redlib binary
COPY . ./
RUN cargo build --release --locked --bin redlib
RUN echo "finished building redlib!"
########################
## release image
########################
FROM ubuntu:${UBUNTU_RELEASE_VERSION} AS release
# Install ca-certificates
RUN apt-get update && apt-get install -y ca-certificates
# Import redlib binary from builder
COPY --from=builder /redlib/target/release/redlib /usr/local/bin/redlib
# Add non-root user for running redlib
RUN useradd \
--no-create-home \
--password "!" \
--comment "user for running redlib" \
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
LABEL org.opencontainers.image.authors="sigaloid"
CMD ["redlib"]