Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
# supported versions here: https://hub.docker.com/_/rust
ARG RUST_BUILDER_VERSION=slim-bookworm
ARG ALPINE_VERSION=3.23
# supported versions here:
# - https://hub.docker.com/_/rust
# - https://hub.docker.com/_/alpine
ARG ALPINE_VERSION=3.24

########################
## builder image
########################
FROM ghcr.io/rust-cross/rust-musl-cross:x86_64-musl AS builder
FROM rust:alpine${ALPINE_VERSION} AS builder

RUN apt-get update \
&& apt-get -y install git cmake perl pkg-config libclang-dev \
&& rm -rf /var/lib/apt/lists/*

RUN rustup target add x86_64-unknown-linux-musl
RUN apk add --update-cache --no-cache gcc g++ clang-dev git cmake make perl pkgconf nasm \
&& rm -rf /var/cache/apk/*

WORKDIR /redlib

# display backtrace on build error
ENV RUST_BACKTRACE=full

# enable dynamic linking, older rust disabled this for musl target by default
ENV RUSTFLAGS="-C target-feature=-crt-static -C link-self-contained=no"

# 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 --target x86_64-unknown-linux-musl
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 --target x86_64-unknown-linux-musl
RUN cargo build --release --locked --bin redlib
RUN echo "finished building redlib!"

########################
## release image
########################
FROM alpine:${ALPINE_VERSION} AS release

# without gcc compat layer, redlib will crash with undefined symbols
RUN apk add --update-cache --no-cache libgcc \
&& rm -rf /var/cache/apk/*

# Import redlib binary from builder
COPY --from=builder /redlib/target/x86_64-unknown-linux-musl/release/redlib /usr/local/bin/redlib
COPY --from=builder /redlib/target/release/redlib /usr/local/bin/redlib

# Add non-root user for running redlib
RUN adduser --home /nonexistent --no-create-home --disabled-password redlib
Expand Down
56 changes: 56 additions & 0 deletions Dockerfile.debian-slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# supported versions here:
# - https://hub.docker.com/_/rust
# - https://hub.docker.com/_/debian
ARG DEBIAN_VERSION_CODENAME=trixie

########################
## builder image
########################
FROM rust:slim-${DEBIAN_VERSION_CODENAME} AS builder

RUN apt-get update \
&& apt-get install -y --no-install-recommends --no-install-suggests gcc g++ libclang-dev git cmake make perl pkg-config nasm \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /redlib

# display backtrace on build error
ENV RUST_BACKTRACE=full

# 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 debian:${DEBIAN_VERSION_CODENAME}-slim AS release

# 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"]
54 changes: 54 additions & 0 deletions Dockerfile.distroless
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# supported versions here: https://github.com/googlecontainertools/distroless
ARG DEBIAN_VERSION_NUMBER=13
# supported builder cpu architectures here: https://github.com/rust-cross/rust-musl-cross
ARG RUST_MUSL_CROSS_TAG=x86_64-musl

########################
## builder image
########################
FROM ghcr.io/rust-cross/rust-musl-cross:${RUST_MUSL_CROSS_TAG} AS builder

ARG COMPILE_TARGET=x86_64-unknown-linux-musl

RUN apt-get update \
&& apt-get -y install git cmake perl pkg-config libclang-dev \
&& rm -rf /var/lib/apt/lists/*

RUN rustup target add ${COMPILE_TARGET}

WORKDIR /redlib

# display backtrace on build error
ENV RUST_BACKTRACE=full

# 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 --target ${COMPILE_TARGET}
RUN rm ./src/main.rs && rmdir ./src

# copy the source and build the redlib binary
COPY . ./
RUN cargo build --release --locked --bin redlib --target ${COMPILE_TARGET}
RUN echo "finished building redlib!"

########################
## release image
########################
FROM gcr.io/distroless/static-debian${DEBIAN_VERSION_NUMBER}:nonroot AS release

ARG COMPILE_TARGET=x86_64-unknown-linux-musl

# Import redlib binary from builder
COPY --from=builder --chown=65532:65532 /redlib/target/${COMPILE_TARGET}/release/redlib /usr/local/bin/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"]
7 changes: 5 additions & 2 deletions Dockerfile.ubuntu
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# supported versions here: https://hub.docker.com/_/rust
ARG RUST_BUILDER_VERSION=slim-bookworm
ARG UBUNTU_RELEASE_VERSION=noble
ARG RUST_BUILDER_VERSION=slim-trixie
ARG UBUNTU_RELEASE_VERSION=resolute

########################
## builder image
Expand All @@ -13,6 +13,9 @@ RUN apt-get update \

WORKDIR /redlib

# display backtrace on build error
ENV RUST_BACKTRACE=full

# 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
Expand Down