Browse Source

docker: fix the bug of using root to create /data/ directory (#6106)

eightpigs 4 years ago
parent
commit
28d74a9844
3 changed files with 6 additions and 17 deletions
  1. 0 1
      docker/s6/gogs/run
  2. 2 13
      docker/s6/gogs/setup
  3. 4 3
      docker/start.sh

+ 0 - 1
docker/s6/gogs/run

@@ -4,5 +4,4 @@ if test -f ./setup; then
     source ./setup
 fi
 
-export USER=git
 exec gosu $USER /app/gogs/gogs web

+ 2 - 13
docker/s6/gogs/setup

@@ -1,12 +1,12 @@
 #!/bin/sh
 
 if ! test -d ~git/.ssh; then
-    mkdir -p ~git/.ssh
+    gosu $USER mkdir -p ~git/.ssh
     chmod 700 ~git/.ssh
 fi
 
 if ! test -f ~git/.ssh/environment; then
-    echo "GOGS_CUSTOM=${GOGS_CUSTOM}" > ~git/.ssh/environment
+    gosu $USER echo "GOGS_CUSTOM=${GOGS_CUSTOM}" > ~git/.ssh/environment
     chmod 600 ~git/.ssh/environment
 fi
 
@@ -19,15 +19,4 @@ ln -sfn /data/gogs/data ./data
 # Backward Compatibility with Gogs Container v0.6.15
 ln -sfn /data/git /home/git
 
-# Only chown for the first time, owner of '/data' is 'git' inside Docker after installation
-if [ $(stat -c '%U' /data) != 'git' ]; then
-    chown -R git:git /data ~git/
-fi
-
-# Check ownership of '/app/gogs' in case the image changed and '/data' is persistent
-if [ $(stat -c '%U' /app/gogs) != 'git' ]; then
-    chown -R git:git /app/gogs
-fi
-
-
 chmod 0755 /data /data/gogs ~git/

+ 4 - 3
docker/start.sh

@@ -33,16 +33,17 @@ create_volume_subfolder() {
     # Create VOLUME subfolder
     for f in /data/gogs/data /data/gogs/conf /data/gogs/log /data/git /data/ssh; do
         if ! test -d $f; then
-            mkdir -p $f
+            gosu $USER mkdir -p $f
         fi
     done
 }
 
 setids() {
+    export USER=git
     PUID=${PUID:-1000}
     PGID=${PGID:-1000}
-    groupmod -o -g "$PGID" git
-    usermod -o -u "$PUID" git
+    groupmod -o -g "$PGID" $USER
+    usermod -o -u "$PUID" $USER
 }
 
 setids