From 8c14087a2c23da766160f3a1c987d275a8cc0b70 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Mon, 18 Dec 2023 17:18:58 +0100 Subject: [PATCH] Fixes #603 by not recreating existing unix groups and users --- Dockerfile | 4 ++-- docker-entrypoint.sh | 10 ++++++---- server/db_backend.ts | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2ac4c88..9784d88 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM lukechannings/deno:v1.38.5 +FROM lukechannings/deno:v1.39.0 # The volume that will keep the space data # Either create a volume: @@ -17,7 +17,7 @@ ENV TINI_VERSION v0.19.0 ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-${TARGETARCH} /tini # Make sure the deno user has access to the space volume -RUN mkdir -p -m 770 /space \ +RUN mkdir -p -m 777 /space \ && chmod +x /tini \ && apt update \ && apt install -y git ssh-client \ diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 37595b7..c52996a 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -16,12 +16,14 @@ if [ "$PUID" == "0" ] || [ "$UID" != "0" ]; then deno run -A --unstable /silverbullet.js $@ else # Create silverbullet user and group ad-hoc mapped to PUID and PGID - getent group silverbullet &> /dev/null || groupadd -g $PGID silverbullet - id -u silverbullet &> /dev/null || useradd -M -u $PUID -g $PGID silverbullet + getent group $PGID &> /dev/null || groupadd -g $PGID silverbullet + getent passwd $PUID &> /dev/null || useradd -M -u $PUID -g $PGID silverbullet # And make sure /deno-dir (Deno cache) is accessible chown -R $PUID:$PGID /deno-dir - # And run via su as the newly mapped 'silverbullet' user args="$@" - su silverbullet -s /bin/bash -c "deno run -A --unstable /silverbullet.js $args" + # And run via su as requested PUID, usually this will be 'silverbullet' but if a user with this idea already exists, we will use that + USERNAME=$(getent passwd $PUID | cut -d ":" -f 1) + echo "Running SilverBullet as $USERNAME (configured as PUID $PUID and PGID $PGID)" + su $USERNAME -s /bin/bash -c "deno run -A --unstable /silverbullet.js $args" fi diff --git a/server/db_backend.ts b/server/db_backend.ts index d98e2c2..d1d0130 100644 --- a/server/db_backend.ts +++ b/server/db_backend.ts @@ -28,7 +28,7 @@ export async function determineDatabaseBackend( } const denoDb = await Deno.openKv(dbFile); console.info( - `Using DenoKV as a database backend (${dbFile || "cloud"}.`, + `Using DenoKV as a database backend (${dbFile || "cloud"}).`, ); return new DenoKvPrimitives(denoDb); }