diff --git a/Server/Dockerfile b/Server/Dockerfile index 661f60d..3b0a319 100644 --- a/Server/Dockerfile +++ b/Server/Dockerfile @@ -31,13 +31,15 @@ RUN CGO_ENABLED=0 GOWORK=off GOOS=$TARGETOS GOARCH=$TARGETARCH go build -trimpat -o /out/docwell-server ./cmd/docwell-server FROM alpine:3.22 -RUN apk add --no-cache ca-certificates && adduser -D -u 10001 docwell && mkdir /data && chown docwell /data +RUN apk add --no-cache ca-certificates su-exec && adduser -D -u 10001 docwell && mkdir /data && chown docwell /data COPY --from=build /out/docwell-server /usr/local/bin/docwell-server -USER docwell +# Starts as root, fixes the ownership of /data (a bind mount arrives owned by +# root), then runs the server as docwell. See entrypoint.sh. +COPY --chmod=0755 Server/entrypoint.sh /usr/local/bin/docwell-entrypoint # The search index; it is rebuilt from PocketBase when missing. ENV DOCWELL_DATA_DIR=/data VOLUME /data EXPOSE 8080 HEALTHCHECK --interval=10s --timeout=3s --retries=5 \ CMD wget -qO- http://127.0.0.1:8080/healthz >/dev/null || exit 1 -ENTRYPOINT ["docwell-server"] +ENTRYPOINT ["docwell-entrypoint"] diff --git a/Server/entrypoint.sh b/Server/entrypoint.sh new file mode 100644 index 0000000..8d01d83 --- /dev/null +++ b/Server/entrypoint.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# docwell-server entrypoint. Started as root only to make the data directory +# writable for the docwell user: a host bind mount, or a volume created by an +# older image, arrives owned by root, and the search index could not be +# written. Then it drops to docwell for good. +set -eu + +DATA_DIR="${DOCWELL_DATA_DIR:-/data}" + +if [ "$(id -u)" = "0" ]; then + mkdir -p "$DATA_DIR" + if [ "$(stat -c %u "$DATA_DIR")" != "10001" ]; then + echo "Fixing $DATA_DIR ownership for docwell (uid=10001)" + chown -R docwell:docwell "$DATA_DIR" + fi + exec su-exec docwell docwell-server "$@" +fi + +# Already unprivileged (e.g. `user:` set in compose): run as is. +exec docwell-server "$@"