Last active
March 31, 2022 17:10
-
-
Save gonssal/8594e60bae7963a1f45f196b96b4a318 to your computer and use it in GitHub Desktop.
Deployer script for locally-built composer-based Drupal 8 deployment. Drush heavily used, including sql-dump for backup.
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 | |
/** | |
* @file | |
* Deployment script for composer-based Drupal 8 installations using Deployer. | |
*/ | |
namespace Deployer; | |
use Deployer\Support\Unix; | |
require 'recipe/common.php'; | |
// Project name. | |
set('application', 'your_project_name'); | |
// Project repository. | |
set('repository', 'file://' . __DIR__ . '/.git'); | |
// Local build path. | |
set('local_build_path', Unix::parseHomeDir('~') . "/.deployer/build/{{application}}"); | |
set('writable_mode', 'chmod'); | |
// Releases to keep. | |
set('keep_releases', 3); | |
set('allow_anonymous_stats', FALSE); | |
// Hosts. | |
host('example.com') | |
->user('your_user') | |
->port(2220) | |
->identityFile('~/.ssh/your_identity_file') | |
->forwardAgent(TRUE) | |
->multiplexing(TRUE) | |
->set('deploy_path', '~/httpdocs'); | |
// Drupal settings. | |
// Set drupal site. Change if you use different site. | |
set('drupal_site', 'default'); | |
// Drupal 8 shared dirs. | |
set('shared_dirs', [ | |
'web/sites/{{drupal_site}}/files', | |
'web/sites/{{drupal_site}}/private', | |
'web/libraries', | |
]); | |
// Drupal 8 shared files. | |
set('shared_files', [ | |
'web/sites/{{drupal_site}}/settings.local.php', | |
'web/sites/{{drupal_site}}/settings.php', | |
'web/sites/{{drupal_site}}/services.yml', | |
]); | |
// Drupal 8 Writable dirs. | |
set('writable_dirs', [ | |
'web/sites/{{drupal_site}}/files', | |
]); | |
// Build the code locally. | |
task('build', function () { | |
set('deploy_path', "{{local_build_path}}"); | |
invoke('deploy:prepare'); | |
invoke('deploy:release'); | |
invoke('deploy:update_code'); | |
invoke('deploy:vendors'); | |
invoke('deploy:symlink'); | |
})->local(); | |
// Upload the code with rsync (built-in Deployer upload function). | |
task('upload', function () { | |
upload("{{local_build_path}}/current/", '{{release_path}}', [ | |
'options' => [ | |
"--exclude '.git'", | |
], | |
]); | |
}); | |
// Drush commands to finalize the deployment. | |
set('php_bin_path', '/usr/bin/env php'); | |
set('drush_bin_path', '{{deploy_path}}/current/vendor/bin/drush'); | |
set('drush_command', '{{php_bin_path}} -d memory_limit=512M {{drush_bin_path}}'); | |
set('drush_sql_dump_args', 'sql-dump --gzip --result-file={{application}}-sql-dump.sql'); | |
if (has('previous_release')) { | |
set('drush_sql_dump_args', 'sql-dump --gzip --result-file={{previous_release}}/{{application}}-sql-dump.sql'); | |
} | |
task('drush:prepare', function () { | |
run('{{drush_command}} cc drush'); | |
run('{{drush_command}} cr'); | |
run('{{drush_command}} {{drush_sql_dump_args}}'); | |
}); | |
task('drush:update', function () { | |
run('{{drush_command}} sset system.maintenance_mode 1'); | |
run('{{drush_command}} updatedb -y'); | |
run('{{drush_command}} config-import -y'); | |
run('{{drush_command}} updatedb -y'); | |
run('{{drush_command}} cr'); | |
run('{{drush_command}} sset system.maintenance_mode 0'); | |
}); | |
// The deploy task. Based on the built-in drupal8 recipe. | |
// @see recipe/drupal8.php | |
task('deploy', [ | |
'build', | |
'deploy:info', | |
'deploy:prepare', | |
'deploy:lock', | |
'deploy:release', | |
'upload', | |
'drush:prepare', | |
'deploy:shared', | |
'deploy:writable', | |
'deploy:symlink', | |
'drush:update', | |
'deploy:unlock', | |
'cleanup', | |
]); | |
task('drush:maintenance:disable', function () { | |
run('{{drush_command}} sset system.maintenance_mode 0'); | |
}); | |
// [Optional] if deploy fails automatically unlock. | |
after('deploy:failed', 'deploy:unlock'); | |
after('deploy:failed', 'drush:maintenance:disable'); | |
after('deploy', 'success'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment