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

Improve composer version defaults #137

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## {{ UNRELEASED_VERSION }} - [{{ UNRELEASED_DATE }}]({{ UNRELEASED_LINK }})

* Added logic to allow default `composer` version to be set based on PHP version.
* Set default `composer` version to `2.8.2`
* Set default `composer` version to `2.2.24` for PHP 5.3-7.2
* Set default `composer` version to `1.10.27` for PHP <= 5.2
* Fixed bug causing `composer` 2.2.x to be installed when `composer_version` was set to a single digit version such as `1`

## v1.6.1 - [November 4, 2024](https://github.com/lando/php/releases/tag/v1.6.1)

* Updated to [@lando/[email protected]](https://github.com/lando/vitepress-theme-default-plus/releases/tag/v1.1.0-beta.18).
Expand Down
36 changes: 35 additions & 1 deletion builders/php.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ const _ = require('lodash');
const path = require('path');
const semver = require('semver');
const addBuildStep = require('./../utils/add-build-step');

/**
* Get the appropriate Composer version based on the PHP version.
* @param {string} phpVersion - The PHP version.
* @return {string|boolean} - The Composer version or false if we cannot parse the version.
*/
const getDefaultComposerVersion = phpVersion => {
phpVersion = semver.coerce(phpVersion);
// Don't set a default composer version if we cannot
// parse the version such as with `custom`.
if (!phpVersion) return false;

if (semver.lt(phpVersion, '5.3.2')) {
// Use Composer 1 for PHP < 5.3.2
return '1';
} else if (semver.lt(phpVersion, '7.3.0')) {
// Use Composer 2.2 LTS for PHP < 7.3
return '2.2.24';
} else {
// Use Composer 2 for PHP >= 7.3
return '2.8.2';
}
};

/*
* Helper to get nginx config
*/
Expand Down Expand Up @@ -108,7 +132,7 @@ module.exports = {
],
confSrc: path.resolve(__dirname, '..', 'config'),
command: ['sh -c \'a2enmod rewrite && apache2-foreground\''],
composer_version: '2.2.22',
composer_version: true,
phpServer: 'apache',
defaultFiles: {
_php: 'php.ini',
Expand Down Expand Up @@ -137,7 +161,11 @@ module.exports = {
parent: '_appserver',
builder: (parent, config) => class LandoPhp extends parent {
constructor(id, options = {}, factory) {
const debug = _.get(options, '_app._lando').log.debug;

// Merge the user config onto the default options
options = parseConfig(_.merge({}, config, options));

// Mount our default php config
options.volumes.push(`${options.confDest}/${options.defaultFiles._php}:${options.remoteFiles._php}`);
options.volumes.push(`${options.confDest}/${options.defaultFiles.pool}:${options.remoteFiles.pool}`);
Expand Down Expand Up @@ -180,8 +208,14 @@ module.exports = {
addBuildStep(['docker-php-ext-enable xdebug'], options._app, options.name, 'build_as_root_internal');
}

// Determine the appropriate composer version if not already set
if (options.composer_version === true || options.composer_version === '') {
options.composer_version = getDefaultComposerVersion(options.version);
}

// Install the desired composer version
if (options.composer_version) {
debug('Installing composer version %s', options.composer_version);
const commands = [`/helpers/install-composer.sh ${options.composer_version}`];
addBuildStep(commands, options._app, options.name, 'build_internal', true);
}
Expand Down
5 changes: 2 additions & 3 deletions examples/5.6/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ events:
services:
defaults:
type: php:5.6
composer_version: false
cli:
type: php:5.6
composer_version: false
composer_version: 1
via: cli
cliworker:
type: php:5.6
Expand All @@ -17,7 +16,7 @@ services:
command: sleep infinity
custom:
type: php:5.6
composer_version: false
composer_version: true
via: nginx
ssl: true
webroot: web
Expand Down
14 changes: 7 additions & 7 deletions examples/5.6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ lando exec defaults -- curl http://localhost | grep "memory_limit" | grep "1G"
# Should have COMPOSER_MEMORY_LIMIT set to -1
lando exec defaults -- env | grep "COMPOSER_MEMORY_LIMIT=-1"

# Should install composer 1.x by default
lando exec defaults -- composer --version --no-ansi | grep "Composer version 1."
# Should install composer 2.2.x by default
lando exec defaults -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 2.2."

# Should have unlimited memory for php for CLI opts
lando php -i | grep memory_limit | grep -e "-1"
Expand All @@ -61,8 +61,8 @@ lando exec custom_nginx -- curl https://localhost | grep SERVER | grep PATH_TRAN
# Should use specified php version if given
lando exec custom -- php -v | grep "PHP 5.6"

# Should install composer 1.x if composer_version is set to true
lando exec custom -- composer --version --no-ansi | grep "Composer version 1."
# Should install composer 2.2.x if composer_version is set to true
lando exec custom -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 2.2."

# Should serve via nginx if specified
lando exec custom_nginx -- curl http://localhost | grep "WEBDIR"
Expand All @@ -77,7 +77,7 @@ lando exec custom -- php -m | grep "xdebug"
lando exec cli -- curl http://localhost || echo $? | grep 7

# Should install the latest composer 1.x using the 1 flag
lando exec cli -- composer --version --no-ansi | grep "Composer version 1."
lando exec cli -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 1."

# Should use custom php ini if specified
lando exec custom -- php -i | grep memory_limit | grep 514
Expand Down Expand Up @@ -112,8 +112,8 @@ lando exec defaults -- curl http://localhost/path_info.php/a/b.php | grep SCRIPT
# Should allow cli services to specify a boot up command
lando info -s cliworker --deep | grep Cmd | grep sleep | grep infinity

# Should install the latest composer 1.x by default.
lando exec cliworker -- composer --version --no-ansi | grep "Composer version 1."
# Should use preinstalled composer 1.x when composer_version is false
lando exec cliworker -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 1."
```

## Destroy tests
Expand Down
3 changes: 1 addition & 2 deletions examples/7.0/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ events:
services:
defaults:
type: php:7.0
composer_version: false
cli:
type: php:7.0
composer_version: false
composer_version: 1
via: cli
build_as_root:
- echo "deb http://archive.debian.org/debian stretch main" > /etc/apt/sources.list
Expand Down
12 changes: 6 additions & 6 deletions examples/7.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ lando exec defaults -- curl http://localhost | grep "memory_limit" | grep "1G"
# Should have COMPOSER_MEMORY_LIMIT set to -1
lando exec defaults -- env | grep "COMPOSER_MEMORY_LIMIT=-1"

# Should install composer 1.x by default
lando exec defaults -- composer --version --no-ansi | grep "Composer version 1."
# Should install composer 2.2.x by default
lando exec defaults -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 2.2."

# Should have unlimited memory for php for CLI opts
lando php -i | grep memory_limit | grep -e "-1"
Expand All @@ -63,7 +63,7 @@ lando exec custom_nginx -- curl https://localhost | grep SERVER | grep PATH_TRAN
lando exec custom -- php -v | grep "PHP 7.0"

# Should install composer 2.x if 2-latest is set
lando exec custom -- composer --version --no-ansi | grep "Composer version 2."
lando exec custom -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 2."

# Should serve via nginx if specified
lando exec custom_nginx -- curl http://localhost | grep "WEBDIR"
Expand All @@ -78,7 +78,7 @@ lando exec custom -- php -m | grep "xdebug"
lando exec cli -- curl http://localhost || echo $? | grep 7

# Should install the latest composer 1.x using the 1 flag
lando exec cli -- composer --version --no-ansi | grep "Composer version 1."
lando exec cli -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 1."

# Should use custom php ini if specified
lando exec custom -- php -i | grep memory_limit | grep 514
Expand Down Expand Up @@ -113,8 +113,8 @@ lando exec defaults -- curl http://localhost/path_info.php/a/b.php | grep SCRIPT
# Should allow cli services to specify a boot up command
lando info -s cliworker --deep | grep Cmd | grep sleep | grep infinity

# Should install the latest composer 1.x by default.
lando exec cliworker -- composer --version --no-ansi | grep "Composer version 1."
# Should install the latest composer 1.x when composer_version is false
lando exec cliworker -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 1."

# Should have node14 installed in cli service
lando node -v | grep v14.
Expand Down
3 changes: 1 addition & 2 deletions examples/7.1/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ events:
services:
defaults:
type: php:7.1
composer_version: false
cli:
type: php:7.1
composer_version: false
composer_version: 1
via: cli
build_as_root:
- curl -sL https://deb.nodesource.com/setup_14.x | bash -
Expand Down
12 changes: 6 additions & 6 deletions examples/7.1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ lando exec defaults -- curl http://localhost | grep "memory_limit" | grep "1G"
# Should have COMPOSER_MEMORY_LIMIT set to -1
lando exec defaults -- env | grep "COMPOSER_MEMORY_LIMIT=-1"

# Should install composer 1.x by default
lando exec defaults -- composer --version --no-ansi | grep "Composer version 1."
# Should install composer 2.2.x by default
lando exec defaults -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 2.2."

# Should have unlimited memory for php for CLI opts
lando php -i | grep memory_limit | grep -e "-1"
Expand All @@ -63,7 +63,7 @@ lando exec custom_nginx -- curl https://localhost | grep SERVER | grep PATH_TRAN
lando exec custom -- php -v | grep "PHP 7.1"

# Should install composer 2.x if 2-latest is set
lando exec custom -- composer --version --no-ansi | grep "Composer version 2."
lando exec custom -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 2."

# Should serve via nginx if specified
lando exec custom_nginx -- curl http://localhost | grep "WEBDIR"
Expand All @@ -78,7 +78,7 @@ lando exec custom -- php -m | grep "xdebug"
lando exec cli -- curl http://localhost || echo $? | grep 7

# Should install the latest composer 1.x using the 1 flag
lando exec cli -- composer --version --no-ansi | grep "Composer version 1."
lando exec cli -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 1."

# Should use custom php ini if specified
lando exec custom -- php -i | grep memory_limit | grep 514
Expand Down Expand Up @@ -113,8 +113,8 @@ lando exec defaults -- curl http://localhost/path_info.php/a/b.php | grep SCRIPT
# Should allow cli services to specify a boot up command
lando info -s cliworker --deep | grep Cmd | grep sleep | grep infinity

# Should install the latest composer 1.x by default.
lando exec cliworker -- composer --version --no-ansi | grep "Composer version 1."
# Should install the latest composer 1.x if composer_version is set to false
lando exec cliworker -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 1."

# Should have node14 installed in cli service
lando node -v | grep v14.
Expand Down
3 changes: 1 addition & 2 deletions examples/7.2/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ events:
services:
defaults:
type: php:7.2
composer_version: false
cli:
type: php:7.2
composer_version: false
composer_version: 1
via: cli
build_as_root:
- curl -sL https://deb.nodesource.com/setup_14.x | bash -
Expand Down
12 changes: 6 additions & 6 deletions examples/7.2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ lando exec defaults -- curl http://localhost | grep "memory_limit" | grep "1G"
# Should have COMPOSER_MEMORY_LIMIT set to -1
lando exec defaults -- env | grep "COMPOSER_MEMORY_LIMIT=-1"

# Should install composer 1.x by default
lando exec defaults -- composer --version --no-ansi | grep "Composer version 1."
# Should install composer 2.2.x by default
lando exec defaults -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 2.2"

# Should have unlimited memory for php for CLI opts
lando php -i | grep memory_limit | grep -e "-1"
Expand All @@ -63,7 +63,7 @@ lando exec custom_nginx -- curl https://localhost | grep SERVER | grep PATH_TRAN
lando exec custom -- php -v | grep "PHP 7.2"

# Should install composer 2.x if 2-latest is set
lando exec custom -- composer --version --no-ansi | grep "Composer version 2."
lando exec custom -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 2."

# Should serve via nginx if specified
lando exec custom_nginx -- curl http://localhost | grep "WEBDIR"
Expand All @@ -78,7 +78,7 @@ lando exec custom -- php -m | grep "xdebug"
lando exec cli -- curl http://localhost || echo $? | grep 7

# Should install the latest composer 1.x using the 1 flag
lando exec cli -- composer --version --no-ansi | grep "Composer version 1."
lando exec cli -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 1."

# Should use custom php ini if specified
lando exec custom -- php -i | grep memory_limit | grep 514
Expand Down Expand Up @@ -113,8 +113,8 @@ lando exec defaults -- curl http://localhost/path_info.php/a/b.php | grep SCRIPT
# Should allow cli services to specify a boot up command
lando info -s cliworker --deep | grep Cmd | grep sleep | grep infinity

# Should install the latest composer 1.x by default.
lando exec cliworker -- composer --version --no-ansi | grep "Composer version 1."
# Should install the latest composer 1.x if composer_version is set to false
lando exec cliworker -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 1."

# Should have node14 installed in cli service
lando node -v | grep v14.
Expand Down
6 changes: 3 additions & 3 deletions examples/7.3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ lando exec defaults -- curl http://localhost | grep "memory_limit" | grep "1G"
lando exec defaults -- env | grep "COMPOSER_MEMORY_LIMIT=-1"

# Should install composer 2.x by default
lando exec defaults -- composer --version --no-ansi | grep "Composer version 2."
lando exec defaults -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 2."

# Should have unlimited memory for php for CLI opts
lando php -i | grep memory_limit | grep -e "-1"
Expand All @@ -63,7 +63,7 @@ lando exec custom_nginx -- curl https://localhost | grep SERVER | grep PATH_TRAN
lando exec custom -- php -v | grep "PHP 7.3"

# Should install composer 2.x if 2-latest is set
lando exec custom -- composer --version --no-ansi | grep "Composer version 2."
lando exec custom -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 2."

# Should serve via nginx if specified
lando exec custom_nginx -- curl http://localhost | grep "WEBDIR"
Expand Down Expand Up @@ -111,7 +111,7 @@ lando exec defaults -- curl http://localhost/path_info.php/a/b.php | grep SCRIPT
lando info -s cliworker --deep | grep Cmd | grep sleep | grep infinity

# Should install the composer 2.x using the false flag
lando exec cliworker -- composer --version --no-ansi | grep "Composer version 2."
lando exec cliworker -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 2."

# Should have node14 installed in cli service
lando node -v | grep v14.
Expand Down
6 changes: 3 additions & 3 deletions examples/7.4/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ lando exec defaults -- curl http://localhost | grep "memory_limit" | grep "1G"
lando exec defaults -- env | grep "COMPOSER_MEMORY_LIMIT=-1"

# Should install composer 2.x by default
lando exec defaults -- composer --version --no-ansi | grep "Composer version 2."
lando exec defaults -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 2."

# Should have unlimited memory for php for CLI opts
lando php -i | grep memory_limit | grep -e "-1"
Expand All @@ -63,7 +63,7 @@ lando exec custom_nginx -- curl https://localhost | grep SERVER | grep PATH_TRAN
lando exec custom -- php -v | grep "PHP 7.4"

# Should install composer 2.x if 2-latest is set
lando exec custom -- composer --version --no-ansi | grep "Composer version 2."
lando exec custom -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 2."

# Should serve via nginx if specified
lando exec custom_nginx -- curl http://localhost | grep "WEBDIR"
Expand Down Expand Up @@ -111,7 +111,7 @@ lando exec defaults -- curl http://localhost/path_info.php/a/b.php | grep SCRIPT
lando info -s cliworker --deep | grep Cmd | grep sleep | grep infinity

# Should install the latest composer 2.x by default.
lando exec cliworker -- composer --version --no-ansi | grep "Composer version 2."
lando exec cliworker -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 2."

# Should have node14 installed in cli service
lando node -v | grep v14.
Expand Down
8 changes: 4 additions & 4 deletions examples/8.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ lando exec defaults -- curl http://localhost | grep "memory_limit" | grep "1G"
lando exec defaults -- env | grep "COMPOSER_MEMORY_LIMIT=-1"

# Should install composer 2.x by default
lando exec defaults -- composer --version --no-ansi | grep "Composer version 2."
lando exec defaults -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 2."

# Should have unlimited memory for php for CLI opts
lando php -i | grep memory_limit | grep -e "-1"
Expand All @@ -60,7 +60,7 @@ lando exec custom_nginx -- curl https://localhost | grep SERVER | grep PATH_TRAN
lando exec custom -- php -v | grep "PHP 8.0"

# Should install composer 2.1.12 if version number is set
lando exec custom -- composer --version --no-ansi | grep "Composer version 2.1.12"
lando exec custom -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 2.1.12"

# Should serve via nginx if specified
lando exec custom_nginx -- curl http://localhost | grep "WEBDIR"
Expand All @@ -75,7 +75,7 @@ lando exec custom -- php -m | grep "xdebug"
lando exec cli -- curl http://localhost || echo $? | grep 7

# Should install the composer 2.x using the false flag
lando exec cli -- composer --version --no-ansi | grep "Composer version 2."
lando exec cli -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 2."

# Should use custom php ini if specified
lando exec custom -- php -i | grep memory_limit | grep 514
Expand Down Expand Up @@ -111,7 +111,7 @@ lando exec defaults -- curl http://localhost/path_info.php/a/b.php | grep SCRIPT
lando info -s cliworker --deep | grep Cmd | grep sleep | grep infinity

# Should install the latest composer 2.x by default.
lando exec cliworker -- composer --version --no-ansi | grep "Composer version 2."
lando exec cliworker -- composer --version --no-ansi | tee >(cat 1>&2) | grep -q "Composer version 2."

# Should have node14 installed in cli service
lando node -v | grep v14.
Expand Down
Loading
Loading