lando / lemp

The Official LEMP Lando Plugin
https://docs.lando.dev/lemp/
GNU General Public License v3.0
0 stars 3 forks source link

Lando LEMP recipe installs incorrect Composer version #2

Closed Niyabi closed 2 years ago

Niyabi commented 2 years ago

In my .lando.yml file I set Composer to be version 2.0.7 however 'lando composer -V' shows version 1.10.1. I've tried rebuilds, upgraded lando to version 3.4.2, set composer version in service... no matter what I've tried it's still version 1.10.1. I'm working in WSL Ubuntu (20.04).

recipe: lemp
config:
  webroot: docroot/pub
  php: '7.4'
  database: mariadb:10.4
  xdebug: 'false'
  composer_version: '2.0.7'
  config:
    php: config/php.ini
    vhosts: config/nginx.conf
pirog commented 2 years ago

@Niyabi which composer is it using? Go into the appserver container and run which composer.

miquelbrazil commented 2 years ago

I started looking into integrating Lando into my dev workflow earlier this week and ran into this issue pretty earlier on.

As a way of learning more about how Lando works, I took a deep dive into trying to understand what was causing this.

Using the bare lemp recipe with a landofile like the this:

name: demo
recipe: lemp

I ran into the error from the outset:

❯ lando start                                                                                                                                                                                       ─╯
Let's get this party started! Starting app demo...
landoproxyhyperion5000gandalfedition_proxy_1 is up-to-date
Creating network "demo_default" with the default driver
Creating volume "demo_data_appserver_nginx" with default driver
Creating volume "demo_home_appserver_nginx" with default driver
Creating volume "demo_data_appserver" with default driver
Creating volume "demo_home_appserver" with default driver
Creating volume "demo_data_database" with default driver
Creating volume "demo_home_database" with default driver
Pulling appserver (devwithlando/php:7.3-fpm-3)...
7.3-fpm-3: Pulling from devwithlando/php
b380bbd43752: Already exists
2678eeaa3904: Already exists
0f3fa9897c65: Already exists
811790ff3537: Already exists
dc8340093cc8: Pull complete
6c7828e8e974: Pull complete
30b5fc33f601: Pull complete
a10ca7f9a3d4: Pull complete
83c02499b133: Pull complete
2b41b815c722: Pull complete
6f81dc9a719e: Pull complete
24b90b7b32c4: Pull complete
Digest: sha256:b015b2ef95974fa8b88a8dec6be2cf40fd4a6864c39c03c008ee1eeb37c38a32
Status: Downloaded newer image for devwithlando/php:7.3-fpm-3
Creating demo_appserver_1 ... done
All settings correct for using Composer
Downloading...

Composer (version 2.0.7) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer

Changed current directory to /var/www/.composer
The "hirak/prestissimo" plugin was skipped because it requires a Plugin API version ("^1.0.0") that does not match your Composer installation ("2.0.0"). You may need to run composer update with the "--no-plugins" option.
./composer.json has been updated
The "hirak/prestissimo" plugin was skipped because it requires a Plugin API version ("^1.0.0") that does not match your Composer installation ("2.0.0"). You may need to run composer update with the "--no-plugins" option.
Running composer update hirak/prestissimo
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 0 updates, 1 removal
  - Removing hirak/prestissimo (0.3.10)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 0 updates, 1 removal
  - Removing hirak/prestissimo (0.3.10)
Generating autoload files
Killing demo_appserver_1 ... 
Killing demo_appserver_1 ... done
Pulling appserver_nginx (bitnami/nginx:1.17.10-debian-10-r52)...
1.17.10-debian-10-r52: Pulling from bitnami/nginx
8639931041da: Pull complete
ac37ad6b4836: Pull complete
c28a9d9c2b13: Pull complete
2efb38883bea: Pull complete
843b0268ec36: Pull complete
e7e7ee30c869: Pull complete
10cc47006231: Pull complete
6a452a58a298: Pull complete
ef4988f1c6ff: Pull complete
9d42bebde252: Pull complete
b12f84735865: Pull complete
Digest: sha256:18d0224800c19722f233093c18b8c90e4d26fe81842838460bc99c0d6c6a2bf4
Status: Downloaded newer image for bitnami/nginx:1.17.10-debian-10-r52
Starting demo_appserver_1       ... done
Creating demo_database_1        ... done
Creating demo_appserver_nginx_1 ... done
Waiting until database service is ready...
Waiting until database service is ready...
Waiting until database service is ready...
Scanning to determine which services are ready... Please standby...

   ___                      __        __        __     __        ______
  / _ )___  ___  __ _  ___ / /  ___ _/ /_____ _/ /__ _/ /_____ _/ / / /
 / _  / _ \/ _ \/  ' \(_-</ _ \/ _ `/  '_/ _ `/ / _ `/  '_/ _ `/_/_/_/ 
/____/\___/\___/_/_/_/___/_//_/\_,_/_/\_\\_,_/_/\_,_/_/\_\\_,_(_|_|_)  

