Skip to content

Commit

Permalink
fix: fix more issues with prestashop image
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Sep 19, 2024
1 parent 5f6b90f commit 79b1e7b
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 95 deletions.
11 changes: 6 additions & 5 deletions images/prestashop/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
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


##########
# Prestashop
##########
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"

Expand Down Expand Up @@ -80,10 +85,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
Expand Down
78 changes: 19 additions & 59 deletions images/prestashop/scripts/_build-themes.sh
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
}
12 changes: 0 additions & 12 deletions images/prestashop/scripts/_dependencies.sh

This file was deleted.

7 changes: 7 additions & 0 deletions images/prestashop/scripts/_install-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

install-cli() {
h1 "Installing CLI dependencies"

composer install --no-plugins --no-interaction --working-dir="/cli"
}
37 changes: 18 additions & 19 deletions images/prestashop/scripts/_install-prestashop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,39 +22,32 @@ install-prestashop() {

touch install.lock

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

reset-permissions

h2 "Installing PrestaShop, this can take +/- 1 minute..."
start=`date +%s`
start=$(date +%s)

composer install --no-plugins --no-interaction

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" \
Expand All @@ -65,7 +64,7 @@ install-prestashop() {

reset-permissions

end=`date +%s`
end=$(date +%s)
runtime=$((end-start))

h2 "PrestaShop installation succeeded in $runtime seconds."
Expand Down
1 change: 1 addition & 0 deletions images/prestashop/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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

Expand Down
8 changes: 8 additions & 0 deletions images/prestashop/scripts/fix-sass.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 79b1e7b

Please sign in to comment.