Composer install with no scripts doesn't work

Hi there!

I have a problem when deploying to production with trellis. I’m using trellis + bedrock + sage 9 and this is my composer.json file -> https://gist.github.com/cfaria/46284212707f7fa1dcebd7edcfe01e21

The issue is that Koodimonni Language composer package ( https://gist.github.com/cfaria/46284212707f7fa1dcebd7edcfe01e21#file-composer-json-L46 ) should write the es_ES language files into web/app/languages using the dropin paths ( https://gist.github.com/cfaria/46284212707f7fa1dcebd7edcfe01e21#file-composer-json-L68 ) but it doesn’t.

I’ve played with it a bit and discovered that if I connect via ssh to my production droplet and remove the /srv/www/domain.com/current/vendor folder and install it again executing composer install without the --no-scripts flag, it works.

Then I’ve searched for the composer install task in the trellis deploy role ( /trellis/roles/deploy/hooks/build-after.yml ) and changed this:

- name: Install Composer dependencies
   composer:
     no_scripts: yes
     working_dir: "{{ deploy_helper.new_release_path }}"

… to this:

- name: Install Composer dependencies
   composer:
     no_scripts: no
     working_dir: "{{ deploy_helper.new_release_path }}"

But it doesn’t work either. So maybe this is not the right place to customize the composer install task, but I haven’t found any other place to change that behaviour

The problem is that Koodimonni Language packages needs composer to be executed without the no-scripts flag because it uses scripts to copy the files to their proper place.

I also tried to change the composer task to sth like this but with no luck:

- name: Install Composer dependencies with scripts
    command: composer install --no-ansi --no-dev --no-interaction --optimize-autoloader
    args:
      chdir: "{{ deploy_helper.new_release_path }}"

Does anyone know how to force composer to be fired with scripts? I always mean bedrock composer, not sage.
Am I editing the right file /trellis/roles/deploy/hooks/build-after.yml ?

Thank you guys for your help ;D

What if you do this (just remove the no_scripts option)?

- name: Install Composer dependencies
   composer:
     working_dir: "{{ deploy_helper.new_release_path }}"

I’ve tried that already, but doesn’t work either. Let me try again…

… nope, it doesn’t work without the flag…

I have this Warning notice when I launch the deploy role:

[WARNING]: You Ansible version is 2.6.2 but this version of Trellis has only been tested for compatability with Ansible 2.4.0.0 -> 2.4.3.0. It is advisable to check for Trellis updates or downgrade your Ansible version.

Maybe I should try downgrading Ansible, but as everything worked like a charm I thought it wasn’t the problem here…

Do you think that should do it?

I’ve downgraded to Ansible 2.4.3.0 but the deploy task does the same. Everything is fine except that script part.
The weird thing is if I SSH and do a composer install manually, everything works just fine.

@alwaysblank Can you confirm me that /trellis/roles/deploy/hooks/build-after.yml is the right file I should focus on? I mean, is that file the YAML file in charge of launching the composer install task on Bedrock?

I’m a bit stuck with this as it seems like the options I put there are not even fired …

Yes, that’s the file you should focus on to run commands on the server during deployment. Can you paste your file’s contents here?

Hi @MWDelaney, of course. Right now it shows like this:

As you can see it has the same contents as the original one https://github.com/roots/trellis/blob/master/roles/deploy/hooks/build-after.yml except that I removed the no_scripts part as @alwaysblank told me, and at the end of the file I also commented out some tests I did using the composer command.

I changed the name of the task too ( Install Composer dependencies with scripts ) to see in the deploy process if the changes were firing.

The weird thing is that the plugins in my composer json are being installed correctly, and the ones from Koodimonni are installed in the composer cache too, but the operation that transfers the language files to the correct folder (/site/web/app/languages) is not being fired.

Thank you both for your help.

Pretty sure this is your problem:

"scripts": {
    "post-root-package-install": [
      "php -r \"copy('.env.example', '.env');\""
    ],
    ...
}

You’re attempting to run this script on post-root-package-install. Take a look at the Composer Documentation for script event names: Scripts - Composer The post-root-package-install event has the following description:

post-root-package-install : occurs after the root package has been installed, during the create-project command.

That means it will only be executed when composer create-project is run. composer create-project is not run by Bedrock or Trellis when installing your dependencies. You probably want to use post-install-cmd, which is executed after composer install.

In other words, this is not a Trellis issue: It’s an issue with the configuration of your composer.json file.

1 Like

But that command comes on a brand new Bedrock install. It seems that lines are used to copy the .env.example file to the site root as .env file when it’s first installed… You mean that I should remove those lines? I don’t know how is that related to the fact that functionality from an independent composer plugin isn’t fired.

I don’t know if it’s a problem with Trellis or the Koodimonni composer plugin itself, but as If I access the production server via SSH, do a manual composer install and everything works fine, it seems like something in the deploy process is not firing the same way as I do it mannually.

Let me sum up and see if I’m wrong with the deploy process:

  1. Every time I do a deploy to production a new composer install is fired in the new site release folder ( https://gist.github.com/cfaria/46284212707f7fa1dcebd7edcfe01e21#file-build-after-yml-L20-L22 ). Then, that composer install should install all the plugins I have in my composer.json and everyone should do all the operations needed.
  2. So, in the composer-dropin-installer plugin from Koodimonni, loaded in my composer.json file ( https://gist.github.com/cfaria/46284212707f7fa1dcebd7edcfe01e21#file-composer-json-L42 ), as the composer plugins are being installed (beacause it’s a brand new composer install), the onPackageInstall function on that plugin ( https://gist.github.com/cfaria/46284212707f7fa1dcebd7edcfe01e21#file-dropin-php-L83-L93 ) should be fired. That function is in charge of copying the files and that is what is not happening when I use the Trellis deploy role.

Maybe I should debug the composer-dropin-installer and see if everything works when deploying. Maybe the files aren’t there when the plugin is trying to move them…

Let me debug that and I’ll come with the results.

My apologies, I was tired and didn’t look too closely when I thought I’d found the problem. You’re correct about that line: it’s unrelated to your problem.

I’m not sure what Is causing your problem, but my guess is that it may have to do with the vendors folder being copied during a deploy (see: Johnpbloch/wordpress moved to a new configuration and WP goes missing). IIRC Trellis does this to speed up deploys, but it may be that when it does, it prevents the “install” event from happening on your package because it is already “installed” from the perspective of Composer. You might be able to solve the issue by removing vendor from project_copy_folders.

2 Likes

That’s great! @alwaysblank that solved the problem. You are right, I’ve tested it and it works like a charm now!! Thank you very much!!

I didn’t know about that feature to speed up the deploy process. It was driving me mad because all the steps I reproduced manually in the server seem to be right so I couldn’t explain why it wasn’t working.

I can confirm too that leaving no_scripts: yes in /trellis/roles/deploy/hooks/build_after.yml doesn’t let Koodimonni plugin to move the language files when installed, so that part of the file should look like this:

- name: Install Composer dependencies
   composer:
     no_scripts: no
     working_dir: "{{ deploy_helper.new_release_path }}"

Thank you very much again!!! I owe you a beer or two ;D

1 Like

Awesome, glad you got it figured out!

1 Like

From Oct the 18th I had an issue derived from commenting out the vendor line from project_copy_folders variable. The problem was that I’ve been getting nested current folders on every deploy. I haven’t noticed this problem until now.

The solution is to declare the project_copy_folders variable as an empty array.

More info here:

1 Like