Skip to content

Commit

Permalink
feat(): improve startup script
Browse files Browse the repository at this point in the history
  • Loading branch information
Magicalex committed Nov 20, 2020
1 parent f8bc065 commit 914b3fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ RUN apk add --no-progress --no-cache \
s6 \
&& cd /tmp \
&& 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 \
&& mkdir -p /flarum/app \
&& COMPOSER_CACHE_DIR="/tmp" composer create-project --stability=beta --no-progress -- flarum/flarum /flarum/app $VERSION \
Expand Down
22 changes: 10 additions & 12 deletions rootfs/usr/local/bin/startup
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ if [ -z "${FORUM_URL}" ]; then
exit 1
fi

CACHE_DIR=/flarum/app/extensions/.cache
LIST_FILE=/flarum/app/extensions/list

# Set file config for nginx and php
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/<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

# Set permissions for /flarum folder
Expand All @@ -42,15 +44,15 @@ if [ -n "${PHP_EXTENSIONS}" ]; then
PACKAGES="php7-${php_extension} ${PACKAGES}"
done
echo "[INFO] Adding php extensions"
apk add --no-progress --no-cache ${PACKAGES}
apk add --no-progress --no-cache "${PACKAGES}"
fi

cd /flarum/app

# Add github token authentication (eg. for privates extensions)
if [ "${GITHUB_TOKEN_AUTH}" != false ]; then
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

# Custom repositories (eg. for privates extensions)
Expand All @@ -59,7 +61,7 @@ if [ -f '/flarum/app/extensions/composer.repositories.txt' ]; then
repository="$(echo ${line} | cut -d '|' -f1)"
json="$(echo ${line} | cut -d '|' -f2)"
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
fi

Expand Down Expand Up @@ -87,24 +89,20 @@ if [ -e '/flarum/app/public/assets/rev-manifest.json' ]; then
cp -p /flarum/app/config.php.sample /flarum/app/config.php
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
if [ -s "${LIST_FILE}" ]; then
echo "[INFO] Install extra bundled extensions"
while read line; do
extension="${extension}${line} "
done < /flarum/app/extensions/list
cmd="composer require ${extension}"
COMPOSER_CACHE_DIR="${CACHE_DIR}" su-exec "${UID}:${GID}" eval "${cmd}"
echo "[INFO] Install extra bundled extensions: DONE."
eval "COMPOSER_CACHE_DIR=${CACHE_DIR} su-exec ${UID}:${GID} ${cmd}"
echo "[INFO] Install extra bundled extensions: DONE"
else
echo "[INFO] No installed extensions"
fi

echo "[INFO] Init done"
echo "[INFO] Flarum already installed, init app: DONE"
else
# if no installation was performed before
echo "[INFO] First launch, installation..."
Expand Down Expand Up @@ -132,5 +130,5 @@ else
echo "[INFO] End of flarum installation"
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

0 comments on commit 914b3fc

Please sign in to comment.