rocketeers/rocketeer

After setup hook not firing

tomvo opened this issue · 10 comments

tomvo commented

I just did a fresh rocketeer ignite in a fresh repo and wanted to run npm run prod command on remote server to run before symlinking but after cloning. Reckoned this would be after.setup.

I have this:

    'after'  => [
        'setup'   => [
            'npm run prod',
        ],
        'deploy'  => [],
        'cleanup' => [],
    ],

Doesn't seem to work.
This is the output when I run with verbose and pretend, so it's missing the call to the after setup hook. I get the same output when I actually deploy.

$ rocketeer deploy --pretend --verbose
No username is set for [repository], please provide one:
No password is set for [repository], please provide one:
production/0/v2         | Deploy (Deploys the website)

Warning: unpack(): Type N: not enough input, need 4, have 1 in phar:///usr/local/bin/rocketeer/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php on line 2826

Warning: extract() expects parameter 1 to be array, boolean given in phar:///usr/local/bin/rocketeer/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php on line 2826

Notice: Undefined variable: length in phar:///usr/local/bin/rocketeer/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php on line 2827
production/0/v2         |-- Primer (Run local checks to ensure deploy can proceed)
production/0/v2         |-- CreateRelease (Creates a new release on the server)
production/0/v2         |---- Deploy/Clone (Clones a fresh instance of the repository by SCM)
production/0/v2         |===> Cloning repository in "/data/www/xxxxxxx.com/v2/releases/20170725171056"
$ /usr/bin/git clone "git@bitbucket.org:xxxxxxx/xxxxxxx-laravel-5.git" "/data/www/xxxxxxx.com/v2/releases/20170725171056" --branch="master" --depth="1"
production/0/v2         |===> Initializing submodules if any
$ cd /data/www/xxxxxxx.com/v2/releases/20170725171056
$ /usr/bin/git submodule update --init --recursive
production/0/v2         |-- Dependencies (Installs or update the dependencies on server)
production/0/v2         |---- Dependencies/Polyglot (Runs all of the above package managers if necessary)
production/0/v2         |------ Dependencies/Composer (Installs dependencies with Composer)
$ cd /data/www/xxxxxxx.com/v2/releases/20170725171056
$ /data/www/bin/composer install --no-interaction --no-dev --prefer-dist
production/0/v2         |------ Dependencies/Npm (Installs dependencies with NPM)
$ cd /data/www/xxxxxxx.com/v2/releases/20170725171056
$ /usr/bin/npm install
production/0/v2         |------ Dependencies/Bower (Installs dependencies with Bower)
$ cd /data/www/xxxxxxx.com/v2/releases/20170725171056
$ bower install
production/0/v2         |=> Sharing file /data/www/xxxxxxx.com/v2/releases/20170725171056/storage/logs
$ ln -s /data/www/xxxxxxx.com/v2/shared/storage/logs /data/www/xxxxxxx.com/v2/releases/20170725171056/storage/logs-temp
$ mv -Tf /data/www/xxxxxxx.com/v2/releases/20170725171056/storage/logs-temp /data/www/xxxxxxx.com/v2/releases/20170725171056/storage/logs
production/0/v2         |=> Sharing file /data/www/xxxxxxx.com/v2/releases/20170725171056/storage/sessions
production/0/v2         |=> Sharing file /data/www/xxxxxxx.com/v2/releases/20170725171056/.env
$ ln -s /data/www/xxxxxxx.com/v2/shared/.env /data/www/xxxxxxx.com/v2/releases/20170725171056/.env-temp
$ mv -Tf /data/www/xxxxxxx.com/v2/releases/20170725171056/.env-temp /data/www/xxxxxxx.com/v2/releases/20170725171056/.env
production/0/v2         |=> Setting permissions for /data/www/xxxxxxx.com/v2/releases/20170725171056/storage
$ cd /data/www/xxxxxxx.com/v2/releases/20170725171056
$ chmod -R 2775 /data/www/xxxxxxx.com/v2/releases/20170725171056/storage
$ chgrp -R www-data /data/www/xxxxxxx.com/v2/releases/20170725171056/storage
production/0/v2         |=> Setting permissions for /data/www/xxxxxxx.com/v2/releases/20170725171056/public
$ cd /data/www/xxxxxxx.com/v2/releases/20170725171056
$ chmod -R 2775 /data/www/xxxxxxx.com/v2/releases/20170725171056/public
$ chgrp -R www-data /data/www/xxxxxxx.com/v2/releases/20170725171056/public
production/0/v2         |=> Setting permissions for /data/www/xxxxxxx.com/v2/releases/20170725171056/bootstrap/cache
$ cd /data/www/xxxxxxx.com/v2/releases/20170725171056
$ chmod -R 2775 /data/www/xxxxxxx.com/v2/releases/20170725171056/bootstrap/cache
$ chgrp -R www-data /data/www/xxxxxxx.com/v2/releases/20170725171056/bootstrap/cache
$ mv /data/www/xxxxxxx.com/v2/current /data/www/xxxxxxx.com/v2/releases/20170725171056
$ ln -s /data/www/xxxxxxx.com/v2/releases/20170725171056 /data/www/xxxxxxx.com/v2/current-temp
$ mv -Tf /data/www/xxxxxxx.com/v2/current-temp /data/www/xxxxxxx.com/v2/current
production/0/v2         |=> Successfully deployed release 20170725171056
production/0/v2         | Cleanup (Clean up old releases from the server)
$ rm -rf /data/www/xxxxxxx.com/v2/releases/20170725092259
production/0/v2         |=> Removing 1 release from the server
Execution time: 3.2825s

What version do you use? Develop branch?

tomvo commented

@miholeus nope, just the one from here: http://rocketeer.autopergamene.eu/versions/rocketeer.phar

$ rocketeer -v
Rocketeer version 2.2.5

Yeah, I have the same problem. Need time to fix it :)

tomvo commented
tomvo commented

@Anahkiasen You have any input on this Maxime? It's kind of a deal-breaker for our current deploy strategy to go and do database migrations and asset compiling only after deploying and symlinking.

Setup is not the correct task to hook on, you should hook into before.deploy in R2 IIRC. setup is what is executed on the very first deploy to the server (to prep it) to create the current/releases/shared folders, it's only run once but in any case the normal deploy task runs right after. Should work in theory

You can find more infos about events over here, you're not limited to the three present in the configuration by default, there are more http://rocketeer.autopergamene.eu/II-Concepts/Events.html

tomvo commented

Thanks for your input, much appreciated. I'm using rocketeer as a standalone version, not loaded through the application composer deps hence don't have the Facade available. Where would the best place be then to define those event listeners?

The facade should work regardless of how you load Rocketeer, it has its own bootstrap mechanism so using it as a normal static class should work in theory. Usually events can be put in .rocketeer/tasks.php (I think events.php also works on Rocketeer 2 but not sure)

tomvo commented

Managed to get it working by creating an events.php file and adding this:

<?php
use Rocketeer\Facades\Rocketeer;

Rocketeer::addTaskListeners('deploy', 'before-symlink', function ($task) {
    $task->runForCurrentRelease([
        'npm run prod',
    ]);
});

Thanks!