deej
deej

Reputation: 2564

php composer install or NOT? for production environments

I am working on Laravel webapp right now and kept vendor directory out of git (version control) so far and every time for fresh install I used to have composer install command added to automated script and everything was fine.

Now just 2 days back I added added laravelcollective (https://laravelcollective.com/) to my project for helping me with forms and html in blade templates. Now somehow one of the dependency requires me to generate GIT private token to install it and that is pain as it would hurt my automation. I can still hack it by calling the url and scrapping html to read token and stuff like that but I don't like it. And then I thought is it good idea to keep vendor directory out of SVN/GIT? Isn't source code for a product contain all dependencies within itself? I am not talking about stuffing JRE in the installer but when it comes to libraries of a product in native language.

I would like to hear more about it on industry standards or best practices on this.

P.S: This question is much generic and not just limited to laravel or even php for the matter.

Upvotes: 0

Views: 220

Answers (2)

ceejayoz
ceejayoz

Reputation: 180023

Now somehow one of the dependency requires me to generate GIT private token to install it and that is pain as it would hurt my automation.

You're just running into Github's rate limits for package downloads for anonymous users. No reason you can't automate this. Generate a Github token (you only need to do it once - they get very high rate limits for authenticated requests), then have your automation use that token like so:

composer config -g github-oauth.github.com <oauthtoken>

https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens

Upvotes: 2

Denis Mysenko
Denis Mysenko

Reputation: 6534

Well, for production environment you usually run a build process first in your CI software. If 'composer install' fails during the build – application won't be deployed to production environment, so you are safe.

Yes, most (99%+) people keep 'vendor' folder out of the repo because it's a third-party code, it's not yours. You may not even have rights to host it in your repo.

If you want to be sure that your production version will have all the dependencies in order, the way you had them during CI, and will always release – you could build Docker images and ship them to production. Then, everything comes prepackaged.

Upvotes: 1

Related Questions