Skip to content

Commit

Permalink
Merge pull request #60 from shopware/allow-hooks
Browse files Browse the repository at this point in the history
feat: allow hooks in the docker image
  • Loading branch information
shyim authored Jan 24, 2024
2 parents af754e9 + d3987d8 commit feab9f5
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 135 deletions.
1 change: 1 addition & 0 deletions .shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
external-sources=true
8 changes: 4 additions & 4 deletions rootfs/setup
Original file line number Diff line number Diff line change
Expand Up @@ -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
65 changes: 0 additions & 65 deletions rootfs/setup_6.5.x

This file was deleted.

66 changes: 0 additions & 66 deletions rootfs/setup_6.6.x

This file was deleted.

56 changes: 56 additions & 0 deletions rootfs/usr/local/shopware/functions.sh
Original file line number Diff line number Diff line change
@@ -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
}
33 changes: 33 additions & 0 deletions rootfs/usr/local/shopware/setup_6.5.x
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions rootfs/usr/local/shopware/setup_6.6.x
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit feab9f5

Please sign in to comment.