Skip to content

Remove --no-scripts from PHP composer install command#464

Open
Spirit55555 wants to merge 2 commits intorailwayapp:mainfrom
Spirit55555:patch-1
Open

Remove --no-scripts from PHP composer install command#464
Spirit55555 wants to merge 2 commits intorailwayapp:mainfrom
Spirit55555:patch-1

Conversation

@Spirit55555
Copy link

--no-scripts prevents pre-install-cmd and post-install-cmd events from running.

I see no reason to prevent this and I had to add a workaround to my own applications, due to this.

It was added as part of this commit: 1547fa7

--no-scripts prevents pre-install-cmd and post-install-cmd events from running.
@iloveitaly
Copy link
Collaborator

@Spirit55555 I'm not familiar with the PHP ecosystem, unfortunately! So you'll have to walk me through this.

  • My understanding is some pre/post install scripts require access to the runtime environment, not just a build environment (possible database access, etc). Does this sound right to you?
  • What workaround did you end up using in your app?
  • Which framework are you using? It's possible for us to specialize the defaults a bit more for different PHP environments.

@Spirit55555
Copy link
Author

@Spirit55555 I'm not familiar with the PHP ecosystem, unfortunately! So you'll have to walk me through this.

* My understanding is _some_ pre/post install scripts require access to the runtime environment, not just a build environment (possible database access, etc). Does this sound right to you?

In post. yes, it's possible.
But then I think it's better it fails, instead of now, where it silently does not run it.

Maybe add support for an env like COMPOSER_INSTALL_ARGS where --no-scripts could be added if needed?

* What workaround did you end up using in your app?

I added a railpack.json file with the following:

{
	"$schema": "https://schema.railpack.com",
	"steps": {
		"composer-run-scripts": {
			"inputs": [
				{
					"step": "build"
				}
			],
			"commands": [
				"composer run-script post-install-cmd"
			]
		}
	}
}
* Which framework are you using? It's possible for us to specialize the defaults a bit more for different PHP environments.

I do not use a framework and I unfortunately have no experience with development using Laravel.

@iloveitaly
Copy link
Collaborator

@Spirit55555 Thanks so much for the detail. I'll need to read up on how all of these PHP frameworks operate a bit more. The tests are failing here, so I can't merge this without understanding the different patterns and improving a generalized solution here.

@Spirit55555
Copy link
Author

@iloveitaly The error looks like a file permission issue to me, but I will have to test some to be sure.

@Spirit55555
Copy link
Author

@iloveitaly After a bit of testing, it seems like the issue is that Composer is run before the copy / /app command. Composer needs access to all the files, as it might run pre/post scripts in other PHP files.

@iloveitaly
Copy link
Collaborator

@Spirit55555 in what cases would an installation process require access to the entire app? Just not familiar with the PHP ecosystem, and in ruby/python/go/typescript (which I'm familiar with) packages generally don't need access to your application source code.

The reason we try to separate build from install steps is to enable layer caching to repeats builds are much faster (i.e. if the same dependencies are used, no need to redownload them).

@Spirit55555
Copy link
Author

@iloveitaly From the documentation: https://getcomposer.org/doc/articles/scripts.md

A script, in Composer's terms, can either be a PHP callback (defined as a static method) or any command-line executable command. Scripts are useful for executing a package's custom code or package-specific commands during the Composer execution process.

There are plenty of examples here on GitHub: https://github.com/search?q=%22post-install-cmd%22&type=code

The default is to run the pre/post scripts, so I think there should be very good reasons not to do this.

If you want to download the dependencies early in the process, you could run composer install with --download-only and then run the actual install later, when all the files are available:
composer install --no-dev --download-only --no-interaction

And later:
composer install --no-dev --optimize-autoloader --no-interaction

@iloveitaly
Copy link
Collaborator

@Spirit55555 Super helpful. This all makes sense. I need to spend some time with it and think through what changes are breaking, etc. I'm going to be able to get to it this week, but I think I have all of the detail I need from you, which is great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants