Skip to content

Commit

Permalink
remove composer installation from images
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFeledy committed Dec 17, 2024
1 parent 497664f commit 284dfd4
Show file tree
Hide file tree
Showing 27 changed files with 103 additions and 108 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

* Added logic to allow default `composer` version to be set based on PHP version.
* Added `2.2` and `2.2-latest` shorthand options to install the latest stable 2.2 LTS version of `composer`.
* Set default `composer` version to `2.8.3`
* 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
* Set default `composer` version to `2-latest`
* Set default `composer` version to `2.2-latest` for PHP 5.3-7.2
* Set default `composer` version to `1-latest` for PHP <= 5.2
* Removed `composer` installation from images to prefer installing during app build
* Fixed bug causing `composer` 2.2.x to be installed when `composer_version` was set to a single digit version such as `1`
* Fixed mismatched `libsqlite3-dev` and `libsqlite3-0` versions in PHP 8.3 and 8.4 images

Expand Down
81 changes: 50 additions & 31 deletions builders/php.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,25 @@ const path = require('path');
const semver = require('semver');
const addBuildStep = require('./../utils/add-build-step');

const composerVersions = {
'1': '1.10.27',
'2': '2.8.3',
'2.2': '2.2.24',
};

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

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

Expand Down Expand Up @@ -60,13 +53,25 @@ const nginxConfig = options => ({
const xdebugConfig = host => ([
`client_host=${host}`,
'discover_client_host=1',
'log=/tmp/xdebug.log',
'remote_enable=true',
'log=/tmp/xdebug.log',
'remote_enable=true',
`remote_host=${host}`,
].join(' '));

/*
* Helper to build a package string
/**
* Helper function to build a package string by combining package name and version
*
* @param {string} pkg - The package name
* @param {string} version - The package version
* @return {string} The formatted package string, either "pkg:version" or just "pkg" if version is empty
*
* @example
* // Returns "php:7.4"
* pkger('php', '7.4');
*
* @example
* // Returns "mysql"
* pkger('mysql', '');
*/
const pkger = (pkg, version) => (!_.isEmpty(version)) ? `${pkg}:${version}` : pkg;

Expand Down Expand Up @@ -172,11 +177,15 @@ module.exports = {
// Merge the user config onto the default options
options = parseConfig(_.merge({}, config, options));

// Get the semver of the PHP version, NULL if we cannot parse it
const phpSemver = semver.coerce(options.version);
phpSemver && debug('Parsed PHP semantic version: %s', phpSemver);

// 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}`);
// Shift on the docker entrypoint if this is a more recent version
if (options.version !== 'custom' && semver.gt(semver.coerce(options.version), '5.5.0')) {
if (phpSemver && semver.gt(phpSemver, '5.5.0')) {
options.command.unshift('docker-php-entrypoint');
}

Expand All @@ -202,28 +211,38 @@ module.exports = {
};
options.info = {via: options.via};

// Add our composer things to run step
if (!_.isEmpty(options.composer)) {
const commands =
require('../utils/get-install-commands')(options.composer, pkger, ['composer', 'global', 'require', '-n']);
addBuildStep(commands, options._app, options.name, 'build_internal');
// Determine the appropriate composer version to install if not specified
if (options.composer_version === true || options.composer_version === '') {
options.composer_version = getDefaultComposerVersion(phpSemver);
} else if (typeof options.composer_version === 'number') {
options.composer_version = options.composer_version.toString();
}
const usingComposer1 = options.composer_version && semver.satisfies(options.composer_version, '1.x');

// Add prestissimo as a global package for Composer 1.x performance improvements. Requires PHP >= 5.3
if (usingComposer1 && phpSemver && semver.gte(phpSemver, '5.3.0')) {
options.composer = options.composer || {};
options.composer = {'hirak/prestissimo': '*', ...options.composer};
}

// Add activate steps for xdebug
// Add build step to enable xdebug
if (options.xdebug) {
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);
// Add build step to install our Composer global packages
if (!_.isEmpty(options.composer)) {
const commands =
require('../utils/get-install-commands')(options.composer, pkger, ['composer', 'global', 'require', '-n']);
addBuildStep(commands, options._app, options.name, 'build_internal');
}

// Install the desired composer version
// Install the desired composer version as the first `build_internal` build step
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);
const firstStep = true;
addBuildStep(commands, options._app, options.name, 'build_internal', firstStep);
}

// Add in nginx if we need to
Expand Down
18 changes: 13 additions & 5 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
webroot: .
xdebug: false
composer: []
composer_version: '2.2.12'
composer_version: '2'
# Below only valid for via: cli
command: tail -f /dev/null
config:
Expand Down Expand Up @@ -161,16 +161,22 @@ You can use `lando info --deep | grep IPAddress` to help discover the correct ho

## Installing composer

As of Lando `3.0.17` you can configure the version of `composer` you would like to install. This _should_ respect any of the versions listed on the [Composer download page](https://getcomposer.org/download/) but it is required you specify down to the patch version.
Lando automatically installs the latest compatible version of Composer based on your specified PHP version:

- PHP >= 7.3: Composer 2.x
- PHP >= 5.3.2 and < 7.3: Composer 2.2 LTS
- PHP < 5.3.2: Composer 1.x

You can customize the Composer version by specifying either a specific version number or using a channel alias:

```yaml
services:
myservice:
type: php
composer_version: "1.10.1"
type: php:8.2
composer_version: "2.6.5" # Install specific version
```

You can also choose to ignore the `composer` install step by setting `composer_version: false`. This will use whatever version of `composer` was last bundled with our `php` image. The following "convenience flags" are also available:
The following channel aliases are available:

```yaml
# Install the latest stable 1.x version
Expand All @@ -192,6 +198,8 @@ composer_version: preview
composer_version: snapshot
```

You can disable Composer installation entirely by setting `composer_version: false`.

## Installing global dependencies

You can also use the `composer` key if you need to require any [global composer dependenices](https://getcomposer.org/doc/03-cli.md#require). This follows the same syntax as your normal [`composer.json`](https://getcomposer.org/doc/01-basic-usage.md#composer-json-project-setup) except written as YAML instead of JSON.
Expand Down
4 changes: 0 additions & 4 deletions images/5.6-apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ RUN \
intl \
gettext \
pcntl \
&& php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer --version=1.10.27 \
&& php -r "unlink('composer-setup.php');" \
&& chsh -s /bin/bash www-data && mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www \
&& su -c "composer global require -n hirak/prestissimo" -s /bin/sh www-data \
&& apt-get -y clean \
&& apt-get -y autoclean \
&& apt-get -y autoremove \
Expand Down
5 changes: 0 additions & 5 deletions images/5.6-fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,7 @@ RUN \
intl \
gettext \
pcntl \
# Install composer
&& php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer --version=1.10.27 \
&& php -r "unlink('composer-setup.php');" \
&& chsh -s /bin/bash www-data && mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www \
&& su -c "composer global require -n hirak/prestissimo" -s /bin/sh www-data \
&& apt-get -y clean \
&& apt-get -y autoclean \
&& apt-get -y autoremove \
Expand Down
4 changes: 0 additions & 4 deletions images/7.0-apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ RUN \
intl \
gettext \
pcntl \
&& php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer --version=1.10.27 \
&& php -r "unlink('composer-setup.php');" \
&& chsh -s /bin/bash www-data && mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www \
&& su -c "composer global require -n hirak/prestissimo" -s /bin/sh www-data \
&& apt-get -y clean \
&& apt-get -y autoclean \
&& apt-get -y autoremove \
Expand Down
4 changes: 0 additions & 4 deletions images/7.0-fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ RUN \
intl \
gettext \
pcntl \
&& php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer --version=1.10.27 \
&& php -r "unlink('composer-setup.php');" \
&& chsh -s /bin/bash www-data && mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www \
&& su -c "composer global require -n hirak/prestissimo" -s /bin/sh www-data \
&& apt-get -y clean \
&& apt-get -y autoclean \
&& apt-get -y autoremove \
Expand Down
4 changes: 0 additions & 4 deletions images/7.1-apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ RUN \
intl \
gettext \
pcntl \
&& php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer --version=1.10.27 \
&& php -r "unlink('composer-setup.php');" \
&& chsh -s /bin/bash www-data && mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www \
&& su -c "composer global require -n hirak/prestissimo" -s /bin/sh www-data \
&& apt-get -y clean \
&& apt-get -y autoclean \
&& apt-get -y autoremove \
Expand Down
4 changes: 0 additions & 4 deletions images/7.1-fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ RUN \
intl \
gettext \
pcntl \
&& php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer --version=1.10.27 \
&& php -r "unlink('composer-setup.php');" \
&& chsh -s /bin/bash www-data && mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www \
&& su -c "composer global require -n hirak/prestissimo" -s /bin/sh www-data \
&& apt-get -y clean \
&& apt-get -y autoclean \
&& apt-get -y autoremove \
Expand Down
4 changes: 0 additions & 4 deletions images/7.2-apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ RUN \
intl \
gettext \
pcntl \
&& php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer --version=1.10.27 \
&& php -r "unlink('composer-setup.php');" \
&& chsh -s /bin/bash www-data && mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www \
&& su -c "composer global require -n hirak/prestissimo" -s /bin/sh www-data \
&& apt-get -y clean \
&& apt-get -y autoclean \
&& apt-get -y autoremove \
Expand Down
4 changes: 0 additions & 4 deletions images/7.2-fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ RUN \
intl \
gettext \
pcntl \
&& php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer --version=1.10.27 \
&& php -r "unlink('composer-setup.php');" \
&& chsh -s /bin/bash www-data && mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www \
&& su -c "composer global require -n hirak/prestissimo" -s /bin/sh www-data \
&& apt-get -y clean \
&& apt-get -y autoclean \
&& apt-get -y autoremove \
Expand Down
3 changes: 0 additions & 3 deletions images/7.3-apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ RUN mkdir -p /usr/share/man/man1 /usr/share/man/man7 \
intl \
gettext \
pcntl \
&& php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer --version=2.2.24 \
&& php -r "unlink('composer-setup.php');" \
&& chsh -s /bin/bash www-data && mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www \
&& apt-get -y clean \
&& apt-get -y autoclean \
Expand Down
3 changes: 0 additions & 3 deletions images/7.3-fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ RUN mkdir -p /usr/share/man/man1 /usr/share/man/man7 \
intl \
gettext \
pcntl \
&& php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer --version=2.2.24 \
&& php -r "unlink('composer-setup.php');" \
&& chsh -s /bin/bash www-data && mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www \
&& apt-get -y clean \
&& apt-get -y autoclean \
Expand Down
2 changes: 0 additions & 2 deletions images/7.4-apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ RUN \
RUN install-php-extensions xdebug \
&& rm -f /usr/local/etc/php/conf.d/*xdebug.ini

RUN install-php-extensions @composer-2.2.24

RUN \
chsh -s /bin/bash www-data && mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www \
&& apt-get -y clean \
Expand Down
2 changes: 0 additions & 2 deletions images/7.4-fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ RUN \
RUN install-php-extensions xdebug \
&& rm -f /usr/local/etc/php/conf.d/*xdebug.ini

RUN install-php-extensions @composer-2.2.24

RUN \
chsh -s /bin/bash www-data && mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www \
&& apt-get -y clean \
Expand Down
2 changes: 0 additions & 2 deletions images/8.0-apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ RUN \
RUN install-php-extensions xdebug \
&& rm -f /usr/local/etc/php/conf.d/*xdebug.ini

RUN install-php-extensions @composer-2.2.24

RUN \
chsh -s /bin/bash www-data && mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www \
&& apt-get -y clean \
Expand Down
2 changes: 0 additions & 2 deletions images/8.0-fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ RUN \
RUN install-php-extensions xdebug \
&& rm -f /usr/local/etc/php/conf.d/*xdebug.ini

RUN install-php-extensions @composer-2.2.24

RUN \
chsh -s /bin/bash www-data && mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www \
&& apt-get -y clean \
Expand Down
2 changes: 0 additions & 2 deletions images/8.1-apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ RUN \
RUN install-php-extensions xdebug \
&& rm -f /usr/local/etc/php/conf.d/*xdebug.ini

RUN install-php-extensions @composer-2

RUN \
chsh -s /bin/bash www-data && mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www \
&& apt-get -y clean \
Expand Down
2 changes: 0 additions & 2 deletions images/8.1-fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ RUN \
RUN install-php-extensions xdebug \
&& rm -f /usr/local/etc/php/conf.d/*xdebug.ini

RUN install-php-extensions @composer-2

RUN \
chsh -s /bin/bash www-data && mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www \
&& apt-get -y clean \
Expand Down
2 changes: 0 additions & 2 deletions images/8.2-apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ RUN \
RUN install-php-extensions xdebug \
&& rm -f /usr/local/etc/php/conf.d/*xdebug.ini

RUN install-php-extensions @composer-2

RUN \
chsh -s /bin/bash www-data && mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www \
&& apt-get -y clean \
Expand Down
2 changes: 0 additions & 2 deletions images/8.2-fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ RUN \
RUN install-php-extensions xdebug \
&& rm -f /usr/local/etc/php/conf.d/*xdebug.ini

RUN install-php-extensions @composer-2

RUN \
chsh -s /bin/bash www-data && mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www \
&& apt-get -y clean \
Expand Down
2 changes: 0 additions & 2 deletions images/8.3-apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ RUN \
RUN install-php-extensions xdebug \
&& rm -f /usr/local/etc/php/conf.d/*xdebug.ini

RUN install-php-extensions @composer-2

RUN \
chsh -s /bin/bash www-data && mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www \
&& apt-get -y clean \
Expand Down
Loading

0 comments on commit 284dfd4

Please sign in to comment.