Skip to content

Instantly share code, notes, and snippets.

@chadwithuhc
Created April 9, 2014 00:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadwithuhc/10212852 to your computer and use it in GitHub Desktop.
Save chadwithuhc/10212852 to your computer and use it in GitHub Desktop.
Rocketeer PHP Hook Sample
<?php
/**
* Used to run any after deploy tasks:
* - Migrate DB
* - Clear expired password reminder tokens
* - Clear caches
* - Remove any unwanted files from the server
*/
$deploy_cleanup = function ($task) {
confirm_stage($task);
//$release_dir = $task->releasesManager->getCurrentReleasePath();
$seed = $task->command->option('seed');
if ($seed) {
$task->command->comment('Migrating Database + Seed');
$task->runForCurrentRelease(array(
// Refresh the database
'php artisan migrate --seed',
));
}
else {
$task->command->comment('Migrating Database');
$task->runForCurrentRelease(array(
// Migrate the database
'php artisan migrate',
));
}
$task->command->comment('Clearing caches');
$task->runForCurrentRelease(array(
// Clear any expired password reminders
'php artisan auth:clear-reminders',
// Clear caches
'php artisan cache:clear',
));
$task->command->comment('Removing development files');
$task->runForCurrentRelease(array(
'rm -rf app/config/local',
'rm artisan',
'rm composer*',
'rm Gruntfile.js',
'rm package.json',
'rm phpunit.xml',
'rm readme*',
'rm server.php'
));
};
if (!function_exists('confirm_stage')) {
function confirm_stage(&$task) {
$actual_stage = $task->runForCurrentRelease('php artisan env');
$stage = $task->rocketeer->getStage();
$correct_stage = preg_match("/\\s".$stage."$/usm", $actual_stage);
if ($correct_stage) {
$task->command->info('Running in the correct stage: ' . $stage);
}
else {
$task->command->error('Are your stages set up correctly? Currently running in: ' . $stage);
}
}
}
return array(
// Tasks
//
// Here you can define in the `before` and `after` array, Tasks to execute
// before or after the core Rocketeer Tasks. You can either put a simple command,
// a closure which receives a $task object, or the name of a class extending
// the Rocketeer\Traits\Task class
//
// In the `custom` array you can list custom Tasks classes to be added
// to Rocketeer. Those will then be available in the command line
// with all the other tasks
//////////////////////////////////////////////////////////////////////
// Tasks to execute before the core Rocketeer Tasks
'before' => array(
'setup' => array(),
'deploy' => array(),
'cleanup' => array(),
),
// Tasks to execute after the core Rocketeer Tasks
'after' => array(
'setup' => array(),
'deploy' => array(
$deploy_cleanup
),
'cleanup' => array(),
),
// Custom Tasks to register with Rocketeer
'custom' => array(),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment