Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony Composer install without clearing cache

We are using a different cache dir to the default one and are using build agents for deployment. We run the composer install on the build agent where the cache dir doesn't exist, and then rsync it over to the web servers where we then run the command to clear and warm up the cache (all done from a Bamboo deployment).

Of course an error comes back in the logs as it can't create the cache dir when the composer install runs on the agent (and we don't want it to as we do this after).

Is there any way that when I run the composer install I can get it to skip the cache clear? I can't see it as a parameter option for composer.

like image 576
MicWit Avatar asked Nov 03 '16 00:11

MicWit


2 Answers

All you need is to remove following line:

"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",

from post-install-cmd and/or post-update-cmd section in your composer.json file.

Assuming you're build agent is doing install, and not update, it may be useful, to keep this line in post-update-cmd section for development work.

like image 147
Jakub Matczak Avatar answered Sep 22 '22 18:09

Jakub Matczak


As much as others say it doesn't, Sensio\Bundle\DistributionBundle\Composer\ScriptHandler‌​::installAssets will do a cache clear if required which will cause issues if you can not write to cache (I do this once rsynced from build agent onto live server).

The only way I can find at the moment to get around this is to remove the 2 lines from composer.json:

"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",

and then once you are on the server that has your cache dir available, run the following 2 commands (by this stage you should have already done your composer install/update):

php bin/console cache:clear --env=prod --no-debug
php bin/console assets:install --env=prod

The assets:install may or may not be needed depending on the vendor bundles installed. Anything that uses the "public" folder to store resources will need this so that the symbolic links are set up correctly for /web/bundles/bundleName. I also do an assetic dump after this.

By doing this you can now do the long parts (git clone and composer install) on a separate server or in a different directory and then rsync it across to where you want it to go. Then you just refresh and warm up the cache and do the final config of assets/assetic (or anything you are doing that requires cache) with minimal down time or any issues of your site going down if something goes wrong half way through deployment.

like image 44
MicWit Avatar answered Sep 25 '22 18:09

MicWit