diff --git a/images/prestashop/Dockerfile b/images/prestashop/Dockerfile index 1ad485b..b4930e2 100644 --- a/images/prestashop/Dockerfile +++ b/images/prestashop/Dockerfile @@ -1,10 +1,11 @@ ARG NODE_VERSION="16" ARG PHP_VERSION="8.1" +ARG YARN_VERSION="3" ########## # Node ########## -FROM node:${NODE_VERSION}-alpine AS node +FROM ghcr.io/myparcelnl/node:${NODE_VERSION}-yarn${YARN_VERSION} AS node ########## @@ -12,11 +13,15 @@ FROM node:${NODE_VERSION}-alpine AS node ########## FROM ghcr.io/myparcelnl/php-xd:${PHP_VERSION}-fpm-alpine AS prestashop +ENV YARN_IGNORE_NODE=1 + COPY --from=node /opt/ /opt/ COPY --from=node /usr/lib /usr/lib COPY --from=node /usr/local/bin /usr/local/bin COPY --from=node /usr/local/include /usr/local/include COPY --from=node /usr/local/lib /usr/local/lib +COPY --from=node /root/.npmrc /root/.npmrc +COPY --from=node /root/.yarnrc.yml /root/.yarnrc.yml ARG PS_VERSION="8.0.4" @@ -44,6 +49,8 @@ RUN PHP_VERSION="$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;")" && \ jq \ # For cloning prestashop git \ + # for node-gyp + python3 \ $PHPIZE_DEPS \ && \ # Configure php extensions \ @@ -80,10 +87,6 @@ RUN PHP_VERSION="$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;")" && \ rm -rf vendor && \ # Set composer cache location composer config --global cache-dir /tmp/.cache/composer && \ - # Set npm cache location - npm config set cache /tmp/.cache/npm && \ - # Set yarn cache location - yarn config set cache-folder /tmp/.cache/yarn && \ # Reset permissions chown -R www-data . && \ # Clear cache and unnecessary dependencies @@ -96,17 +99,18 @@ COPY ./config/php-fpm /usr/local/etc/php-fpm.d COPY ./config/php /usr/local/etc/php COPY ./scripts/ /tmp/scripts +ENV PHP_VERSION=${PHP_VERSION} ENV PS_VERSION=${PS_VERSION} -ENV ROOT_DIR=${ROOT_DIR} - - ### # Core ### ENV BASE_URL=prestashop.dev.myparcel.nl ENV FULL_URL=https://${BASE_URL} -ENV ROOT_DIR=/var/www/html +ENV ROOT_DIR=${ROOT_DIR} + +ENV TMP_MODULES_DIR="/tmp/modules" +ENV PS_MODULES_DIR="$ROOT_DIR/modules" ### # Database @@ -133,7 +137,7 @@ ENV PS_FOLDER_ADMIN=admin1 # Admin credentials ENV PS_ADMIN_MAIL=admin@${BASE_URL} -ENV PS_ADMIN_PASSWORD=admin +ENV PS_ADMIN_PASSWORD=admin123! ### diff --git a/images/prestashop/scripts/_build-themes.sh b/images/prestashop/scripts/_build-themes.sh index 9054e8a..f1d5a89 100755 --- a/images/prestashop/scripts/_build-themes.sh +++ b/images/prestashop/scripts/_build-themes.sh @@ -1,24 +1,25 @@ #!/usr/bin/env bash -# Some super hacky changes needed to be able to compile the scss of admin-dev/themes/new-theme with sass^1 :( -fix-files() { - sed -i 's/@extend a:hover;/@extend a, :hover;/' './admin-dev/themes/new-theme/node_modules/prestakit/scss/_breadcrumb.scss' || true - sed -i 's/@extend .btn-primary:disabled;/@extend .btn-primary, :disabled;/' './admin-dev/themes/new-theme/node_modules/prestakit/scss/_custom-forms.scss' || true - sed -i 's/ - 2;/;/' './admin-dev/themes/new-theme/node_modules/select2-bootstrap-theme/src/select2-bootstrap.scss' || true -} - build-themes() { h2 "Building themes..." - if major-version-is 1; then - YARN_IGNORE_NODE=1 yarn set version 3.6.4 + # Remove legacy node-sass and replace with dart-sass (sass) + find . -type f -name 'package.json' -not \( -path '*/node_modules/*' -o -path '*/vendor/*' \) -exec \ + sed -i 's/"node-sass": ".*"/"sass": "^1"/g' {} \; - yarn config set --home enableTelemetry 0 + # If using sass-embedded, must update to >=1.77.0 to work on ARM + find . -type f -name 'package.json' -not \( -path '*/node_modules/*' -o -path '*/vendor/*' \) -exec \ + sed -i 's/"sass-embedded": ".*"/"sass-embedded": "^1.77.0"/g' {} \; - yarn config set enableGlobalCache true - yarn config set globalFolder /tmp/.cache/yarn + # npm install is run through via make install, so add postinstall hooks to modify files in node_modules after npm install + # shellcheck disable=SC2038 + find . -type f -name 'package.json' -not \( -path '*/node_modules/*' -o -path '*/vendor/*' \) -exec \ + dirname {} \; | xargs -I {} sh -c 'cd {}; npm pkg set "scripts.postinstall=sh /tmp/scripts/fix-sass.sh"' + + if major-version-is 1; then yarn config set logFilters --json '[ {"code":"YN0060","level":"discard"}, {"code":"YN0002","level":"discard"} ]' yarn config set nodeLinker node-modules + yarn config set nmHoistingLimits workspaces yarn plugin import workspace-tools @@ -29,60 +30,19 @@ build-themes() { "workspaces[]=themes" \ "workspaces[]=themes/**" - yarn config set nmHoistingLimits workspaces - - # Replace node-sass with sass in all workspaces - yarn workspaces foreach -pv --exclude root exec npm pkg delete \ - devDependencies.node-sass \ - dependencies.node-sass \ - peerDependencies.node-sass - yarn workspaces foreach -pv --exclude root exec npm pkg set devDependencies.sass=^1 - yarn install - fix-files - yarn workspaces foreach -pv --exclude root exec npm pkg set "scripts.build:dev=NODE_ENV=development webpack --mode development" yarn workspaces foreach -pv --exclude root run build:dev - - if [ "$?" -eq 0 ]; then - h2 "Built themes." - else - h2 "One or more themes failed to build." - fi fi if major-version-is 8; then - workspaces=$(find themes admin-dev -type f -name package.json -not -path "*/node_modules/*" -not -path "*/vendor/*" -exec dirname {} \;) - - for workspace in $workspaces; do - cd "$workspace" || exit 1 - h2 "Installing $workspace..." - - npm pkg delete devDependencies.node-sass - npm pkg delete dependencies.node-sass - npm pkg set devDependencies.sass=^1 - - npm install --legacy-peer-deps - - cd - || exit 1 - done - - fix-files - - for workspace in $workspaces; do - cd "$workspace" || exit 1 - h2 "Building $workspace..." - - npm run build - - if [ "$?" -ne 0 ]; then - h2 "Failed to build $workspace." - else - h2 "Done building $workspace." - fi + make install + fi - cd - || exit 1 - done + if [ "$?" -eq 0 ]; then + h2 "Built themes." + else + h2 "One or more themes failed to build." fi } diff --git a/images/prestashop/scripts/_cache.sh b/images/prestashop/scripts/_cache.sh index 1f9908e..db2f78b 100644 --- a/images/prestashop/scripts/_cache.sh +++ b/images/prestashop/scripts/_cache.sh @@ -2,10 +2,10 @@ clear-cache() { h2 "Clearing cache..." - sudo -u www-data -s php bin/console cache:clear + sudo -u www-data -s php bin/console cache:clear --no-warmup } warmup-cache() { h2 "Warming up cache..." - sudo -u www-data -s php bin/console cache:warmup + sudo -u www-data -s php bin/console cache:warmup --no-optional-warmers } diff --git a/images/prestashop/scripts/_dependencies.sh b/images/prestashop/scripts/_dependencies.sh deleted file mode 100755 index ab7bd30..0000000 --- a/images/prestashop/scripts/_dependencies.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -install-dependencies-composer() { - composer install \ - --no-interaction \ - --no-suggest \ - "$@" -} - -install-dependencies-node() { - yarn install "$@" -} diff --git a/images/prestashop/scripts/_install-cli.sh b/images/prestashop/scripts/_install-cli.sh new file mode 100644 index 0000000..f3d5c68 --- /dev/null +++ b/images/prestashop/scripts/_install-cli.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +install-cli() { + h1 "Installing CLI dependencies" + + composer install --no-plugins --no-interaction --working-dir="/cli" +} diff --git a/images/prestashop/scripts/_install-prestashop.sh b/images/prestashop/scripts/_install-prestashop.sh index 152c864..cd1907d 100644 --- a/images/prestashop/scripts/_install-prestashop.sh +++ b/images/prestashop/scripts/_install-prestashop.sh @@ -3,6 +3,12 @@ install-prestashop() { h1 "Starting PrestaShop installation" + if ! wait-for-it -q -t 0 "$DB_HOST:$DB_PORT"; then + h2 "Waiting for database..." + wait-for-it -q -t 30 "$DB_HOST:$DB_PORT" + h2 "Database is ready." + fi + if [ -f ./config/settings.inc.php ] && [ -f install.lock ]; then h2 "PrestaShop is installed, but install.lock is still present. Installation may not have been successful." exit 1 @@ -15,40 +21,36 @@ install-prestashop() { fi touch install.lock + start=$(date +%s) - install-dependencies-node - install-dependencies-composer - - if [ $PS_FOLDER_ADMIN != "admin" ] && [ -d "${ROOT_DIR}/admin" ]; then + if [ "$PS_FOLDER_ADMIN" != "admin" ] && [ -d "${ROOT_DIR}/admin" ]; then h2 "Renaming admin folder to $PS_FOLDER_ADMIN..."; sudo -u www-data -s mv "${ROOT_DIR}/admin" "${ROOT_DIR}/$PS_FOLDER_ADMIN/" fi - if ! wait-for-it -q -t 0 "$DB_HOST:$DB_PORT"; then - h2 "Waiting for database..." - wait-for-it -q -t 30 "$DB_HOST:$DB_PORT" - h2 "Database is ready." - fi + h2 "Installing dependencies..." + composer install --no-plugins --no-interaction + + build-themes reset-permissions - h2 "Installing PrestaShop, this can take +/- 1 minute..." - start=`date +%s` + h2 "Running PrestaShop installation script..." sudo -u www-data -s php install-dev/index_cli.php \ - --all_languages=$PS_ALL_LANGUAGES \ - --country=$PS_COUNTRY \ + --all_languages="$PS_ALL_LANGUAGES" \ + --country="$PS_COUNTRY" \ --domain="$PS_DOMAIN" \ - --language=$PS_LANGUAGE \ + --language="$PS_LANGUAGE" \ --newsletter=0 \ --send_email=0 \ - --ssl=$PS_ENABLE_SSL \ + --ssl="$PS_ENABLE_SSL" \ --email="$PS_ADMIN_MAIL" \ --firstname="Mr." \ --lastname="Parcel" \ - --password=$PS_ADMIN_PASSWORD \ - --db_clear=$PS_DB_CLEAR \ - --db_create=$PS_DB_CREATE \ + --password="$PS_ADMIN_PASSWORD" \ + --db_clear="$PS_DB_CLEAR" \ + --db_create="$PS_DB_CREATE" \ --db_name="$DB_NAME" \ --db_password="$DB_PASSWORD" \ --db_server="$DB_HOST" \ @@ -61,13 +63,11 @@ install-prestashop() { exit 1 fi - build-themes - - reset-permissions - - end=`date +%s` + end=$(date +%s) runtime=$((end-start)) h2 "PrestaShop installation succeeded in $runtime seconds." rm install.lock + + reset-permissions } diff --git a/images/prestashop/scripts/entrypoint.sh b/images/prestashop/scripts/entrypoint.sh index 5f88858..0329bec 100755 --- a/images/prestashop/scripts/entrypoint.sh +++ b/images/prestashop/scripts/entrypoint.sh @@ -1,24 +1,23 @@ #!/bin/bash -export TMP_MODULES_DIR="/tmp/modules" -export PS_MODULES_DIR="$ROOT_DIR/modules" - for script in /tmp/scripts/_*; do source $script; done # Start php fpm in the background in advance. start-php-fpm +install-cli install-prestashop install-modules add-preset-data +reset-permissions + clear-cache warmup-cache reset-permissions -tail-logs - h1 "🐧 PrestaShop is ready at ${FULL_URL} ✨" -sleep infinity + +tail-logs diff --git a/images/prestashop/scripts/fix-sass.sh b/images/prestashop/scripts/fix-sass.sh new file mode 100644 index 0000000..76c5448 --- /dev/null +++ b/images/prestashop/scripts/fix-sass.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +cd "${ROOT_DIR}" || exit 1 + +# Some super hacky changes needed to be able to compile the scss of admin-dev/themes/new-theme with sass^1 :( +sed -i 's/@extend a:hover;/@extend a, :hover;/' './admin-dev/themes/new-theme/node_modules/prestakit/scss/_breadcrumb.scss' || true +sed -i 's/@extend .btn-primary:disabled;/@extend .btn-primary, :disabled;/' './admin-dev/themes/new-theme/node_modules/prestakit/scss/_custom-forms.scss' || true +sed -i 's/ - 2;/;/' './admin-dev/themes/new-theme/node_modules/select2-bootstrap-theme/src/select2-bootstrap.scss' || true