From c8a56dfe2a4c75e9cc4d8c603853250954369459 Mon Sep 17 00:00:00 2001 From: Jay Rogers Date: Thu, 21 Dec 2023 09:28:44 -0600 Subject: [PATCH] Update Docker user and group settings --- lib/actions/new.sh | 2 +- lib/actions/php.sh | 2 +- templates/laravel/Dockerfile | 8 +++++--- templates/laravel/docker-compose.dev.yml | 1 + 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/actions/new.sh b/lib/actions/new.sh index d68f196f..4cba096d 100755 --- a/lib/actions/new.sh +++ b/lib/actions/new.sh @@ -8,7 +8,7 @@ action_new(){ shift 1 latest_image=$SPIN_PHP_IMAGE docker pull $latest_image - docker run --rm -w /var/www/html -v $(pwd):/var/www/html --user ${SPIN_USER_ID} -e "LOG_LEVEL=off" $latest_image composer create-project laravel/laravel "$@" + docker run --rm -w /var/www/html -v $(pwd):/var/www/html --user "$SPIN_DEFAULT_PHP_USER:$SPIN_GROUP_ID" -e "LOG_LEVEL=off" $latest_image composer create-project laravel/laravel "$@" install_spin_package_to_project php "${@:-laravel}" --force source "$SPIN_HOME/lib/actions/init.sh" action_init --template=laravel --project-directory="${@:-laravel}" --force diff --git a/lib/actions/php.sh b/lib/actions/php.sh index bb6a08c7..a638f450 100755 --- a/lib/actions/php.sh +++ b/lib/actions/php.sh @@ -8,7 +8,7 @@ action_php(){ $COMPOSE_CMD run --remove-orphans --no-deps --rm \ --entrypoint '' \ -e "LOG_LEVEL=off" \ - --user $SPIN_DEFAULT_PHP_USER \ + --user "$SPIN_DEFAULT_PHP_USER:$SPIN_GROUP_ID" \ $SPIN_DEFAULT_PHP_SERVICE_NAME \ "${args[@]}" } \ No newline at end of file diff --git a/templates/laravel/Dockerfile b/templates/laravel/Dockerfile index 42c2016e..876ae0e3 100644 --- a/templates/laravel/Dockerfile +++ b/templates/laravel/Dockerfile @@ -6,10 +6,12 @@ FROM serversideup/php:beta-8.3-fpm-nginx as base FROM base as development # Fix permission issues in development -# by setting the "www-data" user to the same UID as -# the developer's user. +# by setting the "www-data" user to the +# same user and group that is running docker. ARG USER_ID -RUN usermod -u $USER_ID www-data +ARG GROUP_ID +RUN usermod -u $USER_ID www-data && \ + groupmod -g $GROUP_ID www-data FROM base as deploy COPY --chown=www-data:www-data . /var/www/html \ No newline at end of file diff --git a/templates/laravel/docker-compose.dev.yml b/templates/laravel/docker-compose.dev.yml index 3c035b69..47c52604 100644 --- a/templates/laravel/docker-compose.dev.yml +++ b/templates/laravel/docker-compose.dev.yml @@ -20,6 +20,7 @@ services: target: development args: USER_ID: ${SPIN_USER_ID} + GROUP_ID: ${SPIN_GROUP_ID} volumes: - .:/var/www/html/ networks: