2015-07-15 19:38:50 +02:00
|
|
|
<?php
|
2015-08-24 08:37:18 +07:00
|
|
|
/* (c) Sergio Carracedo <info@sergiocarraedo.es>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
2015-07-15 19:38:50 +02:00
|
|
|
|
2016-01-11 14:00:45 +07:00
|
|
|
namespace Deployer;
|
|
|
|
|
2015-08-24 08:37:18 +07:00
|
|
|
require_once __DIR__ . '/common.php';
|
2015-07-15 19:38:50 +02:00
|
|
|
|
2016-04-04 17:01:55 +07:00
|
|
|
task('deploy', [
|
2017-08-12 12:01:27 +03:00
|
|
|
'deploy:info',
|
2015-07-15 19:57:41 +02:00
|
|
|
'deploy:prepare',
|
2016-11-05 12:56:53 +07:00
|
|
|
'deploy:lock',
|
2015-07-15 19:38:50 +02:00
|
|
|
'deploy:release',
|
|
|
|
'deploy:update_code',
|
|
|
|
'deploy:shared',
|
|
|
|
'deploy:symlink',
|
2016-11-05 12:56:53 +07:00
|
|
|
'deploy:unlock',
|
2015-07-15 19:38:50 +02:00
|
|
|
'cleanup'
|
2015-08-24 08:37:18 +07:00
|
|
|
]);
|
2015-07-15 19:38:50 +02:00
|
|
|
|
2016-02-17 23:43:37 +01:00
|
|
|
//Set Drupal 7 site. Change if you use different site
|
2016-11-05 17:50:18 +07:00
|
|
|
set('drupal_site', 'default');
|
2015-07-15 19:38:50 +02:00
|
|
|
|
|
|
|
|
2015-08-24 08:37:18 +07:00
|
|
|
//Drupal 7 shared dirs
|
|
|
|
set('shared_dirs', [
|
2015-07-15 19:38:50 +02:00
|
|
|
'sites/{{drupal_site}}/files',
|
2015-08-24 08:37:18 +07:00
|
|
|
]);
|
2015-07-15 19:38:50 +02:00
|
|
|
|
2016-02-17 23:43:37 +01:00
|
|
|
//Drupal 7 shared files
|
2015-08-24 08:37:18 +07:00
|
|
|
set('shared_files', [
|
2015-07-15 19:38:50 +02:00
|
|
|
'sites/{{drupal_site}}/settings.php',
|
2015-08-24 08:37:18 +07:00
|
|
|
]);
|
2015-07-15 19:38:50 +02:00
|
|
|
|
2016-02-17 23:43:37 +01:00
|
|
|
//Drupal 7 writable dirs
|
2015-08-24 08:37:18 +07:00
|
|
|
set('writable_dirs', [
|
2015-07-15 19:57:41 +02:00
|
|
|
'sites/{{drupal_site}}/files',
|
2015-08-24 08:37:18 +07:00
|
|
|
]);
|
2015-07-15 19:38:50 +02:00
|
|
|
|
|
|
|
|
2015-08-24 08:37:18 +07:00
|
|
|
//Create and upload Drupal 7 settings.php using values from secrets
|
|
|
|
task('drupal:settings', function () {
|
2015-07-15 19:38:50 +02:00
|
|
|
if (askConfirmation('Are you sure to generate and upload settings.php file?')) {
|
2015-08-24 08:37:18 +07:00
|
|
|
$basepath = dirname(__FILE__) . '/drupal7';
|
|
|
|
|
|
|
|
//Import secrets
|
2016-11-05 17:50:18 +07:00
|
|
|
$secrets = get('settings');
|
2015-08-24 08:37:18 +07:00
|
|
|
|
|
|
|
//Prepare replacement variables
|
2016-01-11 14:36:42 +07:00
|
|
|
$iterator = new \RecursiveIteratorIterator(
|
|
|
|
new \RecursiveArrayIterator($secrets)
|
2015-08-24 08:37:18 +07:00
|
|
|
);
|
2015-07-15 19:38:50 +02:00
|
|
|
|
2015-07-15 19:57:41 +02:00
|
|
|
$replacements = [];
|
|
|
|
foreach ($iterator as $key => $value) {
|
|
|
|
$keys = [];
|
|
|
|
for ($i = $iterator->getDepth(); $i > 0; $i --) {
|
|
|
|
$keys[] = $iterator->getSubIterator($i - 1)->key();
|
|
|
|
}
|
|
|
|
$keys[] = $key;
|
2015-07-15 19:38:50 +02:00
|
|
|
|
2015-07-15 19:57:41 +02:00
|
|
|
$replacements['{{' . implode('.', $keys) . '}}'] = $value;
|
|
|
|
}
|
2015-07-15 19:38:50 +02:00
|
|
|
|
2015-08-24 08:37:18 +07:00
|
|
|
//Create settings from template
|
|
|
|
$settings = file_get_contents($basepath . '/settings.php');
|
2015-07-15 19:38:50 +02:00
|
|
|
|
2015-07-15 19:57:41 +02:00
|
|
|
$settings = strtr($settings, $replacements);
|
2015-07-15 19:38:50 +02:00
|
|
|
|
2015-07-15 19:57:41 +02:00
|
|
|
writeln('settings.php created succesfuly');
|
2015-07-15 19:38:50 +02:00
|
|
|
|
2015-07-15 19:57:41 +02:00
|
|
|
$tmpFilename = tempnam($basepath, 'tmp_settings_');
|
|
|
|
file_put_contents($tmpFilename, $settings);
|
2015-08-24 08:37:18 +07:00
|
|
|
|
|
|
|
upload($tmpFilename, '{{deploy_path}}/shared/sites/{{drupal_site}}/settings.php');
|
2015-07-15 19:38:50 +02:00
|
|
|
|
2015-07-15 19:57:41 +02:00
|
|
|
unlink($tmpFilename);
|
2015-07-15 19:38:50 +02:00
|
|
|
}
|
2015-08-24 08:37:18 +07:00
|
|
|
});
|
2015-07-15 19:38:50 +02:00
|
|
|
|
2015-08-24 08:37:18 +07:00
|
|
|
//Upload Drupal 7 files folder
|
|
|
|
task('drupal:upload_files', function () {
|
2015-07-15 19:38:50 +02:00
|
|
|
if (askConfirmation('Are you sure?')) {
|
2015-08-24 08:37:18 +07:00
|
|
|
upload('sites/{{drupal_site}}/files', '{{deploy_path}}/shared/sites/{{drupal_site}}/files');
|
2015-07-15 19:38:50 +02:00
|
|
|
}
|
2015-08-24 08:37:18 +07:00
|
|
|
});
|