rocketeers / rocketeer

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

After setup hook not firing #758

Closed tomvo closed 7 years ago

tomvo commented 7 years ago

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
miholeus commented 7 years ago

What version do you use? Develop branch?

tomvo commented 7 years ago

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

$ rocketeer -v
Rocketeer version 2.2.5
miholeus commented 7 years ago

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

tomvo commented 7 years ago

Any clue on where to start looking? it’s kind of important for our deploy strategy to be able to compile assets before symlinking to current from release and deploying :-) One option would be to compile client side and copy the files over of course...

On 28 Jul 2017, at 14:53, miholeus notifications@github.com wrote:

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

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rocketeers/rocketeer/issues/758#issuecomment-318644114, or mute the thread https://github.com/notifications/unsubscribe-auth/ABbwmdt4P5wWG_iqHdBCOT9w-Xt5ZEQqks5sSdnhgaJpZM4Ois1-.

tomvo commented 7 years ago

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

Anahkiasen commented 7 years ago

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

Anahkiasen commented 7 years ago

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 7 years ago

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?

Anahkiasen commented 7 years ago

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 7 years ago

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!