Skip to content

Instantly share code, notes, and snippets.

@viniciusbig
Forked from sakanaproductions/deploy.php
Created September 13, 2018 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viniciusbig/e4a6fa5296e4e405efe3f6f2a7486b6f to your computer and use it in GitHub Desktop.
Save viniciusbig/e4a6fa5296e4e405efe3f6f2a7486b6f to your computer and use it in GitHub Desktop.
PHP Deployer Config File for VPS on Dreamhost
<?php
namespace Deployer;
require 'recipe/laravel.php';
// Project name
set('application', '');
// Project repository
set('repository', 'git@bitbucket.org');
// [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