From d3987d8b484d052ce1abf86e6bbb838b63b80151 Mon Sep 17 00:00:00 2001 From: Soner Sayakci Date: Wed, 24 Jan 2024 15:52:03 +0100 Subject: [PATCH] feat: allow hooks in the docker image --- .shellcheckrc | 1 + rootfs/setup | 8 ++-- rootfs/setup_6.5.x | 65 ------------------------- rootfs/setup_6.6.x | 66 -------------------------- rootfs/usr/local/shopware/functions.sh | 56 ++++++++++++++++++++++ rootfs/usr/local/shopware/setup_6.5.x | 33 +++++++++++++ rootfs/usr/local/shopware/setup_6.6.x | 42 ++++++++++++++++ 7 files changed, 136 insertions(+), 135 deletions(-) create mode 100644 .shellcheckrc delete mode 100755 rootfs/setup_6.5.x delete mode 100755 rootfs/setup_6.6.x create mode 100644 rootfs/usr/local/shopware/functions.sh create mode 100755 rootfs/usr/local/shopware/setup_6.5.x create mode 100755 rootfs/usr/local/shopware/setup_6.6.x diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 0000000..256d0e6 --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1 @@ +external-sources=true \ No newline at end of file diff --git a/rootfs/setup b/rootfs/setup index 4d892f2..343a60e 100755 --- a/rootfs/setup +++ b/rootfs/setup @@ -7,9 +7,9 @@ shopware_version=$(jq '.packages[] | select (.name == "shopware/core") | .versio # if shopware version starts with 6.6 echo 6.6 # shellcheck disable=SC2081,SC3010 if [[ $shopware_version == v6.6.* ]]; then - # shellcheck source=/dev/null - . /setup_6.6.x + # shellcheck source-path=./rootfs source=./usr/local/shopware/setup_6.6.x + . /usr/local/shopware/setup_6.6.x else - # shellcheck source=/dev/null - . /setup_6.5.x + # shellcheck source-path=./rootfs source=./usr/local/shopware/setup_6.5.x + . /usr/local/shopware/setup_6.5.x fi diff --git a/rootfs/setup_6.5.x b/rootfs/setup_6.5.x deleted file mode 100755 index 25e3dfe..0000000 --- a/rootfs/setup_6.5.x +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env sh - -set -e -set -x - -database_host=$(trurl "$DATABASE_URL" --get '{host}') -database_port=$(trurl "$DATABASE_URL" --get '{port}') - -MYSQL_WAIT_SECONDS=${MYSQL_WAIT_SECONDS:-20} - -try=0 -if [ "$MYSQL_WAIT_SECONDS" != 0 ]; then - until nc -z -v -w30 "$database_host" "${database_port:-3306}" - do - echo "Waiting for database connection..." - # wait for 5 seconds before check again - sleep 1 - - try=$((try+1)) - - if [ $try = "$MYSQL_WAIT_SECONDS" ]; then - echo "Error: We have been waiting for database connection too long already; failing." - exit 1 - fi - done -fi - -console() { - php -derror_reporting=E_ALL bin/console "$@" -} - -update_all_plugins() { - list_with_updates=$(php bin/console plugin:list --json | jq 'map(select(.upgradeVersion != null)) | .[].name' -r) - - for plugin in $list_with_updates; do - php -derror_reporting=E_ALL bin/console plugin:update "$plugin" - done -} - -install_all_plugins() { - list_with_updates=$(php bin/console plugin:list --json | jq 'map(select(.installedAt == null)) | .[].name' -r) - - for plugin in $list_with_updates; do - php -derror_reporting=E_ALL bin/console plugin:install --activate "$plugin" - done -} - -if php bin/console system:config:get shopware.installed; then - php -derror_reporting=E_ALL bin/console system:update:finish - php -derror_reporting=E_ALL bin/console plugin:refresh - - update_all_plugins - install_all_plugins -else - # Shopware is not installed - php -derror_reporting=E_ALL bin/console system:install --create-database "--shop-locale=$INSTALL_LOCALE" "--shop-currency=$INSTALL_CURRENCY" --force - php -derror_reporting=E_ALL bin/console user:create "$INSTALL_ADMIN_USERNAME" --admin --password="$INSTALL_ADMIN_PASSWORD" -n - php -derror_reporting=E_ALL bin/console sales-channel:create:storefront --name=Storefront --url="$APP_URL" - php -derror_reporting=E_ALL bin/console theme:change --all Storefront - php -derror_reporting=E_ALL bin/console system:config:set core.frw.completedAt '2019-10-07T10:46:23+00:00' - php -derror_reporting=E_ALL bin/console system:config:set core.usageData.shareUsageData false --json - php -derror_reporting=E_ALL bin/console plugin:refresh - - install_all_plugins -fi diff --git a/rootfs/setup_6.6.x b/rootfs/setup_6.6.x deleted file mode 100755 index a152f8e..0000000 --- a/rootfs/setup_6.6.x +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env sh - -set -e -set -x - -database_host=$(trurl "$DATABASE_URL" --get '{host}') -database_port=$(trurl "$DATABASE_URL" --get '{port}') - -MYSQL_WAIT_SECONDS=${MYSQL_WAIT_SECONDS:-20} - -try=0 -if [ "$MYSQL_WAIT_SECONDS" != 0 ]; then - until nc -z -v -w30 "$database_host" "${database_port:-3306}" - do - echo "Waiting for database connection..." - # wait for 5 seconds before check again - sleep 1 - - try=$((try+1)) - - if [ $try = "$MYSQL_WAIT_SECONDS" ]; then - echo "Error: We have been waiting for database connection too long already; failing." - exit 1 - fi - done -fi - -console() { - php -derror_reporting=E_ALL bin/console "$@" -} - -update_all_plugins() { - console plugin:update:all -} - -install_all_plugins() { - list_with_updates=$(php bin/console plugin:list --json | jq 'map(select(.installedAt == null)) | .[].name' -r) - - for plugin in $list_with_updates; do - console plugin:install --activate $plugin - done -} - -if console system:is-installed; then - if [[ ${SHOPWARE_SKIP_ASSET_COPY-""} ]]; then - console system:update:finish --skip-asset-build - else - console system:update:finish - fi - - console plugin:refresh - - update_all_plugins - install_all_plugins -else - # Shopware is not installed - console system:install --create-database "--shop-locale=$INSTALL_LOCALE" "--shop-currency=$INSTALL_CURRENCY" --force - console user:create "$INSTALL_ADMIN_USERNAME" --admin --password="$INSTALL_ADMIN_PASSWORD" -n - console sales-channel:create:storefront --name=Storefront --url="$APP_URL" - console theme:change --all Storefront - console system:config:set core.frw.completedAt '2019-10-07T10:46:23+00:00' - console system:config:set core.usageData.shareUsageData false --json - console plugin:refresh - - install_all_plugins -fi diff --git a/rootfs/usr/local/shopware/functions.sh b/rootfs/usr/local/shopware/functions.sh new file mode 100644 index 0000000..7eb1b00 --- /dev/null +++ b/rootfs/usr/local/shopware/functions.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env sh + +set -e + +wait_for_mysql() { + database_host=$(trurl "$DATABASE_URL" --get '{host}') + database_port=$(trurl "$DATABASE_URL" --get '{port}') + MYSQL_WAIT_SECONDS=${MYSQL_WAIT_SECONDS:-20} + + try=0 + if [ "$MYSQL_WAIT_SECONDS" != 0 ]; then + until nc -z -v -w30 "$database_host" "${database_port:-3306}"; do + echo "Waiting for database connection..." + # wait for 5 seconds before check again + sleep 1 + + try=$((try + 1)) + + if [ $try = "$MYSQL_WAIT_SECONDS" ]; then + echo "Error: We have been waiting for database connection too long already; failing." + exit 1 + fi + done + fi +} + +console() { + php -derror_reporting=E_ALL bin/console "$@" +} + +install_all_plugins() { + list_with_updates=$(php bin/console plugin:list --json | jq 'map(select(.installedAt == null)) | .[].name' -r) + + for plugin in $list_with_updates; do + console plugin:install --activate "$plugin" + done +} + +update_all_plugins() { + list_with_updates=$(php bin/console plugin:list --json | jq 'map(select(.upgradeVersion != null)) | .[].name' -r) + + for plugin in $list_with_updates; do + php -derror_reporting=E_ALL bin/console plugin:update "$plugin" + done +} + +run_hooks() { + hook=$1 + if [ -d "/usr/local/shopware/$hook.d" ]; then + for file in "/usr/local/shopware/$hook.d"/*.sh; do + echo "Running $file for $hook" + # shellcheck source=/dev/null + . "$file" + done + fi +} diff --git a/rootfs/usr/local/shopware/setup_6.5.x b/rootfs/usr/local/shopware/setup_6.5.x new file mode 100755 index 0000000..25b9d1c --- /dev/null +++ b/rootfs/usr/local/shopware/setup_6.5.x @@ -0,0 +1,33 @@ +#!/usr/bin/env sh + +set -e +set -x + +. /usr/local/shopware/functions.sh + +if php bin/console system:config:get shopware.installed; then + run_hooks pre_update + + console system:update:finish + console plugin:refresh + + update_all_plugins + install_all_plugins + + run_hooks post_update +else + run_hooks pre_install + + # Shopware is not installed + console system:install --create-database "--shop-locale=$INSTALL_LOCALE" "--shop-currency=$INSTALL_CURRENCY" --force + console user:create "$INSTALL_ADMIN_USERNAME" --admin --password="$INSTALL_ADMIN_PASSWORD" -n + console sales-channel:create:storefront --name=Storefront --url="$APP_URL" + console theme:change --all Storefront + console system:config:set core.frw.completedAt '2019-10-07T10:46:23+00:00' + console system:config:set core.usageData.shareUsageData false --json + console plugin:refresh + + install_all_plugins + + run_hooks post_install +fi diff --git a/rootfs/usr/local/shopware/setup_6.6.x b/rootfs/usr/local/shopware/setup_6.6.x new file mode 100755 index 0000000..edf6d32 --- /dev/null +++ b/rootfs/usr/local/shopware/setup_6.6.x @@ -0,0 +1,42 @@ +#!/usr/bin/env sh + +set -e +set -x + +# shellcheck source=./functions.sh +. /usr/local/shopware/functions.sh + +wait_for_mysql + +if console system:is-installed; then + run_hooks pre_update + + if [ "${SHOPWARE_SKIP_ASSET_COPY-""}" ]; then + console system:update:finish --skip-asset-build + else + console system:update:finish + fi + + if [ "${SHOPWARE_SKIP_ASSET_COPY-""}" ]; then + console plugin:update:all + else + console plugin:update:all --skip-asset-build + fi + + install_all_plugins + + run_hooks post_update +else + run_hooks pre_install + + console system:install --create-database "--shop-locale=$INSTALL_LOCALE" "--shop-currency=$INSTALL_CURRENCY" --force + console user:create "$INSTALL_ADMIN_USERNAME" --admin --password="$INSTALL_ADMIN_PASSWORD" -n + console sales-channel:create:storefront --name=Storefront --url="$APP_URL" + console theme:change --all Storefront + console system:config:set core.frw.completedAt '2019-10-07T10:46:23+00:00' + console plugin:refresh + + install_all_plugins + + run_hooks post_install +fi