From 3cf068f3ceb0184b2695294e5ff72a9f378a16bf Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sat, 26 Jun 2021 13:59:05 +0200 Subject: [PATCH] feat: allow --user option --- apache/Dockerfile | 6 +++--- apache/entrypoint.sh | 41 ++++++++++++++++++++++++++++++++-------- docker-entrypoint.sh | 41 ++++++++++++++++++++++++++++++++-------- fpm-alpine/Dockerfile | 6 +++--- fpm-alpine/entrypoint.sh | 41 ++++++++++++++++++++++++++++++++-------- fpm/Dockerfile | 6 +++--- fpm/entrypoint.sh | 41 ++++++++++++++++++++++++++++++++-------- 7 files changed, 141 insertions(+), 41 deletions(-) diff --git a/apache/Dockerfile b/apache/Dockerfile index f8ea768..0b136cc 100644 --- a/apache/Dockerfile +++ b/apache/Dockerfile @@ -128,9 +128,9 @@ RUN set -ex; \ WORKDIR /var/www/html # Define Monica version -ENV MONICA_VERSION v3.1.1 -LABEL org.opencontainers.image.revision="13325cc8c1f32b391905a35abb166f843faef142" \ - org.opencontainers.image.version="v3.1.1" +ENV MONICA_VERSION v3.1.2 +LABEL org.opencontainers.image.revision="8ba7d983efcef7555b620cb1a0bbc32db3835f00" \ + org.opencontainers.image.version="v3.1.2" RUN set -ex; \ fetchDeps=" \ diff --git a/apache/entrypoint.sh b/apache/entrypoint.sh index 375bfeb..1287612 100755 --- a/apache/entrypoint.sh +++ b/apache/entrypoint.sh @@ -65,18 +65,43 @@ EOPHP if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ]; then + uid="$(id -u)" + gid="$(id -g)" + if [ "$uid" = '0' ]; then + case "$1" in + php-fpm*) + user='www-data' + group='www-data' + ;; + *) # apache + user="${APACHE_RUN_USER:-www-data}" + group="${APACHE_RUN_GROUP:-www-data}" + + # strip off any '#' symbol ('#1000' is valid syntax for Apache) + pound='#' + user="${user#$pound}" + group="${group#$pound}" + ;; + esac + else + user="$uid" + group="$gid" + fi + MONICADIR=/var/www/html ARTISAN="php ${MONICADIR}/artisan" # Ensure storage directories are present - STORAGE=${MONICADIR}/storage - mkdir -p ${STORAGE}/logs - mkdir -p ${STORAGE}/app/public - mkdir -p ${STORAGE}/framework/views - mkdir -p ${STORAGE}/framework/cache - mkdir -p ${STORAGE}/framework/sessions - chown -R www-data:www-data ${STORAGE} - chmod -R g+rw ${STORAGE} + if [ "$uid" = '0' ]; then + STORAGE=${MONICADIR}/storage + mkdir -p ${STORAGE}/logs + mkdir -p ${STORAGE}/app/public + mkdir -p ${STORAGE}/framework/views + mkdir -p ${STORAGE}/framework/cache + mkdir -p ${STORAGE}/framework/sessions + chown -R $user:$group ${STORAGE} + chmod -R g+rw ${STORAGE} + fi if [ -z "${APP_KEY:-}" -o "$APP_KEY" = "ChangeMeBy32KeyLengthOrGenerated" ]; then ${ARTISAN} key:generate --no-interaction diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 375bfeb..1287612 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -65,18 +65,43 @@ EOPHP if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ]; then + uid="$(id -u)" + gid="$(id -g)" + if [ "$uid" = '0' ]; then + case "$1" in + php-fpm*) + user='www-data' + group='www-data' + ;; + *) # apache + user="${APACHE_RUN_USER:-www-data}" + group="${APACHE_RUN_GROUP:-www-data}" + + # strip off any '#' symbol ('#1000' is valid syntax for Apache) + pound='#' + user="${user#$pound}" + group="${group#$pound}" + ;; + esac + else + user="$uid" + group="$gid" + fi + MONICADIR=/var/www/html ARTISAN="php ${MONICADIR}/artisan" # Ensure storage directories are present - STORAGE=${MONICADIR}/storage - mkdir -p ${STORAGE}/logs - mkdir -p ${STORAGE}/app/public - mkdir -p ${STORAGE}/framework/views - mkdir -p ${STORAGE}/framework/cache - mkdir -p ${STORAGE}/framework/sessions - chown -R www-data:www-data ${STORAGE} - chmod -R g+rw ${STORAGE} + if [ "$uid" = '0' ]; then + STORAGE=${MONICADIR}/storage + mkdir -p ${STORAGE}/logs + mkdir -p ${STORAGE}/app/public + mkdir -p ${STORAGE}/framework/views + mkdir -p ${STORAGE}/framework/cache + mkdir -p ${STORAGE}/framework/sessions + chown -R $user:$group ${STORAGE} + chmod -R g+rw ${STORAGE} + fi if [ -z "${APP_KEY:-}" -o "$APP_KEY" = "ChangeMeBy32KeyLengthOrGenerated" ]; then ${ARTISAN} key:generate --no-interaction diff --git a/fpm-alpine/Dockerfile b/fpm-alpine/Dockerfile index e34a7d0..f861acc 100644 --- a/fpm-alpine/Dockerfile +++ b/fpm-alpine/Dockerfile @@ -102,9 +102,9 @@ RUN set -ex; \ WORKDIR /var/www/html # Define Monica version -ENV MONICA_VERSION v3.1.1 -LABEL org.opencontainers.image.revision="13325cc8c1f32b391905a35abb166f843faef142" \ - org.opencontainers.image.version="v3.1.1" +ENV MONICA_VERSION v3.1.2 +LABEL org.opencontainers.image.revision="8ba7d983efcef7555b620cb1a0bbc32db3835f00" \ + org.opencontainers.image.version="v3.1.2" RUN set -ex; \ apk add --no-cache --virtual .fetch-deps \ diff --git a/fpm-alpine/entrypoint.sh b/fpm-alpine/entrypoint.sh index 375bfeb..1287612 100755 --- a/fpm-alpine/entrypoint.sh +++ b/fpm-alpine/entrypoint.sh @@ -65,18 +65,43 @@ EOPHP if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ]; then + uid="$(id -u)" + gid="$(id -g)" + if [ "$uid" = '0' ]; then + case "$1" in + php-fpm*) + user='www-data' + group='www-data' + ;; + *) # apache + user="${APACHE_RUN_USER:-www-data}" + group="${APACHE_RUN_GROUP:-www-data}" + + # strip off any '#' symbol ('#1000' is valid syntax for Apache) + pound='#' + user="${user#$pound}" + group="${group#$pound}" + ;; + esac + else + user="$uid" + group="$gid" + fi + MONICADIR=/var/www/html ARTISAN="php ${MONICADIR}/artisan" # Ensure storage directories are present - STORAGE=${MONICADIR}/storage - mkdir -p ${STORAGE}/logs - mkdir -p ${STORAGE}/app/public - mkdir -p ${STORAGE}/framework/views - mkdir -p ${STORAGE}/framework/cache - mkdir -p ${STORAGE}/framework/sessions - chown -R www-data:www-data ${STORAGE} - chmod -R g+rw ${STORAGE} + if [ "$uid" = '0' ]; then + STORAGE=${MONICADIR}/storage + mkdir -p ${STORAGE}/logs + mkdir -p ${STORAGE}/app/public + mkdir -p ${STORAGE}/framework/views + mkdir -p ${STORAGE}/framework/cache + mkdir -p ${STORAGE}/framework/sessions + chown -R $user:$group ${STORAGE} + chmod -R g+rw ${STORAGE} + fi if [ -z "${APP_KEY:-}" -o "$APP_KEY" = "ChangeMeBy32KeyLengthOrGenerated" ]; then ${ARTISAN} key:generate --no-interaction diff --git a/fpm/Dockerfile b/fpm/Dockerfile index 422fe8d..50523f1 100644 --- a/fpm/Dockerfile +++ b/fpm/Dockerfile @@ -114,9 +114,9 @@ RUN set -ex; \ WORKDIR /var/www/html # Define Monica version -ENV MONICA_VERSION v3.1.1 -LABEL org.opencontainers.image.revision="13325cc8c1f32b391905a35abb166f843faef142" \ - org.opencontainers.image.version="v3.1.1" +ENV MONICA_VERSION v3.1.2 +LABEL org.opencontainers.image.revision="8ba7d983efcef7555b620cb1a0bbc32db3835f00" \ + org.opencontainers.image.version="v3.1.2" RUN set -ex; \ fetchDeps=" \ diff --git a/fpm/entrypoint.sh b/fpm/entrypoint.sh index 375bfeb..1287612 100755 --- a/fpm/entrypoint.sh +++ b/fpm/entrypoint.sh @@ -65,18 +65,43 @@ EOPHP if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ]; then + uid="$(id -u)" + gid="$(id -g)" + if [ "$uid" = '0' ]; then + case "$1" in + php-fpm*) + user='www-data' + group='www-data' + ;; + *) # apache + user="${APACHE_RUN_USER:-www-data}" + group="${APACHE_RUN_GROUP:-www-data}" + + # strip off any '#' symbol ('#1000' is valid syntax for Apache) + pound='#' + user="${user#$pound}" + group="${group#$pound}" + ;; + esac + else + user="$uid" + group="$gid" + fi + MONICADIR=/var/www/html ARTISAN="php ${MONICADIR}/artisan" # Ensure storage directories are present - STORAGE=${MONICADIR}/storage - mkdir -p ${STORAGE}/logs - mkdir -p ${STORAGE}/app/public - mkdir -p ${STORAGE}/framework/views - mkdir -p ${STORAGE}/framework/cache - mkdir -p ${STORAGE}/framework/sessions - chown -R www-data:www-data ${STORAGE} - chmod -R g+rw ${STORAGE} + if [ "$uid" = '0' ]; then + STORAGE=${MONICADIR}/storage + mkdir -p ${STORAGE}/logs + mkdir -p ${STORAGE}/app/public + mkdir -p ${STORAGE}/framework/views + mkdir -p ${STORAGE}/framework/cache + mkdir -p ${STORAGE}/framework/sessions + chown -R $user:$group ${STORAGE} + chmod -R g+rw ${STORAGE} + fi if [ -z "${APP_KEY:-}" -o "$APP_KEY" = "ChangeMeBy32KeyLengthOrGenerated" ]; then ${ARTISAN} key:generate --no-interaction