feat(): improve startup script

pull/45/head
Magicalex 2019-12-28 22:24:02 +01:00
parent 167df1e870
commit c35209a401
No known key found for this signature in database
GPG Key ID: A89B48B1788C3CB5
3 changed files with 23 additions and 25 deletions

View File

@ -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/*

View File

@ -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

View File

@ -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>/${PHP_MEMORY_LIMIT}/g" /etc/php7/php-fpm.conf
sed -i "s/<OPCACHE_MEMORY_LIMIT>/${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>|${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>|${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