Your app has started up correctly.
Here are some vitals:

 NAME                  demo                                                                            
 LOCATION              ~/demo 
 SERVICES              appserver_nginx, appserver, database                                               
 APPSERVER_NGINX URLS  https://localhost:60665                                                            
                       http://localhost:60666                                                             
                       http://demo.lndo.site/                                                          
                       https://demo.lndo.site/     

Entering the appserver container and running which composer produces the output /usr/local/bin/composer which is the expected path. Also, running composer -v reports that it is running Composer v2.0.7.

One thing to point out is that the default version of php for the lamp recipe is 7.3 although the documentation says 7.4 is the default.

Declaring a specific PHP version appears to produce the same result:

name: demo
recipe: lemp
config:
  php: '7.4'

In my case, even though the correct version of Composer is reported and run once the service is started, I end up with the same issue that was reported here. This seems to be caused by the installation of Composer v1.10.1 earlier in the image building process, the directory is then switched to the global installation of Composer and an attempt is made to update it to a newer version. It appears that this update request causes the self-update to encounter the hirak/prestissimo package – which is intended for Composer 1 installations. This set of lines points to the place this happening:

All settings correct for using Composer
Downloading...

Composer (version 2.0.7) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer

Changed current directory to /var/www/.composer
The "hirak/prestissimo" plugin was skipped because it requires a Plugin API version ("^1.0.0") that does not match your Composer installation ("2.0.0"). You may need to run composer update with the "--no-plugins" option.
./composer.json has been updated
The "hirak/prestissimo" plugin was skipped because it requires a Plugin API version ("^1.0.0") that does not match your Composer installation ("2.0.0"). You may need to run composer update with the "--no-plugins" option.
Running composer update hirak/prestissimo
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 0 updates, 1 removal
  - Removing hirak/prestissimo (0.3.10)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 0 updates, 1 removal
  - Removing hirak/prestissimo (0.3.10)
Generating autoload files

I imagine @Niyabi is hitting this same issue but the build is not self-repairing. As pointed out in lando/php#10, the warning isn't preventing me from using lando, but it does slow things down (aside from just being the kind of dev who tries to get rid of warnings, notices and errors early and often).

I tried using the --no-plugins option flag as a build step because my full landofile also included a composer install command. I also tried removing the hirak/prestissimo package as a build step along with other flags like --ignore-platform-reqs as was referenced in this issue. The best I succeeded in doing was in some cases suppressing one of the two warnings.

I dug further and eventually landed on the Dockerfiles that make up each PHP container. Lines 71-75 for the php/7.4-fpm container includes the following:

  && php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
  && php composer-setup.php --install-dir=/usr/local/bin --filename=composer --version=1.10.1 \
  && 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 hirak/prestissimo" -s /bin/sh www-data \

This is also in the Dockerfiles for all PHP containers in the 7-series. However, starting with v8, it looks like this:

  && php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
  && php composer-setup.php --install-dir=/usr/local/bin --filename=composer --version=2.0.7 \
  && 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 hirak/prestissimo" -s /bin/sh www-data \

The explicitly specified Composer is v2.0.7 and the global installation of the hirak/prestissimo package is commented out.

With this information, combined with the information in the Lando documentation for Services: Using Dockerfiles, I created a landofile that looks like the following:

name: demo
services:
  app:
    type: php:7.4-custom
    overrides:
      build: ./config/lando/php
      image: miquelbrazil/php:7.4-custom
    build:
      - composer update

and with the php/7.4-fpm Dockerfile as the basis, I created a custom one with these changes:

&& php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer --2 \
&& php -r "unlink('composer-setup.php');" \

By passing the --2 flag for the latest 2.0 release and removing the now unnecessary hirak/prestissimo package, my app booted up as expected with no errors.

I'm not sure if this is the ideal solution, but I'd be happy to make a PR with these changes.

Niyabi commented 2 years ago

@pirog result of which composer is /usr/local/bin/composer.

I've tried to use build_as_root to install Composer 2 but didn't work

Niyabi commented 2 years ago

During building I run command:

build_as_root:
      - apt update -y -q && apt install -y libxslt-dev cron && docker-php-ext-install xsl sockets sodium

And I get error :

checking for libsodium >= 1.0.8... no
configure: error: Package requirements (libsodium >= 1.0.8) were not met:

No package 'libsodium' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables LIBSODIUM_CFLAGS
and LIBSODIUM_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
ERROR ==> See the pkg-config man page for more details.

That's the cause that Composer doesn't update to v2. When I remove sodium extension from installation Composer updates to v2 as I set it in lando file. As this local environment is for Magento 2 sodium is required so now I have to think how to solve that problem.

labboy0276 commented 2 years ago

This has been fixed in the latest php images for 7.4.

john@tandem:~/lando/lemp-test$ cat .lando.yml
name: lemp-test
recipe: lemp
config:
  webroot: .
  php: '7.4'
john@tandem:~/lando/lemp-test$ lando composer --version
Composer version 2.0.7 2020-11-13 17:31:06

We no longer install hirak/prestissimo either.