Skip to content

Commit

Permalink
[5.x] Optimize hooks, create database.sqlite for Laravel-based projec…
Browse files Browse the repository at this point in the history
…ts (#155)
  • Loading branch information
shinsenter authored Sep 26, 2024
1 parent 5c8a5a5 commit 2712832
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
38 changes: 28 additions & 10 deletions src/php/common/rootfs/etc/hooks/bootstrap/10-create-project
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ install_deps() {
fi
}

copy_env() {
if [ ! -e "$ENV_PATH" ]; then
if [ -f "$ENV_PATH.example" ]; then
cp -p "$ENV_PATH.example" "$ENV_PATH"
debug-echo "Copied .env.example to .env"
elif [ -f "$ENV_PATH.sample" ]; then
cp -p "$ENV_PATH.sample" "$ENV_PATH"
debug-echo "Copied .env.sample to .env"
fi
fi
}

################################################################################

web-mkdir "$APP_PATH" "$COMPOSER_HOME"
Expand Down Expand Up @@ -75,6 +87,8 @@ if [ -z "$(ls -A "$APP_PATH")" ]; then
-- "$INITIAL_PROJECT" "$APP_PATH"
;;
esac

hook post-create-project
web-chown "Project $INITIAL_PROJECT created in $APP_PATH."
fi

Expand All @@ -84,49 +98,53 @@ if [ -z "$(ls -A "$APP_PATH")" ]; then
web-chown "Copied files from /source/ to $APP_PATH"
fi

# copy .env.example to .env
copy_env

# update packages if the project has composer.json
if [ -e "$CONF_PATH" ]; then
hook pre-package-update

install_deps
composer config -n --no-plugins "allow-plugins.*/*" true

if grep -qF '"post-root-package-install"' $CONF_PATH; then
composer run post-root-package-install
hook post-root-package-install
fi

composer update -n -W $COMPOSER_UPDATE_OPTIONS

if grep -qF '"post-create-project-cmd"' $CONF_PATH; then
composer run post-create-project-cmd
hook post-create-project-cmd
fi

hook post-create-project
composer config -n --unset "allow-plugins.*/*"

hook post-package-update
web-chown "Required packages in $APP_PATH were updated."
fi
else
debug-echo "Skip project creation because $APP_PATH is not empty."
fi

# copy .env.example to .env
if [ ! -e "$ENV_PATH" ]; then
if [ -f "$ENV_PATH.example" ]; then
cp -p "$ENV_PATH.example" "$ENV_PATH"
debug-echo "Copied .env.example to .env"
elif [ -f "$ENV_PATH.sample" ]; then
cp -p "$ENV_PATH.sample" "$ENV_PATH"
debug-echo "Copied .env.sample to .env"
fi
fi
copy_env

# run composer install when vendor directory or ClassLoader.php is missing
if ! is-true $DISABLE_AUTORUN_COMPOSER_INSTALL && has-cmd composer; then
if [ -e "$CONF_PATH" ]; then
vendor_dir="$APP_PATH/$(composer config vendor-dir 2>/dev/null)"
if [ ! -d "$vendor_dir" ] || [ ! -e "$vendor_dir/composer/ClassLoader.php" ]; then
hook pre-package-install

install_deps
composer config -n --no-plugins "allow-plugins.*/*" true
composer install -n $COMPOSER_INSTALL_OPTIONS
composer config -n --unset "allow-plugins.*/*"

hook post-package-install
web-chown "Composer packages were installed in $APP_PATH"
fi
else
Expand Down
2 changes: 1 addition & 1 deletion src/webapps/espocrm/espocrm.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ENV DISABLE_AUTORUN_GENERATING_INDEX=1

# https://docs.espocrm.com/administration/server-configuration/#setting-up-crontab
ENV ENABLE_CRONTAB=1
ENV CRONTAB_SETTINGS='* * * * * php -f $(app-path)/cron.php >/dev/null 2>&1'
ENV CRONTAB_SETTINGS='* * * * * php -f $(app-path)/cron.php &>/dev/null'
ENV ESPOCRM_CONFIG_USE_WEB_SOCKET=0
RUN env-default INITIAL_PROJECT "$(curl --retry 3 --retry-delay 5 -ksLRJ https://api.github.com/repos/espocrm/espocrm/releases/latest | grep "browser_download_url.*EspoCRM.*zip" | cut -d \" -f 4)"

Expand Down
1 change: 1 addition & 0 deletions src/webapps/invoiceshelf/rootfs/startup/boot-invoiceshelf
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ APP_PATH="$(app-path)"
APP_ROOT="$(app-root)"

debug-echo "Your web application must be in {$APP_PATH}."
touch $APP_PATH/database/database.sqlite &>/dev/null
1 change: 1 addition & 0 deletions src/webapps/laravel/rootfs/startup/boot-laravel
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ APP_PATH="$(app-path)"
APP_ROOT="$(app-root)"

debug-echo "Your web application must be in {$APP_PATH}."
touch $APP_PATH/database/database.sqlite &>/dev/null
1 change: 1 addition & 0 deletions src/webapps/statamic/rootfs/startup/boot-statamic
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ APP_PATH="$(app-path)"
APP_ROOT="$(app-root)"

debug-echo "Your web application must be in {$APP_PATH}."
touch $APP_PATH/database/database.sqlite &>/dev/null
1 change: 1 addition & 0 deletions src/webapps/zz-crater/rootfs/startup/boot-crater
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ APP_PATH="$(app-path)"
APP_ROOT="$(app-root)"

debug-echo "Your web application must be in {$APP_PATH}."
touch $APP_PATH/database/database.sqlite &>/dev/null

0 comments on commit 2712832

Please sign in to comment.