deployer/recipe/drupal7.php

95 lines
2.4 KiB
PHP
Raw Normal View History

2015-07-15 19:38:50 +02:00
<?php
/* (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.
*/
use Symfony\Component\Yaml\Parser;
2015-07-16 13:35:24 +02:00
2015-07-15 19:57:41 +02:00
require_once __DIR__ . '/common.php';
2015-07-15 19:38:50 +02:00
2015-07-15 19:57:41 +02:00
task('deploy', [
'deploy:prepare',
2015-07-15 19:38:50 +02:00
'deploy:release',
'deploy:update_code',
'deploy:shared',
'deploy:symlink',
'cleanup'
2015-07-15 19:57:41 +02:00
]);
2015-07-15 19:38:50 +02:00
//Set drupal site. Change if you use different site
env('drupal_site', 'default');
//Drupal 7 shared dirs
set('shared_dirs', [
'sites/{{drupal_site}}/files',
]);
//Drupal 7 sharef files
set('shared_files', [
'sites/{{drupal_site}}/settings.php',
]);
//Drupal 7 Writable dirs
set('writable_dirs', [
2015-07-15 19:57:41 +02:00
'sites/{{drupal_site}}/files',
2015-07-15 19:38:50 +02:00
]);
//Create and upload Drupal 7 settings.php using values from secrets
task('drupal:settings', function () {
if (askConfirmation('Are you sure to generate and upload settings.php file?')) {
2015-07-15 19:57:41 +02:00
$basepath = dirname(__FILE__). '/drupal7';
2015-07-15 19:38:50 +02:00
//Import secrets
$secrets = env('settings');
2015-07-15 19:38:50 +02:00
//Prepare replacement variables
$iterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator($secrets)
2015-07-15 19:57:41 +02: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
//Create settings from template
2015-07-15 19:57:41 +02:00
$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-07-15 19:38:50 +02:00
2015-07-15 19:57:41 +02:00
uploadEnv($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
}
});
//Upload Drupal 7 files folder
task('drupal:upload_files', function () {
if (askConfirmation('Are you sure?')) {
2015-07-15 19:57:41 +02:00
uploadEnv('sites/{{drupal_site}}/files', '{{deploy_path}}/shared/sites/{{drupal_site}}/files');
2015-07-15 19:38:50 +02:00
}
});
2015-07-15 19:57:41 +02:00
function uploadEnv($local, $remote)
{
$local = env()->parse($local);
$remote = env()->parse($remote);
upload($local, $remote);
2015-07-15 19:38:50 +02:00
}