Created
February 12, 2018 19:59
-
-
Save sakanaproductions/ace5d003c58167305bcd41e4b6166949 to your computer and use it in GitHub Desktop.
PHP Deployer Config File for VPS on Dreamhost
This file contains hidden or 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/laravel.php'; | |
// Project name | |
set('application', ''); | |
// Project repository | |
set('repository', '[email protected]'); | |
// [Optional] Allocate tty for git clone. Default value is false. | |
set('git_tty', true); | |
// Set default stage to staging | |
set('default_stage', 'staging'); | |
// Shared files/dirs between deploys | |
add('shared_dirs', []); | |
// Copy directorys between releases | |
add('copy_dirs', [ | |
'node_modules' | |
]); | |
// Writable dirs by web server | |
add('writable_dirs', []); | |
// Hosts | |
host('staging') | |
->hostname('') | |
->stage('staging') | |
->set('branch','staging') | |
->set('deploy_path', '') | |
->configFile('~/.ssh/config'); | |
host('production') | |
->hostname('') | |
->stage('production') | |
->set('branch','production') | |
->set('deploy_path', '') | |
->configFile('~/.ssh/config'); | |
// Tasks | |
desc('NPM'); | |
task('npm', function () { | |
if (has('previous_release')) { | |
$result = run('cp -R {{previous_release}}/node_modules {{release_path}}/node_modules'); | |
writeln('node modules copied'); | |
} | |
$result = run('cd {{release_path}} && npm install'); | |
writeln($result); | |
}); | |
task('build', function () { | |
$result = run('cd {{release_path}} && pwd'); | |
writeln("Current dir: $result"); | |
}); | |
// Need to add key to agent every time for SSH to work | |
desc('Add SSH Key to the SSH Agent'); | |
task('ssh-add', function() { | |
$result = run('eval `ssh-agent -s`'); | |
writeln("Agent: $result"); | |
$result = run('ssh-add ~/.ssh/bitbucket.key'); | |
writeln("SSH Added"); | |
}); | |
desc('Copy environment variables'); | |
task('env-vars', 'cp .env{.staging,}'); | |
desc('Install Migration'); | |
task('artisan:migrate-install', '{{bin/php}} {{release_path}}/artisan migrate:install')->once(); | |
desc('Webpack'); | |
task('webpack', function() { | |
$deploy = get('deploy_path'); | |
if(preg_match('/staging/', $deploy)) { | |
$result = run('cd {{release_path}} && npm run dev'); | |
} else { | |
$result = run('cd {{release_path}} && npm run prod'); | |
} | |
writeln($result); | |
}); | |
// [Optional] if deploy fails automatically unlock. | |
after('deploy:failed', 'deploy:unlock'); | |
// Migrate database before symlink new release. | |
before('deploy:symlink', 'artisan:migrate'); | |
// in Dreamhost need to add key to ssh-agent | |
before('deploy:update_code', 'ssh-add'); | |
// copy the right env var to the system | |
before('artisan:storage:link','env-vars'); | |
before('artisan:migrate', 'npm'); | |
after('artisan:migrate', 'webpack'); | |
// overwrite shared files for recipe/laravel | |
set('shared_files', []); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment