Files
inbuxa-server/Dockerfile.fdb
jcoffey-dev 57eee17522
ci / fork-checks (pull_request) Skipped
ci / build (pull_request) Skipped
github/ci (branch) GitHub Actions
ci / github (pull_request) Successful in 13m7s
Image runs with every capability dropped; INBUXA_LISTENER_PORTS
The binary carried cap_net_bind_service as a file capability, so exec
failed outright wherever the capability isn't in the bounding set, as in a
Kubernetes pod with every capability dropped. The images no longer set it
(or install libcap to set it).

Docker users are unaffected: Docker sets ip_unprivileged_port_start=0 in a
container's own network namespace, so the server still listens on 25, 443,
465 and 993 unprivileged. Under podman or --network host, grant the sysctl
or CAP_NET_BIND_SERVICE.

INBUXA_LISTENER_PORTS moves the default listeners a new store gets, or
leaves some out (smtp=2525,pop3s=off,...). It is checked on every start
and a mistake stops the server, but only used when the store has no
listeners yet; after that the registry holds them.

A bind refused on a port below 1024 now says what would allow it.

Closes #424
2026-11-18 07:08:14 -07:00

84 lines
3.6 KiB
Docker

# syntax=docker/dockerfile:1
FROM debian:trixie-slim AS chef
ARG TARGETARCH
ARG FDB_VERSION_RANGE="7.4"
RUN apt-get update && \
export DEBIAN_FRONTEND=noninteractive && \
apt-get install -yq --no-install-recommends \
build-essential \
ca-certificates \
cmake \
clang \
curl \
jq \
protobuf-compiler
ENV RUSTUP_HOME=/opt/rust/rustup \
PATH=/home/root/.cargo/bin:/opt/rust/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUN curl https://sh.rustup.rs -sSf | \
env CARGO_HOME=/opt/rust/cargo \
sh -s -- -y --default-toolchain stable --profile minimal --no-modify-path && \
env CARGO_HOME=/opt/rust/cargo \
rustup component add rustfmt
RUN \
ARCH="${TARGETARCH:-$(dpkg --print-architecture)}" && \
case "$ARCH" in \
amd64) FDB_ARCH=amd64 ;; \
arm64) FDB_ARCH=aarch64 ;; \
*) echo "Unsupported architecture: $ARCH" >&2; exit 1 ;; \
esac && \
curl --retry 5 -fLso fdb-client.deb "$(curl --retry 5 -fLs 'https://api.github.com/repos/apple/foundationdb/releases?per_page=100' | jq --arg FDB_ARCH "$FDB_ARCH" --arg RANGE "${FDB_VERSION_RANGE}" -r '[.[] | select(.tag_name | startswith($RANGE + "."))] | sort_by(.tag_name | split(".") | map(tonumber)) | reverse | .[0].assets[] | select(.name | test("foundationdb-clients.*" + $FDB_ARCH + ".deb$")) | .browser_download_url')" && \
mkdir -p /fdb && \
dpkg -x fdb-client.deb /fdb && \
mv /fdb/usr/include/foundationdb /usr/include && \
mv /fdb/usr/lib/libfdb_c.so /usr/lib && \
rm -rf fdb-client.deb /fdb
RUN env CARGO_HOME=/opt/rust/cargo cargo install cargo-chef && \
rm -rf /opt/rust/cargo/registry/
WORKDIR /app
FROM chef AS planner
COPY Cargo.toml .
COPY Cargo.lock .
COPY crates/ crates/
COPY resources/ resources/
COPY tests/ tests/
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
COPY Cargo.toml .
COPY Cargo.lock .
COPY crates/ crates/
COPY resources/ resources/
COPY tests/ tests/
RUN cargo build -p inbuxa --no-default-features --features "foundationdb s3 redis azure nats" --release
FROM debian:trixie-slim AS runtime
COPY --from=builder --chmod=0755 /app/target/release/inbuxa /usr/local/bin/inbuxa
COPY --from=builder /usr/lib/libfdb_c.so /usr/lib/libfdb_c.so
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get install -yq --no-install-recommends ca-certificates curl && \
rm -rf /var/lib/apt/lists/* && \
groupadd -r -g 2000 inbuxa && \
useradd -r -u 2000 -g 2000 -s /usr/sbin/nologin -M inbuxa && \
mkdir -p /etc/inbuxa /var/lib/inbuxa && \
chown inbuxa:inbuxa /etc/inbuxa /var/lib/inbuxa
# inbuxa: K-S1: no file capability on the binary. One would make exec fail
# where every capability is dropped (Kubernetes' restricted pods). Docker
# lets an unprivileged user bind ports below 1024 on its own networks
# (net.ipv4.ip_unprivileged_port_start=0); elsewhere, grant that sysctl or
# CAP_NET_BIND_SERVICE, or move the listeners with INBUXA_LISTENER_PORTS.
USER inbuxa
WORKDIR /var/lib/inbuxa
VOLUME ["/etc/inbuxa", "/var/lib/inbuxa"]
EXPOSE 443 25 110 587 465 143 993 995 4190 8080
ENV INBUXA_HEALTHCHECK_URL=https://127.0.0.1:443/healthz/live
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
CMD curl -fsSk -H "X-Forwarded-For: 127.0.0.1" "$INBUXA_HEALTHCHECK_URL" || curl -fsS -H "X-Forwarded-For: 127.0.0.1" http://127.0.0.1:8080/healthz/live || exit 1
ENTRYPOINT ["/usr/local/bin/inbuxa"]
CMD ["--config", "/etc/inbuxa/config.json"]