entrypoint DRY refactor and removal of user/group creation
authorAdam Dullage <redacted>
Sun, 10 Sep 2023 14:46:01 +0000 (15:46 +0100)
committerAdam Dullage <redacted>
Sun, 10 Sep 2023 14:46:01 +0000 (15:46 +0100)
entrypoint.sh

index 4fd28223a4701e6a4afdb855dff6d22fff666c80..b317c95b5b7a1c6b836a9b62e9822d947df48f7c 100644 (file)
@@ -1,51 +1,30 @@
 #!/bin/bash
 
+set -e
+
 echo "WARNING: Breaking changes introduced in version 3.x:"
 echo "  - The port flatnotes uses inside the Docker container has been changed to 8080 (previously 80)."
 echo "  - To accompany the above change, support for the PORT environment variable has been removed."
 echo "  - The note directory inside the Docker container has moved from /app/data to simply /data."
 
+flatnotes_command="python -m \
+                  uvicorn \
+                  main:app \
+                  --app-dir flatnotes \
+                  --host 0.0.0.0 \
+                  --port 8080 \
+                  --proxy-headers \
+                  --forwarded-allow-ips '*'"
+
 if [ `id -u` -eq 0 ] && [ `id -g` -eq 0 ]; then
-    set -e
-    
-    USERNAME=flatnotes
-    
-    echo Setting up user and group...
-    addgroup \
-      --gid ${PGID} \
-      ${USERNAME} \
-      || echo "Group '${PGID}' already exists."
-    
-    adduser \
-      --disabled-password \
-      --gecos "" \
-      --uid ${PUID} \
-      --gid ${PGID} \
-      ${USERNAME} \
-      || echo "User '${PUID}' already exists."
-    
     echo Setting file permissions...
     chown -R ${PUID}:${PGID} ${FLATNOTES_PATH}
 
-    echo Starting flatnotes...
-    cd ${APP_PATH}
-    exec gosu ${PUID}:${PGID} \
-      python -m \
-      uvicorn \
-      main:app \
-      --app-dir flatnotes \
-      --host 0.0.0.0 \
-      --port 8080 \
-      --proxy-headers \
-      --forwarded-allow-ips "*"
+    echo Starting flatnotes as user ${PUID}...
+    exec gosu ${PUID}:${PGID} ${flatnotes_command}
+      
 else
-    echo "A user was set by docker, skipping permissions setup."
-    exec python -m \
-      uvicorn \
-      main:app \
-      --app-dir flatnotes \
-      --host 0.0.0.0 \
-      --port 8080 \
-      --proxy-headers \
-      --forwarded-allow-ips "*"
+    echo "A user was set by docker, skipping file permission changes."
+    echo Starting flatnotes as user $(id -u)...
+    exec ${flatnotes_command}
 fi
git clone https://git.99rst.org/PROJECT