Magento 2 Recipe: Use roles to execute DB tasks only on one server
dverkade opened this issue · comments
Description
Have a Magento 2 deployment with 4 webservers. 3 webservers serve traffic for users. 1 webserver is used for the backend of Magento. Database, Redis, Elasticsearch / Opensearch is on a separate server.
Current situation
When deploying the setup:upgrade command runs on all 4 webservers
Expected situation
I've defined the roles in the hosts configuration. The "DB" role is only set on the server used for the Magento backend. I expect the setup:upgrade command and other DB related commands to be run on the server with the "DB" role only. Servers without that role should skip the step.
I feel this is pretty specific for your setup, do we need to put this in the generic recipe?
@peterjaap, I'm sorry, but a multi server setup is not pretty specific IMHO. We've moved over from Capistrano which was supporting it like this: https://github.com/davidalger/capistrano-magento2/blob/master/lib/capistrano/tasks/magento.rake#L256 Run DB upgrade (and other) commands only on the primary server. I think this is a valid use case and something to look into.
Well Deployer already supports it, the question is whether we are going to adjust the Magento 2 recipe to be primarily multi-server or single server. Or is there a way to support both out of the box?
Guess it should be able to support both use cases out of the box. But need to do research how :-) As long as the recipe is backwards compatible is should be ok.
Ahmm… what about:
https://deployer.org/docs/7.x/tasks#once
Ahmm… what about: https://deployer.org/docs/7.x/tasks#once
Nice! Let me look into that.
I'd suggest to take a look at select()
which is more versatile; https://deployer.org/docs/7.x/api#select
You can do a combination of stages and roles to target exactly the servers you want to target.
imho select is for specific usecase, while once() can go into the default recipe :-) But it is not mine recipe, so I'll leave it up to you 🤞 <3