Containerfile
| 1 | ARG RUST_VERSION=1.98 |
| 2 | ARG BUN_VERSION=1.4.2 |
| 3 | ARG TRUNK_VERSION=0.21.14 |
| 4 | ARG ALPINE_VERSION=3.24 |
| 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 | # 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. |
| 16 | RUN 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 |
| 21 | COPY --from=oven/bun:${BUN_VERSION}-alpine /usr/local/bin/bun /usr/local/bin/bun |
| 22 | |
| 23 | # trunk |
| 24 | RUN 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 | |
| 31 | WORKDIR /src |
| 32 | COPY . /src |
| 33 | |
| 34 | # build |
| 35 | RUN --mount=type=cache,target=/usr/local/cargo/registry \ |
| 36 | --mount=type=cache,target=/src/target \ |
| 37 | just build \ |
| 38 | && cp target/release/dovenest /dovenest |
| 39 | |
| 40 | # ── prebuilt ───────────────────────────────────────────────────────────────── |
| 41 | # CI has the binary already. It puts it at ci-bin/dovenest 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/. |
| 44 | FROM scratch AS prebuilt |
| 45 | COPY ci-bin/dovenest /dovenest |
| 46 | |
| 47 | # ── runtime ────────────────────────────────────────────────────────────────── |
| 48 | FROM alpine:${ALPINE_VERSION} |
| 49 | |
| 50 | ARG 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 |
| 54 | RUN apk add --no-cache ca-certificates ffmpeg \ |
| 55 | && mkdir -p /data /var/lib/dovenest /var/cache/dovenest |
| 56 | |
| 57 | COPY --from=${BIN_STAGE} /dovenest /usr/local/bin/dovenest |
| 58 | |
| 59 | EXPOSE 8080 |
| 60 | VOLUME ["/data", "/var/lib/dovenest"] |
| 61 | |
| 62 | HEALTHCHECK --interval=30s --start-period=10s --timeout=5s --retries=3 \ |
| 63 | CMD wget -qO /dev/null http://127.0.0.1:8080/ || exit 1 |
| 64 | |
| 65 | ENTRYPOINT ["/usr/local/bin/dovenest"] |
| 66 | CMD ["--root", "/data", "--db", "/var/lib/dovenest/db.sqlite", "--bind", "0.0.0.0"] |
| 67 |