Containerfile
⎇
Raw
1ARG RUST_VERSION=1.98
2ARG BUN_VERSION=1.4.2
3ARG TRUNK_VERSION=0.21.14
4ARG ALPINE_VERSION=3.24
5
6# ── build ────────────────────────────────────────────────────────────────────
7FROM rust:${RUST_VERSION}-alpine${ALPINE_VERSION} AS build
8
9# re-declare the build-args: args set before FROM do not carry into stages
10ARG BUN_VERSION
11ARG TRUNK_VERSION
12
13# binaryen so trunk uses the system wasm-opt instead of downloading a glibc binary that cannot run on musl
14# openssl-dev + openssl-libs-static for webauthn-rs, whose core crate links
15# OpenSSL. The binary is static, so nothing is needed in the runtime image.
16RUN apk add --no-cache curl ca-certificates musl-dev binaryen just \
17 openssl-dev openssl-libs-static pkgconfig \
18 && rustup target add wasm32-unknown-unknown
19
20# bun
21COPY --from=oven/bun:${BUN_VERSION}-alpine /usr/local/bin/bun /usr/local/bin/bun
22
23# trunk
24RUN set -eux; \
25 url=https://github.com/trunk-rs/trunk/releases/download/v${TRUNK_VERSION}/trunk-x86_64-unknown-linux-musl.tar.gz; \
26 curl -fsSL -o /tmp/trunk.tar.gz "${url}"; \
27 curl -fsSL "${url}.sha256" | awk '{print $1 " /tmp/trunk.tar.gz"}' | sha256sum -c -; \
28 tar xzf /tmp/trunk.tar.gz -C /usr/local/bin; \
29 rm -f /tmp/trunk.tar.gz
30
31WORKDIR /src
32COPY . /src
33
34# build
35RUN --mount=type=cache,target=/usr/local/cargo/registry \
36 --mount=type=cache,target=/src/target \
37 just build \
38 && cp target/release/filebrowser-ng /filebrowser-ng
39
40# ── prebuilt ─────────────────────────────────────────────────────────────────
41# CI has the binary already. It puts it at ci-bin/filebrowser-ng and selects
42# this stage with --build-arg BIN_STAGE=prebuilt. BuildKit and buildah do not
43# build a stage nobody references, so a normal build needs no ci-bin/.
44FROM scratch AS prebuilt
45COPY ci-bin/filebrowser-ng /filebrowser-ng
46
47# ── runtime ──────────────────────────────────────────────────────────────────
48FROM alpine:${ALPINE_VERSION}
49
50ARG BIN_STAGE=build
51
52# ffmpeg is only for video thumbnails, and it is most of the image: it pulls
53# ~120 MiB of codec libraries against 8 MiB for the rest
54RUN apk add --no-cache ca-certificates ffmpeg \
55 && mkdir -p /data /var/lib/filebrowser /var/cache/filebrowser
56
57COPY --from=${BIN_STAGE} /filebrowser-ng /usr/local/bin/filebrowser-ng
58
59EXPOSE 8080
60VOLUME ["/data", "/var/lib/filebrowser"]
61
62HEALTHCHECK --interval=30s --start-period=10s --timeout=5s --retries=3 \
63 CMD wget -qO /dev/null http://127.0.0.1:8080/ || exit 1
64
65ENTRYPOINT ["/usr/local/bin/filebrowser-ng"]
66CMD ["--root", "/data", "--db", "/var/lib/filebrowser/db.sqlite", "--bind", "0.0.0.0"]
67