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