Created
August 7, 2018 10:32
-
-
Save itsgoingd/808970461d528f52212a9a9036840d68 to your computer and use it in GitHub Desktop.
Deployer configuration for a Laravel app example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace Deployer; | |
require 'recipe/composer.php'; | |
require 'recipe/npm.php'; | |
require 'recipe/slack.php'; | |
// Project name | |
set('application', 'Project Name'); | |
// Project repository | |
set('repository', '[email protected]:my/project.git'); | |
// Shared files/dirs between deploys | |
add('shared_files', [ | |
'.env' | |
]); | |
add('shared_dirs', [ | |
'public/files', | |
'public/images/patterns', | |
'storage' | |
]); | |
set('default_stage', 'staging'); | |
set('allow_anonymous_stats', false); | |
set('slack_webhook', 'https://hooks.slack.com/services/123/321/asdf'); | |
set('user', function () { | |
return getenv('GITLAB_USER_LOGIN') ?: runLocally('git config --get user.name'); | |
}); | |
// Hosts | |
host('example.com') | |
->stage('production') | |
->user('example') | |
->forwardAgent(false) | |
->set('deploy_path', '/Sites/example.com'); | |
host('test.example.com') | |
->stage('staging') | |
->user('example') | |
->forwardAgent(false) | |
->set('deploy_path', '/Sites/test.example.com'); | |
// Tasks | |
desc('Execute artisan migrate'); | |
task('artisan:migrate', function () { | |
run('{{bin/php}} {{release_path}}/artisan migrate --force'); | |
}); | |
desc('Execute artisan config:cache'); | |
task('artisan:config:cache', function () { | |
run('{{bin/php}} {{release_path}}/artisan config:cache'); | |
}); | |
desc('Execute artisan route:cache'); | |
task('artisan:route:cache', function () { | |
run('{{bin/php}} {{release_path}}/artisan route:cache'); | |
}); | |
desc('Execute artisan queue:restart'); | |
task('artisan:queue:restart', function () { | |
run('{{bin/php}} {{release_path}}/artisan queue:restart'); | |
}); | |
desc('Execute npm run production'); | |
task('npm:run:production', function () { | |
run('cd {{release_path}} && {{bin/npm}} run production'); | |
}); | |
desc('Restart php-fpm'); | |
task('php:restart', function () { | |
run('sudo /etc/init.d/php7.0-fpm restart'); | |
}); | |
desc('Prepare a new release'); | |
task('prepare', [ | |
'artisan:config:cache', | |
'artisan:route:cache', | |
'artisan:migrate', | |
'npm:install', | |
'npm:run:production' | |
]); | |
// Prepare app before symlinking new release. | |
before('deploy:symlink', 'prepare'); | |
after('deploy:symlink', 'artisan:queue:restart'); | |
after('deploy:symlink', 'php:restart'); | |
// [Optional] if deploy fails automatically unlock. | |
after('deploy:failed', 'deploy:unlock'); | |
// Slack notifications | |
before('deploy', 'slack:notify'); | |
after('success', 'slack:notify:success'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment