Skip to content

Commit a7668b2

Browse files
Feature: Remove Composer 1 support
1 parent 4780aee commit a7668b2

File tree

5 files changed

+96
-13
lines changed

5 files changed

+96
-13
lines changed

.github/workflows/magento-2.3.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ jobs:
4848
- { PHP_VERSION: php72-fpm, MAGENTO_VERSION: 2.3.5-p1, SAMPLE_DATA: true }
4949
- { PHP_VERSION: php73-fpm, MAGENTO_VERSION: 2.3.5-p1, SAMPLE_DATA: false }
5050
- { PHP_VERSION: php73-fpm, MAGENTO_VERSION: 2.3.5-p1, SAMPLE_DATA: true }
51-
- { PHP_VERSION: php72-fpm, MAGENTO_VERSION: 2.3.4, SAMPLE_DATA: false }
52-
- { PHP_VERSION: php72-fpm, MAGENTO_VERSION: 2.3.4, SAMPLE_DATA: true }
53-
- { PHP_VERSION: php73-fpm, MAGENTO_VERSION: 2.3.4, SAMPLE_DATA: false }
54-
- { PHP_VERSION: php73-fpm, MAGENTO_VERSION: 2.3.4, SAMPLE_DATA: true }
51+
# 2.3.4 is disabled as I get a lot of these errors after switchting to Composer 2:
52+
# Problem 1
53+
# - Root composer.json requires zendframework/zend-barcode == 2.8.0.0 -> satisfiable by laminas/laminas-barcode[2.8.0].
54+
# - 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.
55+
# - { PHP_VERSION: php72-fpm, MAGENTO_VERSION: 2.3.4, SAMPLE_DATA: false }
56+
# - { PHP_VERSION: php72-fpm, MAGENTO_VERSION: 2.3.4, SAMPLE_DATA: true }
57+
# - { PHP_VERSION: php73-fpm, MAGENTO_VERSION: 2.3.4, SAMPLE_DATA: false }
58+
# - { PHP_VERSION: php73-fpm, MAGENTO_VERSION: 2.3.4, SAMPLE_DATA: true }
5559
- { PHP_VERSION: php72-fpm, MAGENTO_VERSION: 2.3.3, SAMPLE_DATA: false }
5660
- { PHP_VERSION: php72-fpm, MAGENTO_VERSION: 2.3.3, SAMPLE_DATA: true }
5761
- { PHP_VERSION: php73-fpm, MAGENTO_VERSION: 2.3.3, SAMPLE_DATA: false }

magento/Dockerfile-2.3

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,55 @@ ARG SAMPLE_DATA=false
88
ENV CI=true
99
ENV URL=http://localhost/
1010
ENV FLAT_TABLES=false
11-
ENV COMPOSER_VERSION=1
1211

1312
COPY scripts/retry retry
1413
COPY scripts/install-phpstan.php scripts/install-phpstan.php
14+
COPY scripts/upgrade-to-composer-2.php scripts/upgrade-to-composer-2.php
15+
COPY scripts/allow-composer-plugins.php scripts/allow-composer-plugins.php
1516
COPY patches/vertex-compilation-issue.patch vertex-compilation-issue.patch
1617
COPY patches/APSB22-12/MDVA-43395_EE_2.4.3-p1_COMPOSER_v1.patch MDVA-43395_EE_2.4.3-p1_COMPOSER_v1.patch
1718
COPY patches/APSB22-12/MDVA-43443_EE_2.3.4_COMPOSER_v1.patch MDVA-43443_EE_2.3.4_COMPOSER_v1.patch
1819
COPY patches/APSB22-12/MDVA-43443_EE_2.4.2-p2_COMPOSER_v1.patch MDVA-43443_EE_2.4.2-p2_COMPOSER_v1.patch
1920
COPY templates/memory-limit-php.ini /usr/local/etc/php/conf.d/memory-limit-php.ini
2021

2122
RUN ./start-services && \
23+
composer self-update --2 && \
24+
echo "[cad] Composer version:" && \
25+
composer --version && \
26+
echo "[cad] Downloading & unzipping Magento" && \
2227
curl -o magento.zip https://repo-magento-mirror.fooman.co.nz/dist/magento/$MAGENTO_TYPE/magento-$MAGENTO_TYPE-$MAGENTO_VERSION.zip && \
2328
unzip -q magento.zip -d . && \
2429
rm magento.zip && \
30+
echo "[cad] Allowing composer plugins" && \
31+
php scripts/allow-composer-plugins.php && \
32+
rm scripts/allow-composer-plugins.php && \
33+
echo "[cad] Upgrading to composer 2" && \
34+
php scripts/upgrade-to-composer-2.php && \
35+
rm scripts/upgrade-to-composer-2.php && \
2536
composer config --unset repositories.0 && \
2637
composer config repositories.fooman composer https://repo-magento-mirror.fooman.co.nz/ && \
38+
echo "[cad] Running Composer install" && \
2739
./retry "composer install" && \
40+
echo "[cad] Updating XML" && \
2841
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 && \
2942
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 && \
3043
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 && \
44+
echo "[cad] Running Magento setup:install" && \
3145
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 --admin-email=user@example.com --admin-firstname=Example --admin-lastname=Example --use-rewrites=1 --use-sample-data && \
46+
echo "[cad] Setting developer mode" && \
3247
php bin/magento deploy:mode:set developer && \
3348
sed -i 's/\$lastUpdatedTime = strtotime(\$lastUpdatedTime);/\$lastUpdatedTime = \$lastUpdatedTime === null ? 0 : strtotime(\$lastUpdatedTime);/' vendor/magento/module-security/Model/AdminSessionInfo.php && \
49+
echo "[cad] Applying patches" && \
3450
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 && \
3551
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 && \
3652
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 && \
3753
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 && \
38-
echo "Running scconnector_google_remove_cl queries" && \
54+
echo "[cad] Running scconnector_google_remove_cl queries" && \
3955
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";' && \
4056
mysql -u root magento -e 'INSERT INTO `scconnector_google_remove_cl` (`version_id`, `entity_id`) VALUES ('1', '1');' && \
4157
mysql -u root magento -e 'alter table `scconnector_google_remove_cl` auto_increment = 1;' && \
42-
if [ "${SAMPLE_DATA}" = "true" ]; then echo "Running php bin/magento sampledata:deploy"; php bin/magento sampledata:deploy; fi && \
43-
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 && \
58+
if [ "${SAMPLE_DATA}" = "true" ]; then echo "[cad] Running php bin/magento sampledata:deploy"; php bin/magento sampledata:deploy; fi && \
59+
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 && \
4460
php bin/magento setup:static-content:deploy en_US -f -j 12 && \
4561
php bin/magento setup:di:compile && \
4662
php bin/magento indexer:reindex && \

magento/Dockerfile-2.4

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,46 @@ COPY scripts/retry retry
1414
COPY patches/ patches/
1515
COPY scripts/apply-2.4-patches.php scripts/apply-2.4-patches.php
1616
COPY scripts/downgrade-monolog.php scripts/downgrade-monolog.php
17+
COPY scripts/upgrade-to-composer-2.php scripts/upgrade-to-composer-2.php
1718
COPY scripts/allow-composer-plugins.php scripts/allow-composer-plugins.php
1819
COPY scripts/remove-paypal-braintree.php scripts/remove-paypal-braintree.php
1920
COPY scripts/patch-AC2855.php scripts/patch-AC2855.php
2021
COPY templates/memory-limit-php.ini /usr/local/etc/php/conf.d/memory-limit-php.ini
2122

2223
RUN ./start-services && \
23-
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 && \
24-
echo "Composer version:" && \
24+
composer self-update --2 && \
25+
echo "[cad] Composer version:" && \
2526
composer --version && \
27+
echo "[cad] Downloading & unzipping Magento" && \
2628
curl -o magento.zip https://repo-magento-mirror.fooman.co.nz/dist/magento/$MAGENTO_TYPE/magento-$MAGENTO_TYPE-$MAGENTO_VERSION.zip && \
2729
unzip -q magento.zip -d . && \
2830
rm magento.zip && \
29-
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 && \
31+
echo "[cad] Allowing composer plugins" && \
32+
php scripts/allow-composer-plugins.php && \
33+
rm scripts/allow-composer-plugins.php && \
34+
echo "[cad] Upgrading to composer 2" && \
35+
php scripts/upgrade-to-composer-2.php && \
36+
rm scripts/upgrade-to-composer-2.php && \
3037
composer config --unset repositories.0 && \
3138
composer config repositories.fooman composer https://repo-magento-mirror.fooman.co.nz/ && \
3239
if [ "$MAGENTO_VERSION" = "2.4.4" ]; then composer require "magento/security-package:1.1.3-p1 as 1.1.3" --no-update; fi && \
3340
if [ "$MAGENTO_VERSION" = "2.4.4" ]; then composer require "magento/inventory-metapackage:1.2.4-p1 as 1.2.4" --no-update; fi && \
41+
echo "[cad] Running Composer install" && \
3442
./retry "composer install" && \
3543
php scripts/patch-AC2855.php && \
3644
php scripts/downgrade-monolog.php && \
3745
php scripts/remove-paypal-braintree.php && \
46+
echo "[cad] Updating XML" && \
3847
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 && \
3948
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 && \
4049
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 && \
4150
composer dump-autoload && \
51+
echo "[cad] Running Magento setup:install" && \
4252
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 --admin-email=user@example.com --admin-firstname=Example --admin-lastname=Example --use-rewrites=1 --use-sample-data && \
53+
echo "[cad] Setting developer mode" && \
4354
php bin/magento deploy:mode:set developer && \
44-
if [ "${SAMPLE_DATA}" = "true" ]; then php bin/magento sampledata:deploy; fi && \
45-
if [ "${SAMPLE_DATA}" = "true" ]; then php bin/magento setup:upgrade; fi && \
55+
if [ "${SAMPLE_DATA}" = "true" ]; then echo "[cad] Running php bin/magento sampledata:deploy"; php bin/magento sampledata:deploy; fi && \
56+
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 && \
4657
php bin/magento setup:static-content:deploy en_US -f -j 12 && \
4758
php bin/magento setup:di:compile && \
4859
php bin/magento indexer:reindex && \

magento/scripts/retry

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ cmd=$1
1111

1212
# Execute the command until it succeeds or the maximum number of retries is reached
1313
while ! eval $cmd && [ $retries -lt $max_retries ]; do
14+
echo "Command failed. Retry attempt $retries"
1415
retries=$((retries+1))
1516
sleep 1
1617
done
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
$isPhp72OrLower = version_compare(PHP_VERSION, '7.2', '>=');
4+
5+
$version = getenv('MAGENTO_VERSION');
6+
$is230 = substr($version, 0, 5) == '2.3.0';
7+
$is231 = substr($version, 0, 5) == '2.3.1';
8+
$is232 = substr($version, 0, 5) == '2.3.2';
9+
$is233 = substr($version, 0, 5) == '2.3.3';
10+
$is234 = substr($version, 0, 5) == '2.3.4';
11+
$is235 = substr($version, 0, 5) == '2.3.5';
12+
$is236 = substr($version, 0, 5) == '2.3.6';
13+
$is237 = substr($version, 0, 5) == '2.3.7';
14+
$is240 = substr($version, 0, 5) == '2.4.0';
15+
$is241 = substr($version, 0, 5) == '2.4.1';
16+
$is242 = substr($version, 0, 5) == '2.4.2';
17+
$is243 = substr($version, 0, 5) == '2.4.3';
18+
$is244 = substr($version, 0, 5) == '2.4.4';
19+
$is245 = substr($version, 0, 5) == '2.4.5';
20+
$is246 = substr($version, 0, 5) == '2.4.6';
21+
$is247 = substr($version, 0, 5) == '2.4.7';
22+
23+
if ($is230 || $is231 || $is232 || $is233) {
24+
run('composer require magento/inventory-composer-installer:"1.2.0 as 1.1.0" --no-update');
25+
return;
26+
}
27+
28+
$laminasDependencyPluginVersion = "2.1.2 as 1.0.4";
29+
if ($isPhp72OrLower) {
30+
$laminasDependencyPluginVersion = "2.0.0 as 1.0.4";
31+
}
32+
33+
if ($is234 || $is235 || $is236 || $is240 || $is241) {
34+
run('composer require laminas/laminas-dependency-plugin:"' . $laminasDependencyPluginVersion . '" --no-update');
35+
run('composer require magento/inventory-composer-installer:"1.2.0 as 1.1.0" --no-update');
36+
run('composer require --dev dealerdirect/phpcodesniffer-composer-installer:^0.7.0 --no-update');
37+
return;
38+
}
39+
40+
function run(string $command) {
41+
echo 'Running command ' . $command . PHP_EOL;
42+
43+
$output = null;
44+
$code = null;
45+
exec($command, $output, $code);
46+
47+
if ($code !== 0) {
48+
echo 'Error while running "' . $command . '"' . PHP_EOL;
49+
die($code);
50+
}
51+
}

0 commit comments

Comments
 (0)