Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow hooks in the docker image
Browse files Browse the repository at this point in the history
shyim committed Jan 24, 2024

Verified

This commit was signed with the committer’s verified signature.
shyim Shyim
1 parent af754e9 commit 5d3a47d
Showing 7 changed files with 138 additions and 135 deletions.
1 change: 1 addition & 0 deletions .github/workflows/shell-lint.yml
Original file line number Diff line number Diff line change
@@ -17,3 +17,4 @@ jobs:

- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
working-directory: rootfs
8 changes: 4 additions & 4 deletions rootfs/setup
Original file line number Diff line number Diff line change
@@ -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=./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=./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.

57 changes: 57 additions & 0 deletions rootfs/usr/local/shopware/functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/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" ]; then
for file in "/usr/local/shopware/$hook"/*.sh; do
if [ -x "$file" ]; then
echo "Running $file for $hook"
"$file"
fi
done
fi
}
34 changes: 34 additions & 0 deletions rootfs/usr/local/shopware/setup_6.5.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/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

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
php -derror_reporting=E_ALL bin/console theme:compile

run_hooks post-update
else
run_hooks pre-install

# 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

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 5d3a47d

Please sign in to comment.