Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(prestashop): fix some bugs in image #17

Merged
merged 6 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 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 @@ -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 \
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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!


###
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
}
4 changes: 2 additions & 2 deletions images/prestashop/scripts/_cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
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"
}
46 changes: 23 additions & 23 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 @@ -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" \
Expand All @@ -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
}
11 changes: 5 additions & 6 deletions images/prestashop/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
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