Fix docwell-server data dir ownership on start
The server runs as docwell (uid 10001), but a host bind mount for SERVER_DATA, or a volume created by an older image, arrives owned by root, so the search index failed with "mkdir /data/search.bleve: permission denied". The image now starts as root through a small entrypoint that chowns DOCWELL_DATA_DIR to docwell when needed, then runs docwell-server as docwell via su-exec. A container already started with a non-root user: skips the fix and runs the server directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ef2c81d062
commit
24a2d275a0
2 files changed
+25
-3
No files matched your search
+5
-3
@@ -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"]
|
||||
@@ -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 "$@"
|
||||
Reference in new issue
Block a user