Skip to content

Instantly share code, notes, and snippets.

@wmgodyak
Forked from freekmurze/deploy.php
Created November 26, 2017 20:45
Show Gist options
  • Save wmgodyak/bb29abbf9dc969b5c613816aabc5512f to your computer and use it in GitHub Desktop.
Save wmgodyak/bb29abbf9dc969b5c613816aabc5512f to your computer and use it in GitHub Desktop.
A sample deploy.php file that can be used with Deployer (http://deployer.in)
<?php
/*
* Define the servers
*/
server('production-web', '<your server url>')
->path('<path to the project on your server>')
->user('<user on the server>')
->pubKey();
/*
* Define the states
*/
stage('master', ['production-web'], ['branch' => 'master']);
/*
* Make sure we are on the right branch
*/
task('deploy:checkout', function () {
runLocally('git checkout '.get('branch', '').' 2> /dev/null');
})->desc('checking out git branch');
/*
* Bring the app on the server down
*/
task('deploy:app_down', function () {
run('php artisan down');
run('php artisan cache:clear');
})->desc('bringing app down');
/*
* Pull the changes onto the server
*/
task('deploy:pull_changes', function () {
run('git pull origin '.get('branch', '').' 2> /dev/null');
run('php artisan cache:clear');
})->desc('pull changes on server');
/*
* Locally generate assets and transfer them to the server
*/
task('deploy:generate_assets', function () {
runLocally('gulp compile');
run('rm -rf public/assets/*');
upload('public/assets/', 'public/assets/');
})->desc('generating assets');
/*
* Run composer install on the server
*/
task('deploy:composer_install', function () {
run('composer install');
})->desc('running composer install');
/*
* Run the migrations on the server
*/
task('deploy:run_migrations', function () {
run('php artisan db:backup');
run('php artisan migrate --force --env=production');
})->desc('running migrations');
/*
* Bring the app back up
*/
task('deploy:app_up', function () {
run('php artisan cache:clear');
run('php artisan up');
})->desc('bringing app up');
/*
* Run all the tasks in the right order
*/
task('deploy',
[
'deploy:checkout',
'deploy:app_down',
'deploy:pull_changes',
'deploy:generate_assets',
'deploy:composer_install',
'deploy:run_migrations',
'deploy:app_up',
]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment