Skip to content

Commit

Permalink
Feature: Remove Composer 1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
michielgerritsen committed Nov 25, 2024
1 parent 4780aee commit a7668b2
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 13 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/magento-2.3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ jobs:
- { PHP_VERSION: php72-fpm, MAGENTO_VERSION: 2.3.5-p1, SAMPLE_DATA: true }
- { PHP_VERSION: php73-fpm, MAGENTO_VERSION: 2.3.5-p1, SAMPLE_DATA: false }
- { PHP_VERSION: php73-fpm, MAGENTO_VERSION: 2.3.5-p1, SAMPLE_DATA: true }
- { PHP_VERSION: php72-fpm, MAGENTO_VERSION: 2.3.4, SAMPLE_DATA: false }
- { PHP_VERSION: php72-fpm, MAGENTO_VERSION: 2.3.4, SAMPLE_DATA: true }
- { PHP_VERSION: php73-fpm, MAGENTO_VERSION: 2.3.4, SAMPLE_DATA: false }
- { PHP_VERSION: php73-fpm, MAGENTO_VERSION: 2.3.4, SAMPLE_DATA: true }
# 2.3.4 is disabled as I get a lot of these errors after switchting to Composer 2:
# Problem 1
# - Root composer.json requires zendframework/zend-barcode == 2.8.0.0 -> satisfiable by laminas/laminas-barcode[2.8.0].
# - laminas/laminas-barcode 2.8.0 requires laminas/laminas-zendframework-bridge ^1.0 -> found laminas/laminas-zendframework-bridge[1.0.0, ..., 1.8.0] but these were not loaded, likely because it conflicts with another require.
# - { PHP_VERSION: php72-fpm, MAGENTO_VERSION: 2.3.4, SAMPLE_DATA: false }
# - { PHP_VERSION: php72-fpm, MAGENTO_VERSION: 2.3.4, SAMPLE_DATA: true }
# - { PHP_VERSION: php73-fpm, MAGENTO_VERSION: 2.3.4, SAMPLE_DATA: false }
# - { PHP_VERSION: php73-fpm, MAGENTO_VERSION: 2.3.4, SAMPLE_DATA: true }
- { PHP_VERSION: php72-fpm, MAGENTO_VERSION: 2.3.3, SAMPLE_DATA: false }
- { PHP_VERSION: php72-fpm, MAGENTO_VERSION: 2.3.3, SAMPLE_DATA: true }
- { PHP_VERSION: php73-fpm, MAGENTO_VERSION: 2.3.3, SAMPLE_DATA: false }
Expand Down
24 changes: 20 additions & 4 deletions magento/Dockerfile-2.3
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,55 @@ ARG SAMPLE_DATA=false
ENV CI=true
ENV URL=http://localhost/
ENV FLAT_TABLES=false
ENV COMPOSER_VERSION=1

COPY scripts/retry retry
COPY scripts/install-phpstan.php scripts/install-phpstan.php
COPY scripts/upgrade-to-composer-2.php scripts/upgrade-to-composer-2.php
COPY scripts/allow-composer-plugins.php scripts/allow-composer-plugins.php
COPY patches/vertex-compilation-issue.patch vertex-compilation-issue.patch
COPY patches/APSB22-12/MDVA-43395_EE_2.4.3-p1_COMPOSER_v1.patch MDVA-43395_EE_2.4.3-p1_COMPOSER_v1.patch
COPY patches/APSB22-12/MDVA-43443_EE_2.3.4_COMPOSER_v1.patch MDVA-43443_EE_2.3.4_COMPOSER_v1.patch
COPY patches/APSB22-12/MDVA-43443_EE_2.4.2-p2_COMPOSER_v1.patch MDVA-43443_EE_2.4.2-p2_COMPOSER_v1.patch
COPY templates/memory-limit-php.ini /usr/local/etc/php/conf.d/memory-limit-php.ini

RUN ./start-services && \
composer self-update --2 && \
echo "[cad] Composer version:" && \
composer --version && \
echo "[cad] Downloading & unzipping Magento" && \
curl -o magento.zip https://repo-magento-mirror.fooman.co.nz/dist/magento/$MAGENTO_TYPE/magento-$MAGENTO_TYPE-$MAGENTO_VERSION.zip && \
unzip -q magento.zip -d . && \
rm magento.zip && \
echo "[cad] Allowing composer plugins" && \
php scripts/allow-composer-plugins.php && \
rm scripts/allow-composer-plugins.php && \
echo "[cad] Upgrading to composer 2" && \
php scripts/upgrade-to-composer-2.php && \
rm scripts/upgrade-to-composer-2.php && \
composer config --unset repositories.0 && \
composer config repositories.fooman composer https://repo-magento-mirror.fooman.co.nz/ && \
echo "[cad] Running Composer install" && \
./retry "composer install" && \
echo "[cad] Updating XML" && \
if [ -f "/data/vendor/magento/module-inventory-catalog/etc/communication.xml" ]; then sed -i 's/is_synchronous="false"//g' /data/vendor/magento/module-inventory-catalog/etc/communication.xml; fi && \
if [ -f "/data/vendor/magento/module-inventory-sales/etc/communication.xml" ]; then sed -i 's/is_synchronous="false"//g' /data/vendor/magento/module-inventory-sales/etc/communication.xml; fi && \
if [ -f "/data/vendor/magento/module-inventory-indexer/etc/communication.xml" ]; then sed -i 's/is_synchronous="false"//g' /data/vendor/magento/module-inventory-indexer/etc/communication.xml; fi && \
echo "[cad] Running Magento setup:install" && \
php bin/magento setup:install --backend-frontname=admin --session-save=db --db-host=127.0.0.1 --db-name=magento --db-user=magento --db-password=password --base-url=http://localhost --timezone=Europe/Amsterdam --currency=EUR --admin-user=exampleuser --admin-password=examplepassword123 [email protected] --admin-firstname=Example --admin-lastname=Example --use-rewrites=1 --use-sample-data && \
echo "[cad] Setting developer mode" && \
php bin/magento deploy:mode:set developer && \
sed -i 's/\$lastUpdatedTime = strtotime(\$lastUpdatedTime);/\$lastUpdatedTime = \$lastUpdatedTime === null ? 0 : strtotime(\$lastUpdatedTime);/' vendor/magento/module-security/Model/AdminSessionInfo.php && \
echo "[cad] Applying patches" && \
if (( $(php -r 'echo version_compare(getenv("MAGENTO_VERSION"), "2.3.3", ">") ? "true" : "false";') = "true" )); then echo "applying MDVA-43395_EE_2.4.3-p1_COMPOSER_v1.patch"; git apply MDVA-43395_EE_2.4.3-p1_COMPOSER_v1.patch; fi && \
if (( $(php -r 'echo version_compare(getenv("MAGENTO_VERSION"), "2.3.3-p1", ">=") && version_compare(getenv("MAGENTO_VERSION"), "2.3.4", "<=") ? "true" : "false";') = "true" )); then echo "applying MDVA-43443_EE_2.3.4_COMPOSER_v1.patch"; git apply MDVA-43443_EE_2.3.4_COMPOSER_v1.patch; fi && \
if (( $(php -r 'echo version_compare(getenv("MAGENTO_VERSION"), "2.3.4-p2", ">=") ? "true" : "false";') = "true" )); then echo "applying MDVA-43443_EE_2.4.2-p2_COMPOSER_v1.patch"; git apply MDVA-43443_EE_2.4.2-p2_COMPOSER_v1.patch; fi && \
if (( $(php -r 'echo substr(getenv("MAGENTO_VERSION"), 0, 5) == "2.3.3" ? "true" : "false";') = "true" )); then echo "applying vertex-compilation-issue.patch"; git apply vertex-compilation-issue.patch; fi && \
echo "Running scconnector_google_remove_cl queries" && \
echo "[cad] Running scconnector_google_remove_cl queries" && \
mysql -u root magento -e 'CREATE TABLE IF NOT EXISTS `scconnector_google_remove_cl` (`version_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT "Version ID", `entity_id` int(10) unsigned NOT NULL DEFAULT "0" COMMENT "Entity ID", PRIMARY KEY (`version_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT="scconnector_google_remove_cl";' && \
mysql -u root magento -e 'INSERT INTO `scconnector_google_remove_cl` (`version_id`, `entity_id`) VALUES ('1', '1');' && \
mysql -u root magento -e 'alter table `scconnector_google_remove_cl` auto_increment = 1;' && \
if [ "${SAMPLE_DATA}" = "true" ]; then echo "Running php bin/magento sampledata:deploy"; php bin/magento sampledata:deploy; fi && \
if [ "${SAMPLE_DATA}" = "true" ]; then echo "Running setup:upgrade" && (php bin/magento setup:upgrade || php bin/magento setup:upgrade || php bin/magento setup:upgrade); fi && \
if [ "${SAMPLE_DATA}" = "true" ]; then echo "[cad] Running php bin/magento sampledata:deploy"; php bin/magento sampledata:deploy; fi && \
if [ "${SAMPLE_DATA}" = "true" ]; then echo "[cad] Running setup:upgrade" && (php bin/magento setup:upgrade || php bin/magento setup:upgrade || php bin/magento setup:upgrade); fi && \
php bin/magento setup:static-content:deploy en_US -f -j 12 && \
php bin/magento setup:di:compile && \
php bin/magento indexer:reindex && \
Expand Down
21 changes: 16 additions & 5 deletions magento/Dockerfile-2.4
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,46 @@ COPY scripts/retry retry
COPY patches/ patches/
COPY scripts/apply-2.4-patches.php scripts/apply-2.4-patches.php
COPY scripts/downgrade-monolog.php scripts/downgrade-monolog.php
COPY scripts/upgrade-to-composer-2.php scripts/upgrade-to-composer-2.php
COPY scripts/allow-composer-plugins.php scripts/allow-composer-plugins.php
COPY scripts/remove-paypal-braintree.php scripts/remove-paypal-braintree.php
COPY scripts/patch-AC2855.php scripts/patch-AC2855.php
COPY templates/memory-limit-php.ini /usr/local/etc/php/conf.d/memory-limit-php.ini

RUN ./start-services && \
if (( $(php -r 'echo version_compare(getenv("MAGENTO_VERSION"), "2.4.2", "<=") ? "true" : "false";') = "true" )); then composer self-update --1; else composer self-update --2; fi && \
echo "Composer version:" && \
composer self-update --2 && \
echo "[cad] Composer version:" && \
composer --version && \
echo "[cad] Downloading & unzipping Magento" && \
curl -o magento.zip https://repo-magento-mirror.fooman.co.nz/dist/magento/$MAGENTO_TYPE/magento-$MAGENTO_TYPE-$MAGENTO_VERSION.zip && \
unzip -q magento.zip -d . && \
rm magento.zip && \
if (( $(php -r 'echo version_compare(getenv("MAGENTO_VERSION"), "2.4.2", "<=") ? "true" : "false";') = "true" )); then echo "Using Composer version 1 so skipping allow-plugins"; else php scripts/allow-composer-plugins.php rm scripts/allow-composer-plugins.php; fi && \
echo "[cad] Allowing composer plugins" && \
php scripts/allow-composer-plugins.php && \
rm scripts/allow-composer-plugins.php && \
echo "[cad] Upgrading to composer 2" && \
php scripts/upgrade-to-composer-2.php && \
rm scripts/upgrade-to-composer-2.php && \
composer config --unset repositories.0 && \
composer config repositories.fooman composer https://repo-magento-mirror.fooman.co.nz/ && \
if [ "$MAGENTO_VERSION" = "2.4.4" ]; then composer require "magento/security-package:1.1.3-p1 as 1.1.3" --no-update; fi && \
if [ "$MAGENTO_VERSION" = "2.4.4" ]; then composer require "magento/inventory-metapackage:1.2.4-p1 as 1.2.4" --no-update; fi && \
echo "[cad] Running Composer install" && \
./retry "composer install" && \
php scripts/patch-AC2855.php && \
php scripts/downgrade-monolog.php && \
php scripts/remove-paypal-braintree.php && \
echo "[cad] Updating XML" && \
if [ -f "/data/vendor/magento/module-inventory-catalog/etc/communication.xml" ]; then sed -i 's/is_synchronous="false"//g' /data/vendor/magento/module-inventory-catalog/etc/communication.xml; fi && \
if [ -f "/data/vendor/magento/module-inventory-sales/etc/communication.xml" ]; then sed -i 's/is_synchronous="false"//g' /data/vendor/magento/module-inventory-sales/etc/communication.xml; fi && \
if [ -f "/data/vendor/magento/module-inventory-indexer/etc/communication.xml" ]; then sed -i 's/is_synchronous="false"//g' /data/vendor/magento/module-inventory-indexer/etc/communication.xml; fi && \
composer dump-autoload && \
echo "[cad] Running Magento setup:install" && \
php bin/magento setup:install --backend-frontname=admin --session-save=db --db-host=127.0.0.1 --db-name=magento --db-user=magento --db-password=password --base-url=http://localhost --timezone=Europe/Amsterdam --currency=EUR --admin-user=exampleuser --admin-password=examplepassword123 [email protected] --admin-firstname=Example --admin-lastname=Example --use-rewrites=1 --use-sample-data && \
echo "[cad] Setting developer mode" && \
php bin/magento deploy:mode:set developer && \
if [ "${SAMPLE_DATA}" = "true" ]; then php bin/magento sampledata:deploy; fi && \
if [ "${SAMPLE_DATA}" = "true" ]; then php bin/magento setup:upgrade; fi && \
if [ "${SAMPLE_DATA}" = "true" ]; then echo "[cad] Running php bin/magento sampledata:deploy"; php bin/magento sampledata:deploy; fi && \
if [ "${SAMPLE_DATA}" = "true" ]; then echo "[cad] Running setup:upgrade" && (php bin/magento setup:upgrade || php bin/magento setup:upgrade || php bin/magento setup:upgrade); fi && \
php bin/magento setup:static-content:deploy en_US -f -j 12 && \
php bin/magento setup:di:compile && \
php bin/magento indexer:reindex && \
Expand Down
1 change: 1 addition & 0 deletions magento/scripts/retry
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cmd=$1

# Execute the command until it succeeds or the maximum number of retries is reached
while ! eval $cmd && [ $retries -lt $max_retries ]; do
echo "Command failed. Retry attempt $retries"
retries=$((retries+1))
sleep 1
done
Expand Down
51 changes: 51 additions & 0 deletions magento/scripts/upgrade-to-composer-2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

$isPhp72OrLower = version_compare(PHP_VERSION, '7.2', '>=');

$version = getenv('MAGENTO_VERSION');
$is230 = substr($version, 0, 5) == '2.3.0';
$is231 = substr($version, 0, 5) == '2.3.1';
$is232 = substr($version, 0, 5) == '2.3.2';
$is233 = substr($version, 0, 5) == '2.3.3';
$is234 = substr($version, 0, 5) == '2.3.4';
$is235 = substr($version, 0, 5) == '2.3.5';
$is236 = substr($version, 0, 5) == '2.3.6';
$is237 = substr($version, 0, 5) == '2.3.7';
$is240 = substr($version, 0, 5) == '2.4.0';
$is241 = substr($version, 0, 5) == '2.4.1';
$is242 = substr($version, 0, 5) == '2.4.2';
$is243 = substr($version, 0, 5) == '2.4.3';
$is244 = substr($version, 0, 5) == '2.4.4';
$is245 = substr($version, 0, 5) == '2.4.5';
$is246 = substr($version, 0, 5) == '2.4.6';
$is247 = substr($version, 0, 5) == '2.4.7';

if ($is230 || $is231 || $is232 || $is233) {
run('composer require magento/inventory-composer-installer:"1.2.0 as 1.1.0" --no-update');
return;
}

$laminasDependencyPluginVersion = "2.1.2 as 1.0.4";
if ($isPhp72OrLower) {
$laminasDependencyPluginVersion = "2.0.0 as 1.0.4";
}

if ($is234 || $is235 || $is236 || $is240 || $is241) {
run('composer require laminas/laminas-dependency-plugin:"' . $laminasDependencyPluginVersion . '" --no-update');
run('composer require magento/inventory-composer-installer:"1.2.0 as 1.1.0" --no-update');
run('composer require --dev dealerdirect/phpcodesniffer-composer-installer:^0.7.0 --no-update');
return;
}

function run(string $command) {
echo 'Running command ' . $command . PHP_EOL;

$output = null;
$code = null;
exec($command, $output, $code);

if ($code !== 0) {
echo 'Error while running "' . $command . '"' . PHP_EOL;
die($code);
}
}

0 comments on commit a7668b2

Please sign in to comment.