From c35209a401a1d030e06766a49c06330727815f03 Mon Sep 17 00:00:00 2001 From: Magicalex Date: Sat, 28 Dec 2019 22:24:02 +0100 Subject: [PATCH] feat(): improve startup script --- Dockerfile | 12 ++++++++++-- rootfs/usr/local/bin/extension | 6 +++--- rootfs/usr/local/bin/startup | 30 ++++++++++-------------------- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6d06db0..11b5427 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,15 @@ ENV GID=991 \ UID=991 \ UPLOAD_MAX_SIZE=50M \ PHP_MEMORY_LIMIT=128M \ - OPCACHE_MEMORY_LIMIT=128 + OPCACHE_MEMORY_LIMIT=128 \ + DB_HOST=mariadb \ + DB_USER=flarum \ + DB_NAME=flarum \ + DB_PORT=3306 \ + FLARUM_TITLE=Docker-Flarum \ + DEBUG=false \ + LOG_TO_STDOUT=false \ + GITHUB_TOKEN_AUTH=false RUN apk add --no-progress --no-cache \ nginx \ @@ -47,7 +55,7 @@ RUN apk add --no-progress --no-cache \ && COMPOSER_CACHE_DIR="/tmp" su-exec $UID:$GID composer create-project --stability=beta --no-progress -- flarum/flarum /flarum/app $VERSION \ && composer clear-cache \ && rm -rf /flarum/.composer /tmp/* \ - && apk del --purge curl + && apk del --purge curl git COPY rootfs / RUN chmod +x /usr/local/bin/* /services/*/run /services/.s6-svscan/* diff --git a/rootfs/usr/local/bin/extension b/rootfs/usr/local/bin/extension index 6ca8d2c..362f8fa 100644 --- a/rootfs/usr/local/bin/extension +++ b/rootfs/usr/local/bin/extension @@ -19,8 +19,8 @@ action="${1}" package="${2}" # Create custom extensions cache folder and list file -su-exec $UID:$GID mkdir -p "${CACHE_DIR}" -su-exec $UID:$GID touch "${LIST_FILE}" +su-exec "${UID}:${GID}" mkdir -p "${CACHE_DIR}" +su-exec "${UID}:${GID}" touch "${LIST_FILE}" case "${action}" in # Install a flarum extension @@ -54,6 +54,6 @@ case "${action}" in ;; esac -su-exec $UID:$GID php /flarum/app/flarum cache:clear +su-exec "${UID}:${GID}" php /flarum/app/flarum cache:clear exit 0 diff --git a/rootfs/usr/local/bin/startup b/rootfs/usr/local/bin/startup index 64bf382..0e55061 100644 --- a/rootfs/usr/local/bin/startup +++ b/rootfs/usr/local/bin/startup @@ -1,15 +1,5 @@ #!/usr/bin/env sh -# Default values -DB_HOST="${DB_HOST:-mariadb}" -DB_USER="${DB_USER:-flarum}" -DB_NAME="${DB_NAME:-flarum}" -DB_PORT="${DB_PORT:-3306}" -FLARUM_TITLE="${FLARUM_TITLE:-Docker-Flarum}" -DEBUG="${DEBUG:-false}" -LOG_TO_STDOUT="${LOG_TO_STDOUT:-false}" -GITHUB_TOKEN_AUTH="${GITHUB_TOKEN_AUTH:-false}" - # Required env variables if [ -z "${DB_PASS}" ]; then echo "[ERROR] Mariadb database password must be set !" @@ -27,7 +17,7 @@ sed -i "s//${PHP_MEMORY_LIMIT}/g" /etc/php7/php-fpm.conf sed -i "s//${OPCACHE_MEMORY_LIMIT}/g" /etc/php7/conf.d/00_opcache.ini # Set permissions -chown -R $UID:$GID /services /var/log /var/lib/nginx +chown -R "${UID}:${GID}" /services /var/log /var/lib/nginx # Set log output to STDOUT if wanted (LOG_TO_STDOUT=true) if [ "${LOG_TO_STDOUT}" = true ]; then @@ -48,8 +38,8 @@ fi # Custom repositories (eg. for privates extensions) if [ -f '/flarum/app/extensions/composer.repositories.txt' ]; then while read line; do - repository=$(echo $line | cut -d '|' -f1) - json=$(echo $line | cut -d '|' -f2) + repository="$(echo ${line} | cut -d '|' -f1)" + json="$(echo ${line} | cut -d '|' -f2)" echo "[INFO] Adding ${repository} composer repository" composer config repositories."${repository}" "${json}" done < /flarum/app/extensions/composer.repositories.txt @@ -77,7 +67,7 @@ if [ -e '/flarum/app/public/assets/rev-manifest.json' ]; then -e "s||${FORUM_URL}|g" /flarum/app/config.php.sample cp /flarum/app/config.php.sample /flarum/app/config.php - su-exec $UID:$GID php /flarum/app/flarum cache:clear + su-exec "${UID}:${GID}" php /flarum/app/flarum cache:clear # Composer cache dir and packages list paths CACHE_DIR=/flarum/app/extensions/.cache @@ -90,7 +80,7 @@ if [ -e '/flarum/app/public/assets/rev-manifest.json' ]; then extension="${extension}${line} " done < /flarum/app/extensions/list cmd="composer require ${extension}" - COMPOSER_CACHE_DIR="${CACHE_DIR}" eval $cmd + COMPOSER_CACHE_DIR="${CACHE_DIR}" eval "${cmd}" echo "[INFO] Install extra bundled extensions: DONE." else echo "[INFO] No installed extensions" @@ -120,15 +110,15 @@ else -e "s||${FLARUM_TITLE}|g" /flarum/app/config.yml # Install flarum - chown -R $UID:$GID /flarum - su-exec $UID:$GID php /flarum/app/flarum install --file=/flarum/app/config.yml + chown -R "${UID}:${GID}" /flarum + su-exec "${UID}:${GID}" php /flarum/app/flarum install --file=/flarum/app/config.yml echo "[INFO] End of flarum installation" fi # Set permissions for /flarum folder -find /flarum ! -user $UID -print0 | xargs -0 -r chown $UID:$GID -find /flarum ! -group $GID -print0 | xargs -0 -r chown $UID:$GID +find /flarum ! -user "${UID}" -exec chown "${UID}:${GID}" {} \; +find /flarum ! -group "${GID}" -exec chown "${UID}:${GID}" {} \; # RUN ! -exec su-exec $UID:$GID /bin/s6-svscan /services +exec su-exec "${UID}:${GID}" /bin/s6-svscan /services