rocketeers / rocketeer

Send your projects up in the clouds
http://rocketeer.autopergamene.eu/
MIT License
2.67k stars 217 forks source link

Server Roles #380

Closed ShonM closed 9 years ago

ShonM commented 9 years ago

Please bare with me if this sounds stupid, but... Is there any concept of roles or groups? I caught a couple mentions of this, but it's very scattered (here's one https://github.com/rocketeers/rocketeer/issues/37#issuecomment-22988150), so I wanted to focus the discussion a bit. Let me explain how I would like to deploy, maybe there's something that fits...

  1. Grab new code, deps, et al on every server
  2. Build PHP-land caches (templating, containers, etc) on every server
  3. Build assets only on the static asset server
  4. Reload the web server only on the web server

More than that, I'd love if I could do all the code updates on all servers, then only build assets on just the asset server, and the same thing for the web server. So it's something like "grouping tasks on servers within a connection" or something like that.

Is this something I could hack together easily? Is there a clear official path to get it into the codebase? If so, I'd be happy to start figuring that out and submit a PR back once I've got it all figured out.

ShonM commented 9 years ago

Oh, some casual conversation with another author led me to these:

And that's enough to work something off of, awesome! I won't write out code for the core quite yet, since this looks like it will work just fine in my case.

ShonM commented 9 years ago

For anyone who stumbles into this issue, here's what I've done so far. In the connection config:

    'connections' => array(
        'local' => array(
            'host'          => 'www.c.com',
            'username'      => 'vagrant',
            'key'           => true,
            'agent'         => true,
            'agent-forward' => true,
            'roles'         => array('web', 'asset', 'balance'),
        ),

Then in my tasks:

<?php

use Rocketeer\Abstracts\AbstractTask;

class Nginx extends AbstractTask
{
    protected $role = 'balance';

    public function execute()
    {
        $serverCredentials = $this->connections->getServerCredentials();
        $multiserver       = $this->connections->isMultiserver($this->connections->getConnection());
        $hasRole           = (isset($serverCredentials['roles']) && in_array($this->role, $serverCredentials['roles']));

        // Skip this task if there's no reason to run it
        if ($multiserver === true && $hasRole === false) {
            return true;
        }

        // rest of the task
    }
}

Now to work out a parent that does this more automagically :)

Anahkiasen commented 9 years ago

Feature seems interesting, if it were introduced though I think it would be in a separate class (ie. not the ConnectionsHandler) so you could have global roles and per-connection roles, etc. If you want to PR it I'm up for it.

bkuhl commented 7 years ago

Thanks for the followup @ShonM, I'm using your approach.