deployphp / deployer

The PHP deployment tool with support for popular frameworks out of the box
https://deployer.org
MIT License
10.56k stars 1.48k forks source link

Magento 2 Recipe: Use roles to execute DB tasks only on one server #3800

Closed dverkade closed 5 months ago

dverkade commented 5 months ago

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.

Upvote & Fund

Fund with Polar

peterjaap commented 5 months ago

I feel this is pretty specific for your setup, do we need to put this in the generic recipe?

dverkade commented 5 months ago

@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.

peterjaap commented 5 months ago

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?

dverkade commented 5 months ago

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.

Schrank commented 5 months ago

Ahmm… what about: https://deployer.org/docs/7.x/tasks#once

dverkade commented 5 months ago

Ahmm… what about: https://deployer.org/docs/7.x/tasks#once

Nice! Let me look into that.

peterjaap commented 5 months ago

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.

Schrank commented 5 months ago

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