[GH-ISSUE #35] setting ownership of node_modules #21

Closed
opened 2026-10-15 13:01:33 +00:00 by bsakaguchi · 6 comments
Owner

Originally created by @doomedramen on GitHub (Jun 15, 2025).
Original GitHub issue: https://github.com/games-on-whales/wolfmanager/issues/35

Description of issue

when starting the server it takes ownership of files (very useful).
it does however take a long time (and will keep taking longer as more packages are added).

wolf-admin-1  | [2025-06-15 12:35:42] [WolfManager] Creating directory: /app/config/logs
wolf-admin-1  | [2025-06-15 12:35:42] [WolfManager] Setting ownership of /app/config/logs to 1000:1000
wolf-admin-1  | [2025-06-15 12:35:42] [WolfManager] Setting ownership of /app/logs to 1000:1000
wolf-admin-1  | [2025-06-15 12:35:42] [WolfManager] Setting ownership of /app/.next to 1000:1000
wolf-admin-1  | [2025-06-15 12:35:44] [WolfManager] Setting ownership of /app/public to 1000:1000
wolf-admin-1  | [2025-06-15 12:35:44] [WolfManager] Setting ownership of application files
wolf-admin-1  | [2025-06-15 12:35:45] [WolfManager] Setting ownership of node_modules 
wolf-admin-1  | [2025-06-15 12:39:54] [WolfManager] Directory permissions setup complete <- 4 minutes

this could be faster:

#!/bin/bash
set -e
source /opt/wolf/scripts/utils.sh

wolf_log "**** Configure directory permissions ****"

# Get environment variables with defaults
PUID="${PUID:-1000}"
PGID="${PGID:-1000}"
UNAME="${UNAME:-node}"

# Application directories that need proper ownership
APP_DIRS=(
    "/app/config"
    "/app/config/logs"
    "/app/logs"
    "/app/.next"
    "/app/public"
)

# Create all directories in one pass
wolf_log "Creating directories if needed"
mkdir -p "${APP_DIRS[@]}"

# Single chown command for all directories
wolf_log "Setting ownership of all directories to ${PUID}:${PGID}"
chown -R "$PUID:$PGID" "${APP_DIRS[@]}"

# Single find command for all directories - set permissions in one pass
wolf_log "Setting directory and file permissions"
find "${APP_DIRS[@]}" \( -type d -exec chmod 755 {} + \) -o \( -type f -exec chmod 644 {} + \)

# Set ownership of main app files in batch with single chown call
wolf_log "Setting ownership of application files"
chown -R "$PUID:$PGID" \
    /app/package.json \
    /app/pnpm-lock.yaml \
    /app/pnpm-workspace.yaml \
    /app/next.config.js \
    /app/src \
    2>/dev/null || true

# Handle node_modules if it exists
if [ -d "/app/node_modules" ]; then
    wolf_log "Setting ownership of node_modules"
    chown -R "$PUID:$PGID" /app/node_modules
fi

wolf_log "Directory permissions setup complete"
Originally created by @doomedramen on GitHub (Jun 15, 2025). Original GitHub issue: https://github.com/games-on-whales/wolfmanager/issues/35 # Description of issue when starting the server it takes ownership of files (very useful). it does however take a long time (and will keep taking longer as more packages are added). ``` wolf-admin-1 | [2025-06-15 12:35:42] [WolfManager] Creating directory: /app/config/logs wolf-admin-1 | [2025-06-15 12:35:42] [WolfManager] Setting ownership of /app/config/logs to 1000:1000 wolf-admin-1 | [2025-06-15 12:35:42] [WolfManager] Setting ownership of /app/logs to 1000:1000 wolf-admin-1 | [2025-06-15 12:35:42] [WolfManager] Setting ownership of /app/.next to 1000:1000 wolf-admin-1 | [2025-06-15 12:35:44] [WolfManager] Setting ownership of /app/public to 1000:1000 wolf-admin-1 | [2025-06-15 12:35:44] [WolfManager] Setting ownership of application files wolf-admin-1 | [2025-06-15 12:35:45] [WolfManager] Setting ownership of node_modules wolf-admin-1 | [2025-06-15 12:39:54] [WolfManager] Directory permissions setup complete <- 4 minutes ``` this could be faster: ``` #!/bin/bash set -e source /opt/wolf/scripts/utils.sh wolf_log "**** Configure directory permissions ****" # Get environment variables with defaults PUID="${PUID:-1000}" PGID="${PGID:-1000}" UNAME="${UNAME:-node}" # Application directories that need proper ownership APP_DIRS=( "/app/config" "/app/config/logs" "/app/logs" "/app/.next" "/app/public" ) # Create all directories in one pass wolf_log "Creating directories if needed" mkdir -p "${APP_DIRS[@]}" # Single chown command for all directories wolf_log "Setting ownership of all directories to ${PUID}:${PGID}" chown -R "$PUID:$PGID" "${APP_DIRS[@]}" # Single find command for all directories - set permissions in one pass wolf_log "Setting directory and file permissions" find "${APP_DIRS[@]}" \( -type d -exec chmod 755 {} + \) -o \( -type f -exec chmod 644 {} + \) # Set ownership of main app files in batch with single chown call wolf_log "Setting ownership of application files" chown -R "$PUID:$PGID" \ /app/package.json \ /app/pnpm-lock.yaml \ /app/pnpm-workspace.yaml \ /app/next.config.js \ /app/src \ 2>/dev/null || true # Handle node_modules if it exists if [ -d "/app/node_modules" ]; then wolf_log "Setting ownership of node_modules" chown -R "$PUID:$PGID" /app/node_modules fi wolf_log "Directory permissions setup complete" ```
bsakaguchi 2026-10-15 13:01:33 +00:00
Author
Owner

@salty2011 commented on GitHub (Jun 16, 2025):

Oops sorry @doomedramen I accidentally closed this. Reopened

Shall take a look.

I think the the other issue is it's chown'ing the node_module dir during startup which would have thousands of files to churn through

If you submit a pr to the new 004 branch with the changes, that should trigger a build with a new preview image.

Otherwise will look at integrating above changes

<!-- gh-comment-id:2975094122 --> @salty2011 commented on GitHub (Jun 16, 2025): Oops sorry @doomedramen I accidentally closed this. Reopened Shall take a look. I think the the other issue is it's chown'ing the node_module dir during startup which would have thousands of files to churn through If you submit a pr to the new 004 branch with the changes, that should trigger a build with a new preview image. Otherwise will look at integrating above changes
Author
Owner

@salty2011 commented on GitHub (Jun 16, 2025):

Added https://github.com/games-on-whales/wolfmanager/tree/optimize-startup-permissions

Done some initial testing. does seem to be a little faster. But node modules is where it seems to be bottlenecked

<!-- gh-comment-id:2976688420 --> @salty2011 commented on GitHub (Jun 16, 2025): Added https://github.com/games-on-whales/wolfmanager/tree/optimize-startup-permissions Done some initial testing. does seem to be a little faster. But node modules is where it seems to be bottlenecked
Author
Owner

@salty2011 commented on GitHub (Jun 23, 2025):

Further review I think there is addition things that can be done to further reduce the node_modules directory

<!-- gh-comment-id:2996075669 --> @salty2011 commented on GitHub (Jun 23, 2025): Further review I think there is addition things that can be done to further reduce the node_modules directory
Author
Owner

@shawly commented on GitHub (Jun 24, 2025):

I just tested setting the ownership using find and xargs -P to optimze the speed of owning node_modules. I measured the speed with the time command.

Here is the time it takes using the current chown -R "$PUID:$PGID" /app/node_modules command:

[2025-06-24 22:00:35] [WolfManager] Setting ownership of node_modules
real	0m36.824s
user	0m0.033s
sys	0m3.681s
[2025-06-24 22:01:12] [WolfManager] Directory permissions setup complete

Using find + xargs find /app/node_modules -print0 | xargs -0 -P $(nproc) chown -h "$PUID:$PGID":

[2025-06-24 21:59:31] [WolfManager] Setting ownership of node_modules
real	0m8.613s
user	0m0.099s
sys	0m5.844s
[2025-06-24 21:59:40] [WolfManager] Directory permissions setup complete

So with find and xargs it can be about 75% faster to own the node_modules now, depending on how many cores the host has.

<!-- gh-comment-id:3001722439 --> @shawly commented on GitHub (Jun 24, 2025): I just tested setting the ownership using find and xargs -P to optimze the speed of owning node_modules. I measured the speed with the time command. Here is the time it takes using the current `chown -R "$PUID:$PGID" /app/node_modules` command: ``` [2025-06-24 22:00:35] [WolfManager] Setting ownership of node_modules real 0m36.824s user 0m0.033s sys 0m3.681s [2025-06-24 22:01:12] [WolfManager] Directory permissions setup complete ``` Using find + xargs `find /app/node_modules -print0 | xargs -0 -P $(nproc) chown -h "$PUID:$PGID"`: ``` [2025-06-24 21:59:31] [WolfManager] Setting ownership of node_modules real 0m8.613s user 0m0.099s sys 0m5.844s [2025-06-24 21:59:40] [WolfManager] Directory permissions setup complete ``` So with find and xargs it can be about 75% faster to own the node_modules now, depending on how many cores the host has.
Author
Owner

@salty2011 commented on GitHub (Jun 24, 2025):

Nice, I've merged the patch @shawly provided into the optimise branch

If you want to do a pr to the preview branch. May need to rebase from stable to the preview as have done some fixes for other things

<!-- gh-comment-id:3002025246 --> @salty2011 commented on GitHub (Jun 24, 2025): Nice, I've merged the patch @shawly provided into the optimise branch If you want to do a pr to the preview branch. May need to rebase from stable to the preview as have done some fixes for other things
Author
Owner

@salty2011 commented on GitHub (Jul 7, 2025):

@shawly ive now merged this into the release/202506.004 branch,

<!-- gh-comment-id:3043194576 --> @salty2011 commented on GitHub (Jul 7, 2025): @shawly ive now merged this into the release/202506.004 branch,
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
games-on-whales/wolfmanager#21
No description provided.