public function kill() { if ($this->exists()) { writeln("<comment>Kill elasticsearch container {$this->container}</comment>"); $command = Env::evalDocker() . "docker rm -f {$this->container}"; runLocally($command); } }
function postToSlack($message) { $slackHookUrl = env('SLACK_HOOK_URL'); if (!empty($slackHookUrl)) { runLocally('curl -s -S -X POST --data-urlencode payload="{\\"channel\\": \\"#' . env('SLACK_CHANNEL_NAME') . '\\", \\"username\\": \\"Release Bot\\", \\"text\\": \\"' . $message . '\\"}"' . env('SLACK_HOOK_URL')); } else { write('Configure the SLACK_HOOK_URL to post to slack'); } }
public function stop() { try { writeln("Stop docker-machine {$this->name}"); $output = runLocally("docker-machine stop {$this->name}"); writeln("<comment>Docker-machine {$this->name} stopped</comment>"); } catch (Exception $ex) { } }
public function exists() { $command = Env::evalDocker() . "docker inspect {$this->container}"; try { $output = runLocally($command); return true; } catch (\Exception $ex) { return false; } }
<?php if (!class_exists('EkAndreas\\DockerBedrock\\Helpers')) { include_once 'src/DockerBedrock/Helpers.php'; } use EkAndreas\DockerBedrock\Helpers; $dir = Helpers::getProjectDir(); require_once $dir . '/vendor/autoload.php'; task('docker:start', function () { Helpers::start(); }, 999); task('docker:up', function () { Helpers::start(); }, 999); task('docker:stop', function () { Helpers::stop(); }); task('docker:halt', function () { Helpers::stop(); }); task('docker:kill', function () { Helpers::kill(); }); task('wpinit', function () { $server = env('server'); runLocally("wp core install --url='{$server['name']}' --title='{$server['name']}' --admin_user='******' --admin_password='******' --admin_email='admin@{$server['name']}'"); });
$sourceServerKey = input()->getOption('source-server'); } $sourceServer = $serverList[$sourceServerKey]; $destServer = $serverList[env('server.name')]; runLocally("ssh {$sourceServer['user']}@{$sourceServer['host']} 'mysqldump -h {$sourceServer['app']['mysql']['host']} -u {$sourceServer['app']['mysql']['username']} -p{$sourceServer['app']['mysql']['password']} {$sourceServer['app']['mysql']['dbname']} --skip-lock-tables --add-drop-table' | mysql -h {$destServer['app']['mysql']['host']} -u{$destServer['app']['mysql']['username']} -p{$destServer['app']['mysql']['password']} {$destServer['app']['mysql']['dbname']}", 0); })->onlyOn('dev'); task("sync:dirs", function () { $serverList = $serverInfo = Yaml::parse(file_get_contents(__DIR__ . '/stage/servers.yml')); $sourceServerKey = null; if (input()->hasOption('source-server')) { $sourceServerKey = input()->getOption('source-server'); } $destPath = null; if (input()->hasOption('dest-path')) { $destPath = input()->getOption('dest-path'); } $sourceServer = $serverList[$sourceServerKey]; $destServer = $serverList[env('server.name')]; foreach (get('sync_dirs') as $dir) { $excludeString = ''; foreach (get('sync_excludes') as $exclude) { $excludeString .= " --exclude={$exclude} "; } writeln("rsync -avz --delete {$sourceServer['user']}@{$sourceServer['host']}:{$sourceServer['webroot']}/{$dir}/ {$destPath}/{$dir} {$excludeString}"); runLocally("rsync -avz --delete {$sourceServer['user']}@{$sourceServer['host']}:{$sourceServer['webroot']}/{$dir}/ {$destPath}/{$dir} {$excludeString}", 0); } }); task('sync', ['sync:dirs', 'sync:db']); task('deploy', ['deploy:prepare', 'deploy:release', 'deploy:update_code', 'deploy:shared', 'deploy:configure', 'deploy:vendors', 'deploy:symlink', 'deploy:clean', 'cleanup'])->desc('Deploy your project'); after('deploy', 'success'); serverList(__DIR__ . '/stage/servers.yml');
function testrunner_restart_mysql() { $ip = env('testrunner_docker_ip'); testrunner_kill_container('testrunner_mysql'); runLocally("{{docker}} && \\\n docker run \\\n -d --env 'MYSQL_ROOT_PASSWORD=root' --env 'MYSQL_DATABASE=wp' \\\n --name='testrunner_mysql' -p {$ip}:3306:3306 \\\n mysql:5.6", 999); testrunner_wait_port('Waiting for mysql to start', '3306'); }
public static function doLocal($command, $timeout = 999) { writeln('==================================================='); writeln('Running command:'); writeln($command); writeln('==================================================='); return runLocally(Env::evalDocker() . $command, $timeout); }
* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Deployer; /** * Get local username */ set('local_user', function () { return trim(run("whoami")); }); desc('Notifying Rollbar of deployment'); task('deploy:rollbar', function () { global $php_errormsg; $defaultConfig = ['access_token' => null, 'environment' => get('stages')[0], 'revision' => trim(runLocally('git log -n 1 --format="%h"')), 'local_username' => trim(runLocally('git config user.name')), 'rollbar_username' => null, 'comment' => "Deployment to `{{host}}` on *{{stage}}* was successful\n({{release_path}})"]; $config = array_merge($defaultConfig, (array) get('rollbar', [])); if (!is_array($config) || !isset($config['access_token'])) { throw new \RuntimeException("Please configure new rollbar: set('rollbar', ['access_token' => 'c09a3...', 'revision' => 'v4.3', 'rollbar_username' => 'John Doe', 'comment' => 'Brand new version']);"); } $server = \Deployer\Task\Context::get()->getServer(); if ($server instanceof \Deployer\Server\Local) { $user = get('local_user'); } else { $user = $server->getConfiguration()->getUser() ?: null; } $commentPlaceHolders = ['{{release_path}}' => get('release_path'), '{{host}}' => get('server.host'), '{{stage}}' => get('stages')[0], '{{user}}' => $user, '{{branch}}' => get('branch')]; $config['comment'] = strtr($config['comment'], $commentPlaceHolders); $urlParams = ['access_token' => $config['access_token'], 'environment' => $config['environment'], 'revision' => $config['revision'], 'local_username' => $config['local_username'], 'rollbar_username' => $config['rollbar_username'], 'comment' => $config['comment']]; $options = array('http' => array('method' => 'POST', 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'content' => http_build_query($urlParams))); $context = stream_context_create($options);
/** * recipe for http://deployer.org/ */ /** * Update project code */ task('package:create', function () { $basePath = env('deploy_path'); $packageSourcePath = __DIR__ . '/../../'; $packageName = 'deploy_package_' . date('Ymd') . '_' . time() . '.tar.gz'; $packageLocation = $packageSourcePath . '../deployer-dashboard/' . $packageName; $excludes = " --exclude=build/var --exclude=build/pub"; foreach (get('not_packaged') as $exclude) { $excludes .= " --exclude={$exclude} "; } runLocally("tar --exclude-vcs --exclude=vendor {$excludes} -czf {$packageLocation} -C {$packageSourcePath} ./"); //runLocally("tar --exclude-vcs {$excludes} -czf {$packageLocation} -C {$packageSourcePath} ./"); env()->set('packageLocation', $packageLocation); env()->set('packageName', $packageName); })->desc('create package'); /** * Update project code */ task('package:upload', function () { $basePath = env('deploy_path'); $release = date('Ymd') . substr((string) time(), -5); $releasePath = "{$basePath}/releases/{$release}"; $releasePath = env('release_path'); $packageLocation = env()->get('packageLocation'); $packageName = env()->get('packageName'); upload($packageLocation, $packageName);
<?php /* (c) Tim Robertson <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Deployer; desc('Notifying Bugsnag of deployment'); task('deploy:bugsnag', function () { global $php_errormsg; $defaultConfig = ['api_key' => null, 'release_stage' => get('stages')[0], 'repository' => get('repository'), 'provider' => null, 'branch' => get('branch'), 'revision' => trim(runLocally('git log -n 1 --format="%h"')), 'app_version' => null]; $config = array_merge($defaultConfig, (array) get('bugsnag')); if (!is_array($config) || !isset($config['api_key'])) { throw new \RuntimeException("Please configure new bugsnag: set('bugsnag', ['api_key' => 'c09a3...', 'release_stage' => 'production']);"); } $postdata = ['apiKey' => $config['api_key'], 'releaseStage' => $config['release_stage'], 'repository' => $config['repository'], 'provider' => $config['provider'], 'branch' => $config['branch'], 'revision' => $config['revision'], 'appVersion' => $config['app_version']]; $options = array('http' => array('method' => 'POST', 'header' => "Content-type: application/json\r\n", 'content' => json_encode($postdata))); $context = stream_context_create($options); $result = @file_get_contents('https://notify.bugsnag.com/deploy', false, $context); if (!$result) { throw new \RuntimeException($php_errormsg); } });
<?php task('pull:dump', function () { writeln('Creating a new database dump (approx. 60s)'); run('mysqldump nordiciron > /tmp/nordiciron.sql'); }); task('pull:fetch_dump', function () { writeln('Getting database dump (approx. 60s)'); runLocally('scp root@andreasek.se:/tmp/nordiciron.sql nordiciron.sql', 999); }); task('pull:resolve_dump', function () { writeln('Restore database inside vagrant (approx. 60s)'); runLocally('vagrant ssh -c "mysql -u root -proot nordiciron < /home/vagrant/www/nordiciron/nordiciron.sql"', 999); }); task('pull:set_vagrant_wp', function () { writeln('Restore wp after pull (approx. 60s)'); runLocally('vagrant ssh -c "cd /home/vagrant/www/nordiciron/web && wp search-replace "nordiciron.com" "nordiciron.dev" && wp rewrite flush"', 999); runLocally('vagrant ssh -c "cd /home/vagrant/www/nordiciron/web && wp search-replace "www.nordiciron.com" "nordiciron.dev" && wp rewrite flush"', 999); }); task('pull:uploads', function () { writeln('Getting uploads, long duration first time! (approx. 60-999s)'); runLocally('rsync -re ssh root@andreasek.se:/mnt/persist/www/nordiciron.com/shared/web/app/uploads web/app', 999); }); task('pull:cleanup', function () { writeln('Cleaning up locally...'); runLocally('rm nordiciron.sql'); }); task('pull', ['pull:dump', 'pull:fetch_dump', 'pull:resolve_dump', 'pull:set_vagrant_wp', 'pull:uploads', 'pull:cleanup']);
env('remote.name', 'aekab'); env('remote.path', '/home/forge/www.aekab.se'); env('remote.ssh', 'forge@178.62.249.226'); env('remote.database', 'aekab'); env('remote.domain', 'aekab.se'); env('local.domain', 'aekab.dev'); env('local.is_elastic', false); server('development', 'default', 22)->env('container', 'bedrock')->env('deploy_path', '/var/www/aekab'); server('production', '178.62.249.226', 22)->env('deploy_path', '/home/forge/www.aekab.se')->user('forge')->env('branch', 'master')->stage('production')->identityFile(); set('repository', 'git@github.com:ekandreas/aekab.git'); // Symlink the .env file for Bedrock set('env', 'prod'); set('keep_releases', 10); set('shared_dirs', ['web/app/uploads', 'web/app/themes/aekab/.cache']); set('shared_files', ['.env', 'web/.htaccess', 'web/robots.txt']); set('env_vars', '/usr/bin/env'); //set('writable_dirs', ['web/app/uploads']); task('deploy:restart', function () { writeln('Purge cache...'); run('rm -Rf web/app/themes/aekab/.cache && mkdir -p shared/web/app/themes/aekab/.cache'); })->desc('Restarting apache2 and varnish'); task('deploy', ['deploy:prepare', 'deploy:release', 'deploy:update_code', 'deploy:vendors', 'deploy:shared', 'deploy:writable', 'deploy:symlink', 'cleanup', 'deploy:restart', 'success'])->desc('Deploy your Bedrock project, eg dep deploy production'); task('pull:files', function () { writeln('Getting uploads, long duration first time! (approx. 60s)'); runLocally('rsync --exclude .cache -re ssh {{remote.ssh}}:{{remote.path}}/web/app/uploads web/app', 999); }); task('pull:deactivate', function () { writeln('Deactivate SEO'); runLocally('cd web && wp plugin deactivate wordpress-seo', 999); }); task('pull', ['pull:create_database_dump', 'pull:get_database_dump', 'pull:restore_database', 'pull:search_and_replace_database', 'pull:files', 'pull:elastic', 'pull:deactivate', 'pull:cleanup']);
writeln('working with env files'); $tmp_dir = dirname(__DIR__) . '/../.tmp/'; $local_env = '.local.env'; $remote_env = '.remote.env'; runLocally('mkdir -p ' . $tmp_dir); runLocally('cp .env ' . $tmp_dir . $local_env); download($tmp_dir . $remote_env, $config['shared_dir'] . '/.env'); $dotenvremote = new Dotenv\Dotenv($tmp_dir, $remote_env); if (file_exists($tmp_dir . $remote_env)) { $dotenvremote->overload(); $dotenvremote->required(['WP_HOME']); set('remote_url', getenv('WP_HOME')); } $dotenvlocal = new Dotenv\Dotenv($tmp_dir, $local_env); if (file_exists($tmp_dir . $local_env)) { $dotenvlocal->overload(); $dotenvlocal->required(['WP_HOME']); set('local_url', getenv('WP_HOME')); } runLocally('rm -rf .tmp'); } else { writeln('working with config'); set('local_url', $config['local_wp_url']); set('remote_url', $config['remote_wp_url']); } })->desc('Download backup database'); /* --------------------- */ /* DB TASKS */ /* --------------------- */ task('db:push', ['db:local:backup', 'db:cmd:push']); task('db:pull', ['db:remote:backup', 'db:cmd:pull']);
* It is used to create the Git tags before deployment */ env('code_path', '/var/www/YOUR_OCTOBERCMS_CODE_PATH_HERE'); /** * Instruct OctoberCMS to create a mirror folder in the web/ dir */ task('deploy:symlink:web', function () { $deployPath = env('deploy_path'); cd($deployPath); run('cd {{release_path}} && php artisan october:mirror web/'); }); /** * After OctoberCMS finishes creating the mirror folder copy the .htaccess as well */ task('deploy:cp-htaccess', function () { run('cp {{release_path}}/.htaccess {{release_path}}/web'); }); /** * Instruct deployer to create a Git tag before deployment */ task('deploy:tag-deployment', function () { $codePath = env('code_path'); $time = date('d/m/YTH-i-s'); cd($codePath); runLocally("git tag -a -m 'Deployment of version {$time}' '{$time}' && git push origin --tags"); }); /** * Main deployment task which creates the deployment scenario */ task('deploy-test', ['deploy:prepare', 'deploy:release', 'deploy:update_code', 'deploy:shared', 'deploy:vendors', 'deploy:writable', 'deploy:symlink', 'deploy:symlink:web', 'deploy:cp-htaccess', 'cleanup'])->desc('Deploy your project'); after('deploy-test', 'success');
<?php task('pull:dump', function () { writeln('Creating a new database dump (approx. 10s)'); run('cd current/web && wp db export --allow-root'); }); task('pull:fetch_dump', function () { writeln('Getting database dump (approx. 10s)'); runLocally('scp root@www.andreasek.se:/mnt/persist/www/andreasek.se/current/web/andreasek.sql andreasek.sql', 999); }); task('pull:resolve_dump', function () { writeln('Restore database inside vagrant (approx. 10s)'); runLocally('cd .. && vagrant ssh -c "mysql -u root -proot aek < /var/www/aek.dev/andreasek.sql" && cd aek.dev', 999); }); task('pull:set_vagrant_wp', function () { writeln('Restore wp after pull (approx. 60s)'); runLocally('cd .. && vagrant ssh -c "cd /var/www/aek.dev/web && wp search-replace www.andreasek.se aek.dev" && cd aek.dev', 999); }); task('pull:uploads', function () { writeln('Getting uploads, long duration first time! (approx. 60-999s)'); runLocally('rsync -re ssh root@www.andreasek.se:/mnt/persist/www/andreasek.se/shared/web/app/uploads web/app', 999); }); task('pull', ['pull:dump', 'pull:fetch_dump', 'pull:resolve_dump', 'pull:set_vagrant_wp', 'pull:uploads']);
writeln("<comment>No way to warmup rsync.</comment>"); } })->desc('Warmup remote Rsync target'); task('rsync', function () { $config = get('rsync'); $src = env('rsync_src'); while (is_callable($src)) { $src = $src(); } if (!trim($src)) { // if $src is not set here rsync is going to do a directory listing // exiting with code 0, since only doing a directory listing clearly // is not what we want to achieve we need to throw an exception throw new \RuntimeException('You need to specify a source path.'); } $dst = env('rsync_dest'); while (is_callable($dst)) { $dst = $dst(); } if (!trim($dst)) { // if $dst is not set here we are going to sync to root // and even worse - depending on rsync flags and permission - // might end up deleting everything we have write permission to throw new \RuntimeException('You need to specify a destination path.'); } $server = \Deployer\Task\Context::get()->getServer()->getConfiguration(); $host = $server->getHost(); $port = $server->getPort() ? ' -p' . $server->getPort() : ''; $user = !$server->getUser() ? '' : $server->getUser() . '@'; runLocally("rsync -{$config['flags']} -e 'ssh{$port}' {{rsync_options}}{{rsync_excludes}}{{rsync_includes}}{{rsync_filter}} '{$src}/' '{$user}{$host}:{$dst}/'", $config['timeout']); })->desc('Rsync local->remote');
} }); desc('Installing vendors locally'); task('local:vendors', function () { runLocally("cd {{local_release_path}} && {{env_vars}} {{local_bin/composer}} {{composer_options}}"); }); desc('Creating symlink to local release'); task('local:symlink', function () { runLocally("cd {{local_deploy_path}} && ln -sfn {{local_release_path}} current"); // Atomic override symlink. runLocally("cd {{local_deploy_path}} && rm release"); // Remove release link. }); desc('Show current local release.'); task('local:current', function () { writeln('Current local release: ' . basename(get('local_current'))); }); desc('Cleaning up old local releases'); task('local:cleanup', function () { $releases = get('local_releases_list'); $keep = get('keep_releases'); while ($keep > 0) { array_shift($releases); --$keep; } foreach ($releases as $release) { runLocally("rm -rf {{local_deploy_path}}/releases/{$release}"); } runLocally("cd {{local_deploy_path}} && if [ -e release ]; then rm release; fi"); runLocally("cd {{local_deploy_path}} && if [ -h release ]; then rm release; fi"); });
<?php // All Deployer recipes are based on `recipe/common.php`. require 'recipe/composer.php'; $config = parse_ini_file(__DIR__ . '/deploy.ini'); env('timezone', 'Europe/Vienna'); // Specify the repository from which to download your project's code. // The server needs to have git installed for this to work. // If you're not using a forward agent, then the server has to be able to clone // your project from this repository. set('repository', $config['repo']); set('keep_releases', 5); server('prod', $config['host'], $config['port'])->user($config['user'])->password($config['password'])->stage('production')->env('deploy_path', $config['path'])->env('env_vars', $config['env_vars']); task('deploy:push', function () { runLocally("git push"); })->desc('Installing vendors'); task('deploy:vendors', function () { $envVars = env('env_vars') ? 'export ' . env('env_vars') . ' &&' : ''; run("cd {{release_path}} && {$envVars} sculpin update --env prod"); })->desc('Installing vendors'); task('deploy:generate', function () { $envVars = env('env_vars') ? 'export ' . env('env_vars') . ' &&' : ''; run("cd {{release_path}} && {$envVars} sculpin generate --env prod"); })->desc('Generating static HTML'); task('deploy', ['deploy:push', 'deploy:prepare', 'deploy:release', 'deploy:update_code', 'deploy:vendors', 'deploy:shared', 'deploy:generate', 'deploy:symlink', 'cleanup'])->desc('Deploy your project');
} serverList(__DIR__ . '/deployer/stage/servers.yml'); set('repository', '{{repository}}'); set('default_stage', 'production'); set('keep_releases', 2); set('writable_use_sudo', false); // Using sudo in writable commands? task('deploy:configure_composer', function () { $stage = env('app.stage'); if ($stage == 'dev') { env('composer_options', 'install --verbose --no-progress --no-interaction'); } })->desc('Configure composer'); // build assets task('deploy:build_assets', function () { runLocally('gulp build --production'); $theme = env('app.theme'); upload(__DIR__ . '/themes/' . $theme . '/assets/dist/css', '{{release_path}}/themes/' . $theme . '/assets/dist/css'); upload(__DIR__ . '/themes/' . $theme . '/assets/dist/js', '{{release_path}}/themes/' . $theme . '/assets/dist/js'); upload(__DIR__ . '/themes/' . $theme . '/assets/dist/fonts', '{{release_path}}/themes/' . $theme . '/assets/dist/fonts'); upload(__DIR__ . '/themes/' . $theme . '/assets/dist/img', '{{release_path}}/themes/' . $theme . '/assets/dist/img'); })->desc('Build assets'); // update symlink to images dir task('deploy:images_symlink', function () { run('php {{release_path}}/yii mdpages/pages/symlink'); })->desc('Update images symlink'); // flush the cache task('flush_cache', function () { run('php {{release_path}}/yii cache/flush-all'); })->desc('Flush the cache'); // flush the templates
<?php /* WP UPLOADS TASK /* --------------------- */ task('uploads:sync', function () { $server = \Deployer\Task\Context::get()->getServer()->getConfiguration(); $upload_dir = 'web/app/uploads'; $user = $server->getUser(); $host = $server->getHost(); $port = $server->getPort() ? ' -p ' . $server->getPort() : ''; $identityFile = $server->getPrivateKey() ? ' -i ' . $server->getPrivateKey() : ''; writeln('<comment>> Receive remote uploads ... </comment>'); runLocally("rsync -avzO -e 'ssh{$port}{$identityFile}' {$user}@{$host}:{{deploy_path}}/shared/{$upload_dir}/ {$upload_dir}"); writeln('<comment>> Send local uploads ... </comment>'); runLocally("rsync -avzO -e 'ssh{$port}{$identityFile}' {$upload_dir}/ {$user}@{$host}:{{deploy_path}}/shared/{$upload_dir}"); })->desc('Sync uploads');
<?php /* (c) Samuel Gordalina <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Deployer; desc('Notifying New Relic of deployment'); task('deploy:newrelic', function () { global $php_errormsg; $config = get('newrelic', array()); if (!is_array($config) || !isset($config['license']) || !isset($config['app_name']) && !isset($config['application_id'])) { throw new \RuntimeException("<comment>Please configure new relic:</comment> <info>set('newrelic', array('license' => 'xad3...', 'application_id' => '12873'));</info>"); } $git = array('user' => trim(runLocally('git config user.name')), 'revision' => trim(runLocally('git log -n 1 --format="%h"')), 'description' => trim(runLocally('git log -n 1 --format="%an: %s" | tr \'"\' "\'"'))); $postdata = array_merge($git, $config); unset($postdata['license']); $options = array('http' => array('method' => 'POST', 'header' => "Content-type: application/x-www-form-urlencoded\r\n" . "X-License-Key: {$config['license']}\r\n", 'content' => http_build_query(array('deployment' => $postdata)))); $context = stream_context_create($options); $result = @file_get_contents('https://api.newrelic.com/deployments.xml', false, $context); if ($result === false) { throw new \RuntimeException($php_errormsg); } });
// Load the Dotenv class if it is not loaded yet if (class_exists('Dotenv') === false) { require __DIR__ . '/../../../../vendor/vlucas/phpdotenv/src/Dotenv.php'; } task('deploy:db_backup', function () { if (class_exists('Dotenv') === false) { throw new \RuntimeException("Please install php package 'vlucas/phpdotenv' to use this recipe"); } $sharedDir = sprintf('%s/shared', env('deploy_path')); // Download the .env file so we can load the env variables download('/tmp/.env', sprintf('%s/.env', $sharedDir)); // Load the downloaded .env file Dotenv::load('/tmp'); // Clean up the temporary file runLocally('rm -f /tmp/.env'); // Load the config that's set in the deploy.php file try { $config = get('db-backup', []); } catch (\RuntimeException $e) { $config = []; } $defaultConfig = array('backup_dir' => sprintf('%s/backups', env('deploy_path'))); $config = array_merge($defaultConfig, $config); // Create the backup dir if it doesn't exist run(sprintf("if [ ! -d %s ]; then mkdir -p %s; fi", $config['backup_dir'], $config['backup_dir'])); $release = basename(env('release_path')); run(sprintf('mysqldump -h%s -u%s -p%s %s > %s/%s.sql', getenv('DB_HOST'), getenv('DB_USERNAME'), getenv('DB_PASSWORD'), getenv('DB_DATABASE'), $config['backup_dir'], $release)); // Cleanup old database backups $releases = run(sprintf('ls %s', $config['backup_dir']))->toArray(); rsort($releases);
preg_match('/Made (\\d+) replacements/', $output, $matches); $replaced3 = (int) $matches[1]; writeln("[33m{$replaced3}[37m replacements..."); $totalReplaced = $replaced1 + $replaced2 + $replaced3; writeln("Total of [33m{$totalReplaced}[37m replacements"); }); task('pull:files', function () { writeln('Getting uploads, long duration first time! (approx. 60s)'); $user = run('echo $USER'); runLocally("rsync --exclude .cache -re ssh {$user}@{{server.host}}:{{deploy_path}}/shared/web/app/uploads web/app", 999); }); task('pull:elastic', function () { if (has('elastic') && get('elastic')) { writeln('Setup elasticsearch and elasticpress'); runLocally('wp elasticpress index --setup', 999); } }); task('pull:cleanup', function () { writeln('Remove all tranisents'); runLocally('wp transient delete-all'); writeln('Permalinks rewrite/flush'); runLocally('wp rewrite flush'); writeln('Activate query monitor'); runLocally('wp plugin activate query-monitor'); if (file_exists('web/app/uploads/.cache/')) { runLocally('chmod -R 777 web/app/uploads/.cache'); writeln('Empty Bladerunner cache'); array_map('unlink', glob("web/app/uploads/.cache/*.*")); } }); task('pull', ['pull:check_parameters', 'pull:create_database_dump', 'pull:get_database_dump', 'pull:restore_database', 'pull:search_and_replace_database', 'pull:files', 'pull:elastic', 'pull:cleanup', 'success']);
/** * Check if command exist in bash. * * @param string $command * @return bool */ function commandExistLocally($command) { return runLocally("if hash {$command} 2>/dev/null; then echo 'true'; fi")->toBool(); }
if (file_exists('releases.json')) { $manifest = json_decode(file_get_contents('releases.json'), TRUE); foreach ($manifest as $key => $release) { if ($release['version'] == get('version')) { unset($manifest[$key]); } } } $sha1 = sha1_file(get('releaseFilename')); $file = basename(get('releaseFilename')); $baseUrl = 'https://github.com/' . get('username') . '/' . get('repository') . '/releases/download/'; $manifest[] = array('name' => 'soup.phar', 'sha1' => $sha1, 'url' => $baseUrl . get('version') . '/' . $file, 'version' => get('version')); file_put_contents('releases.json', json_encode(array_values($manifest), JSON_PRETTY_PRINT)); runLocally('git add releases.json'); runLocally('git commit -m "Added Version: ' . get('version') . '"'); runLocally('git push origin master'); }); task('release:createGithubRelease', function () { $ch = getGithubCurl(); $release = array('tag_name' => get('version'), 'name' => 'Release: ' . get('version')); $uri = 'https://api.github.com/repos/' . get('username') . '/' . get('repository') . '/releases'; curl_setopt($ch, CURLOPT_URL, $uri); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($release)); curl_setopt($ch, CURLOPT_POST, 1); $release = json_decode(curl_exec($ch)); $releaseId = $release->id; set('releaseId', $releaseId); }); task('release:destroyGithubRelease', function () { $ch = getGithubCurl(); $uri = 'https://api.github.com/repos/' . get('username') . '/' . get('repository') . '/releases/tags/' . get('version');
<?php /** * Init WP with noncens data */ task('init:wp', function () { writeln('Initialize WP to get WP-CLI working'); runLocally('cd web && wp core install --url=http://something.dev --title=wp --admin_user=admin --admin_password=admin --admin_email=arne@nada.se'); }); /** * Gets the latest from prod */ task('init:pull', function () { writeln('Pull remote version of WP'); runLocally('dep pull production', 999); }); task('init', ['init:wp', 'init:pull']);
// writeln('Update and commit version in composer.json'); runLocally('git add composer.json'); runLocally('git commit -m "' . get('version') . '"'); }); task('release:tagRelease', function () { // writeln('tag current state with provided version number'); runLocally('git tag "' . get('version') . '"'); }); task('release:pushTags', function () { // writeln('push tags to github'); runLocally('git push origin master'); runLocally('git push origin --tags'); }); task('release:removeCurrentTagFromRemote', function () { runLocally('git tag -d "' . get('version') . '"'); runLocally('git push origin :refs/tags/' . get('version')); }); task('release:createGithubRelease', function () { $ch = getGithubCurl(); $release = array('tag_name' => get('version'), 'name' => 'Release: ' . get('version')); $uri = 'https://api.github.com/repos/' . get('repository') . '/releases'; curl_setopt($ch, CURLOPT_URL, $uri); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($release)); curl_setopt($ch, CURLOPT_POST, 1); $release = json_decode(curl_exec($ch)); $releaseId = $release->id; set('releaseId', $releaseId); }); task('release:destroyGithubRelease', function () { $ch = getGithubCurl(); $uri = 'https://api.github.com/repos/' . get('repository') . '/releases/tags/' . get('version');
<?php date_default_timezone_set('Europe/Stockholm'); /** * Change the IP to your env */ env('docker_ip', '192.168.99.100'); task('tests:docker', function () { writeln('Starting docker container'); runLocally('docker-compose up -d'); sleep(4); })->desc('Starting docker'); task('tests:wp', function () { writeln('Checking out WordPress from SVN'); runLocally('svn co https://develop.svn.wordpress.org/trunk/ --non-interactive --trust-server-cert wordpress-develop', 999); })->desc('Start testing wp'); task('tests:prepp', function () { writeln('Config files'); runLocally("sed 's/docker_ip/{{docker_ip}}/g' wp-tests-config.php > wordpress-develop/wp-tests-config.php"); })->desc('Start testing wp'); task('tests:run', function () { writeln('Running phpunit'); $output = runLocally('cd wordpress-develop && ../vendor/bin/phpunit', 999); writeln($output); })->desc('Start testing wp'); task('tests:cleanup', function () { writeln('Killing containers'); runLocally('docker-compose stop'); runLocally('docker-compose rm -f'); })->desc('Cleanup'); task('tests', ['tests:docker', 'tests:wp', 'tests:prepp', 'tests:run', 'tests:cleanup'])->desc('Initialize tests');
protected function loadRecipe() { require __DIR__ . '/../../recipe/common.php'; // Override update code task to use local copy. task('deploy:update_code', function () { runLocally('cp -R ' . __DIR__ . '/../fixture/app/. {{release_path}}'); }); }