feat(): improve startup script

pull/72/head
Magicalex 2020-11-20 18:02:41 +01:00
parent f8bc06585f
commit 914b3fcc4b
No known key found for this signature in database
GPG Key ID: A89B48B1788C3CB5
2 changed files with 11 additions and 12 deletions

View File

@ -53,6 +53,7 @@ RUN apk add --no-progress --no-cache \
s6 \ s6 \
&& cd /tmp \ && cd /tmp \
&& curl -s http://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \ && curl -s http://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& sed -i 's/memory_limit = .*/memory_limit = ${PHP_MEMORY_LIMIT}/' /etc/php7/php.ini \
&& chmod +x /usr/local/bin/composer \ && chmod +x /usr/local/bin/composer \
&& mkdir -p /flarum/app \ && mkdir -p /flarum/app \
&& COMPOSER_CACHE_DIR="/tmp" composer create-project --stability=beta --no-progress -- flarum/flarum /flarum/app $VERSION \ && COMPOSER_CACHE_DIR="/tmp" composer create-project --stability=beta --no-progress -- flarum/flarum /flarum/app $VERSION \

View File

@ -11,11 +11,13 @@ if [ -z "${FORUM_URL}" ]; then
exit 1 exit 1
fi fi
CACHE_DIR=/flarum/app/extensions/.cache
LIST_FILE=/flarum/app/extensions/list
# Set file config for nginx and php # Set file config for nginx and php
sed -i "s/<FLARUM_PORT>/${FLARUM_PORT}/g" /etc/nginx/nginx.conf sed -i "s/<FLARUM_PORT>/${FLARUM_PORT}/g" /etc/nginx/nginx.conf
sed -i "s/<UPLOAD_MAX_SIZE>/${UPLOAD_MAX_SIZE}/g" /etc/nginx/nginx.conf /etc/php7/php-fpm.conf sed -i "s/<UPLOAD_MAX_SIZE>/${UPLOAD_MAX_SIZE}/g" /etc/nginx/nginx.conf /etc/php7/php-fpm.conf
sed -i "s/<PHP_MEMORY_LIMIT>/${PHP_MEMORY_LIMIT}/g" /etc/php7/php-fpm.conf sed -i "s/<PHP_MEMORY_LIMIT>/${PHP_MEMORY_LIMIT}/g" /etc/php7/php-fpm.conf
sed -i 's/memory_limit = .*/memory_limit = ${PHP_MEMORY_LIMIT}/' /etc/php7/php.ini
sed -i "s/<OPCACHE_MEMORY_LIMIT>/${OPCACHE_MEMORY_LIMIT}/g" /etc/php7/conf.d/00_opcache.ini sed -i "s/<OPCACHE_MEMORY_LIMIT>/${OPCACHE_MEMORY_LIMIT}/g" /etc/php7/conf.d/00_opcache.ini
# Set permissions for /flarum folder # Set permissions for /flarum folder
@ -42,7 +44,7 @@ if [ -n "${PHP_EXTENSIONS}" ]; then
PACKAGES="php7-${php_extension} ${PACKAGES}" PACKAGES="php7-${php_extension} ${PACKAGES}"
done done
echo "[INFO] Adding php extensions" echo "[INFO] Adding php extensions"
apk add --no-progress --no-cache ${PACKAGES} apk add --no-progress --no-cache "${PACKAGES}"
fi fi
cd /flarum/app cd /flarum/app
@ -50,7 +52,7 @@ cd /flarum/app
# Add github token authentication (eg. for privates extensions) # Add github token authentication (eg. for privates extensions)
if [ "${GITHUB_TOKEN_AUTH}" != false ]; then if [ "${GITHUB_TOKEN_AUTH}" != false ]; then
echo "[INFO] Adding github token authentication" echo "[INFO] Adding github token authentication"
composer config github-oauth.github.com "${GITHUB_TOKEN_AUTH}" COMPOSER_CACHE_DIR="${CACHE_DIR}" su-exec "${UID}:${GID}" composer config github-oauth.github.com "${GITHUB_TOKEN_AUTH}"
fi fi
# Custom repositories (eg. for privates extensions) # Custom repositories (eg. for privates extensions)
@ -59,7 +61,7 @@ if [ -f '/flarum/app/extensions/composer.repositories.txt' ]; then
repository="$(echo ${line} | cut -d '|' -f1)" repository="$(echo ${line} | cut -d '|' -f1)"
json="$(echo ${line} | cut -d '|' -f2)" json="$(echo ${line} | cut -d '|' -f2)"
echo "[INFO] Adding ${repository} composer repository" echo "[INFO] Adding ${repository} composer repository"
composer config repositories."${repository}" --json "${json}" COMPOSER_CACHE_DIR="${CACHE_DIR}" su-exec "${UID}:${GID}" composer config repositories."${repository}" --json "${json}"
done < /flarum/app/extensions/composer.repositories.txt done < /flarum/app/extensions/composer.repositories.txt
fi fi
@ -87,10 +89,6 @@ if [ -e '/flarum/app/public/assets/rev-manifest.json' ]; then
cp -p /flarum/app/config.php.sample /flarum/app/config.php cp -p /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
LIST_FILE=/flarum/app/extensions/list
# Download extra extensions installed with composer wrapup script # Download extra extensions installed with composer wrapup script
if [ -s "${LIST_FILE}" ]; then if [ -s "${LIST_FILE}" ]; then
echo "[INFO] Install extra bundled extensions" echo "[INFO] Install extra bundled extensions"
@ -98,13 +96,13 @@ if [ -e '/flarum/app/public/assets/rev-manifest.json' ]; then
extension="${extension}${line} " extension="${extension}${line} "
done < /flarum/app/extensions/list done < /flarum/app/extensions/list
cmd="composer require ${extension}" cmd="composer require ${extension}"
COMPOSER_CACHE_DIR="${CACHE_DIR}" su-exec "${UID}:${GID}" eval "${cmd}" eval "COMPOSER_CACHE_DIR=${CACHE_DIR} su-exec ${UID}:${GID} ${cmd}"
echo "[INFO] Install extra bundled extensions: DONE." echo "[INFO] Install extra bundled extensions: DONE"
else else
echo "[INFO] No installed extensions" echo "[INFO] No installed extensions"
fi fi
echo "[INFO] Init done" echo "[INFO] Flarum already installed, init app: DONE"
else else
# if no installation was performed before # if no installation was performed before
echo "[INFO] First launch, installation..." echo "[INFO] First launch, installation..."
@ -132,5 +130,5 @@ else
echo "[INFO] End of flarum installation" echo "[INFO] End of flarum installation"
fi fi
echo "[Info] End of startup script. Forum is starting." echo "[INFO] End of startup script. Forum is starting."
exec su-exec "${UID}:${GID}" /bin/s6-svscan /services exec su-exec "${UID}:${GID}" /bin/s6-svscan /services