81 lines
3.4 KiB
Docker
81 lines
3.4 KiB
Docker
# Build the customized Plainleaf client and Rust server for an amd64 NAS. Build
|
|
# stages run on the builder's native architecture; only the Rust output and
|
|
# final image target amd64. This keeps Apple Silicon cross-builds practical.
|
|
# Docker Hub is not directly reachable from the NAS network, so the defaults
|
|
# use a reachable mirror. Digests match the upstream Docker Hub manifests and
|
|
# keep builds reproducible; each image can still be overridden with --build-arg.
|
|
ARG NODE_IMAGE=docker.m.daocloud.io/library/node:24.13.0-bookworm-slim@sha256:4660b1ca8b28d6d1906fd644abe34b2ed81d15434d26d845ef0aced307cf4b6f
|
|
ARG RUST_IMAGE=docker.m.daocloud.io/library/rust:bookworm@sha256:0e2bcaef56d041a486784e54104a81aebe0da44bd03019bd70bc0401e42e4a97
|
|
ARG DEBIAN_IMAGE=docker.m.daocloud.io/library/debian:bookworm-slim@sha256:abd67ffcfa541b485a3dff59865ab629aa048a6c613e639d36e7456b0b229241
|
|
|
|
FROM --platform=$BUILDPLATFORM ${NODE_IMAGE} AS client-builder
|
|
|
|
# The build script calls `git describe` and falls back to GITHUB_SHA when it
|
|
# exits non-zero. A tiny stub avoids installing Git into this disposable stage.
|
|
RUN printf '#!/bin/sh\nexit 1\n' > /usr/local/bin/git \
|
|
&& chmod +x /usr/local/bin/git
|
|
|
|
WORKDIR /src
|
|
COPY package.json package-lock.json ./
|
|
RUN npm ci
|
|
|
|
COPY . .
|
|
|
|
ARG GITHUB_SHA=unknown
|
|
RUN npm run build
|
|
|
|
FROM --platform=$BUILDPLATFORM ${RUST_IMAGE} AS server-builder
|
|
|
|
ENV RUSTUP_DIST_SERVER=https://rsproxy.cn \
|
|
RUSTUP_UPDATE_ROOT=https://rsproxy.cn/rustup
|
|
|
|
RUN sed -i \
|
|
-e 's|http://deb.debian.org/debian|http://mirrors.aliyun.com/debian|g' \
|
|
-e 's|http://deb.debian.org/debian-security|http://mirrors.aliyun.com/debian-security|g' \
|
|
/etc/apt/sources.list.d/debian.sources \
|
|
&& apt-get update \
|
|
&& apt-get install -y --no-install-recommends \
|
|
gcc-x86-64-linux-gnu libc6-dev-amd64-cross \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /src
|
|
COPY rust-toolchain.toml ./
|
|
RUN rustup target add x86_64-unknown-linux-gnu
|
|
|
|
COPY . .
|
|
COPY --from=client-builder /src/client_bundle /src/client_bundle
|
|
COPY --from=client-builder /src/version.json /src/version.json
|
|
|
|
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc \
|
|
CC_x86_64_unknown_linux_gnu=x86_64-linux-gnu-gcc
|
|
|
|
RUN printf '[source.crates-io]\nreplace-with = "rsproxy"\n\n[source.rsproxy]\nregistry = "sparse+https://rsproxy.cn/index/"\n' \
|
|
> /usr/local/cargo/config.toml
|
|
|
|
RUN --mount=type=cache,id=plainleaf-cargo-registry,target=/usr/local/cargo/registry \
|
|
--mount=type=cache,id=plainleaf-cargo-git,target=/usr/local/cargo/git \
|
|
--mount=type=cache,id=plainleaf-cargo-target,target=/src/target \
|
|
cargo build --locked --release -p silverbullet --target x86_64-unknown-linux-gnu \
|
|
&& x86_64-linux-gnu-strip target/x86_64-unknown-linux-gnu/release/silverbullet \
|
|
&& cp target/x86_64-unknown-linux-gnu/release/silverbullet /plainleaf
|
|
|
|
FROM ${DEBIAN_IMAGE}
|
|
|
|
ENV SB_HOSTNAME=0.0.0.0 \
|
|
SB_FOLDER=/space \
|
|
SB_PORT=3000 \
|
|
SB_SHELL_BACKEND=off
|
|
|
|
RUN apt-get update \
|
|
&& apt-get install -y --no-install-recommends curl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
COPY --from=server-builder /plainleaf /usr/local/bin/plainleaf
|
|
COPY --from=server-builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
|
|
|
EXPOSE 3000
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=5 \
|
|
CMD curl --fail --silent --show-error "http://127.0.0.1:${SB_PORT}/.instance" >/dev/null || exit 1
|
|
|
|
ENTRYPOINT ["/usr/local/bin/plainleaf"]
|