protected function loadRecipe() { require __DIR__ . '/../../recipe/common.php'; task('deploy:timeout_test', function () { $this->result = run('sleep 11 && echo $SSH_CLIENT'); }); task('deploy:ssh_test', function () { $this->result = run('echo $SSH_CLIENT'); }); task('deploy:agent_test', function () { $this->result = run('ssh -T deployer@localhost \'echo $SSH_CLIENT\''); }); }
<?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); } });
<?php namespace Deployer; require_once __DIR__ . '/common.php'; /** * Silverstripe configuration */ // Silverstripe shared dirs set('shared_dirs', ['assets']); // Silverstripe writable dirs set('writable_dirs', ['assets']); /** * Helper tasks */ task('silverstripe:build', function () { return run('{{bin/php}} {{release_path}}/framework/cli-script.php /dev/build'); })->desc('Run /dev/build'); task('silverstripe:buildflush', function () { return run('{{bin/php}} {{release_path}}/framework/cli-script.php /dev/build flush=all'); })->desc('Run /dev/build?flush=all'); /** * Main task */ task('deploy', ['deploy:prepare', 'deploy:lock', 'deploy:release', 'deploy:update_code', 'deploy:vendors', 'deploy:shared', 'deploy:writable', 'silverstripe:buildflush', 'deploy:symlink', 'deploy:unlock', 'cleanup'])->desc('Deploy your project'); after('deploy', 'success');
require 'recipe/drupal8.php'; server('prod', '146.185.128.63', 9999)->user('deploy')->identityFile()->stage('production')->env('deploy_path', '/usr/share/nginx/html/kristiankaadk'); set('repository', 'git@github.com:kaa4ever/kristiankaadk.git'); task('deploy:permissions', function () { run('if [ -d {{deploy_path}}/shared ]; then sudo chown -R deploy:deploy {{deploy_path}}/shared; fi'); run('if [ -d {{deploy_path}}/releases ]; then sudo chown -R deploy:deploy {{deploy_path}}/releases; fi'); }); task('docker:reboot', function () { cd('{{release_path}}'); run('docker stop kristiankaa.site || true'); run('docker rm kristiankaa.site || true'); run('docker-compose -f docker-compose.prod.yml up -d'); }); task('drush:make', function () { writeln("<info>Drush: Building site</info>"); run('docker exec kristiankaa.site bash -c "cd /var/www/html && drush make site.make -y"'); }); task('drush:updb', function () { writeln("<info>Drush: Updating database</info>"); run('docker exec kristiankaa.site drush updb -y --root=/var/www/html'); }); task('drush:cache', function () { writeln("<info>Drush: Rebuilding cache</info>"); run('docker exec kristiankaa.site drush cr --root=/var/www/html'); }); after('deploy:prepare', 'deploy:permissions'); after('deploy:update_code', 'docker:reboot'); after('deploy:update_code', 'drush:make'); after('deploy', 'drush:updb'); after('deploy', 'drush:cache');
<?php use Deployer\Database\Database; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; option('from', null, InputOption::VALUE_OPTIONAL, 'The source server for copying the instance'); task('copy:database', function () { if (!input()->getOption('from')) { throw new Exception('The source server is required'); } $from = input()->getArgument('stage'); if ($from == 'production') { throw new \Exception('That is strictly prohibited to restore the dump to the production server'); } /** @var string $dump */ $dump = Database::loadUsingStage($from)->dump(); Database::loadUsingStage(input()->getOption('from'))->restore($dump); run("rm -f " . $dump); }); task('copy', ['copy:database']);
} } } catch (\RuntimeException $e) { } return $opts; }); desc('Migrating database by phinx'); task('phinx:migrate', function () { $ALLOWED_OPTIONS = ['configuration', 'date', 'environment', 'target', 'parser']; $conf = get('phinx_get_allowed_config')($ALLOWED_OPTIONS); cd('{{release_path}}'); $phinxCmd = get('phinx_get_cmd')('migrate', $conf); run($phinxCmd); cd('{{deploy_path}}'); }); task('phinx:rollback', function () { $ALLOWED_OPTIONS = ['configuration', 'date', 'environment', 'target', 'parser']; $conf = get('phinx_get_allowed_config')($ALLOWED_OPTIONS); cd('{{release_path}}'); $phinxCmd = get('phinx_get_cmd')('rollback', $conf); run($phinxCmd); cd('{{deploy_path}}'); }); task('phinx:seed', function () { $ALLOWED_OPTIONS = ['configuration', 'environment', 'parser', 'seed']; $conf = get('phinx_get_allowed_config')($ALLOWED_OPTIONS); cd('{{release_path}}'); $phinxCmd = get('phinx_get_cmd')('seed:run', $conf); run($phinxCmd); cd('{{deploy_path}}'); });
<?php /* (c) Anton Medvedev <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once __DIR__ . '/common.php'; // Flow-Framework application-context env('flow_context', 'Production'); // Flow-Framework cli-command env('flow_command', 'flow'); // Flow-Framework shared directories set('shared_dirs', ['Data/Persistent', 'Data/Logs', 'Configuration/{{flow_context}}']); /** * Apply database migrations */ task('deploy:run_migrations', function () { run('FLOW_CONTEXT={{flow_context}} {{bin/php}} {{release_path}}/{{flow_command}} doctrine:migrate'); })->desc('Apply database migrations'); /** * Publish resources */ task('deploy:publish_resources', function () { run('FLOW_CONTEXT={{flow_context}} {{bin/php}} {{release_path}}/{{flow_command}} resource:publish'); })->desc('Publish resources'); /** * Main task */ task('deploy', ['deploy:prepare', 'deploy:release', 'deploy:update_code', 'deploy:vendors', 'deploy:shared', 'deploy:run_migrations', 'deploy:publish_resources', 'deploy:symlink', 'cleanup'])->desc('Deploy your project'); after('deploy', 'success');
run("echo '<?php' > {{release_path}}/db.php"); run("echo 'return [' >> {{release_path}}/db.php"); run("echo \" 'class' => 'yii\\db\\Connection',\" >> {{release_path}}/db.php"); run("echo \" 'dsn' => 'mysql:host=localhost;dbname=test_dep_aaaaa',\" >> {{release_path}}/db.php"); run("echo \" 'username' => 'test',\" >> {{release_path}}/db.php"); run("echo \" 'password' => '',\" >> {{release_path}}/db.php"); run("echo \" 'charset' => 'utf8',\" >> {{release_path}}/db.php"); run("echo \"];\" >> {{release_path}}/db.php"); })->desc('Configure database connection'); /** * Run migrations */ task('deploy:run_migrations', function () { run('{{bin/php}} {{release_path}}/yii migrate up --interactive=0'); })->desc('Run migrations'); /** * Main task */ task('deploy', ['deploy:prepare', 'deploy:release', 'deploy:update_code', 'deploy:shared', 'deploy:vendors', 'deploy:configure_db', 'deploy:run_migrations', 'deploy:symlink', 'deploy:writable', 'cleanup'])->desc('Deploy your project'); after('deploy', 'success'); /** * Restart php-fpm on success deploy. */ //task('php-fpm:restart', function () { // // Attention: The user must have rights for restart service // // Attention: the command "sudo /bin/systemctl restart php-fpm.service" used only on CentOS system // // /etc/sudoers: username ALL=NOPASSWD:/bin/systemctl restart php-fpm.service // run('sudo /bin/systemctl restart php-fpm.service'); //})->desc('Restart PHP-FPM service'); // //after('success', 'php-fpm:restart');
desc('Execute artisan view:clear'); task('artisan:view:clear', function () { run('{{bin/php}} {{release_path}}/artisan view:clear'); }); desc('Execute artisan optimize'); task('artisan:optimize', function () { run('{{bin/php}} {{release_path}}/artisan optimize'); }); /** * Task deploy:public_disk support the public disk. * To run this task automatically, please add below line to your deploy.php file * * before('deploy:symlink', 'deploy:public_disk'); * * @see https://laravel.com/docs/5.2/filesystem#configuration */ desc('Make symlink for public disk'); task('deploy:public_disk', function () { // Remove from source. run('if [ -d $(echo {{release_path}}/public/storage) ]; then rm -rf {{release_path}}/public/storage; fi'); // Create shared dir if it does not exist. run('mkdir -p {{deploy_path}}/shared/storage/app/public'); // Symlink shared dir to release dir run('{{bin/symlink}} {{deploy_path}}/shared/storage/app/public {{release_path}}/public/storage'); }); /** * Main task */ desc('Deploy your project'); task('deploy', ['deploy:prepare', 'deploy:lock', 'deploy:release', 'deploy:update_code', 'deploy:shared', 'deploy:vendors', 'deploy:writable', 'artisan:view:clear', 'artisan:cache:clear', 'artisan:config:cache', 'artisan:optimize', 'deploy:symlink', 'deploy:unlock', 'cleanup']); after('deploy', 'success');
* file that was distributed with this source code. */ namespace Deployer; require_once __DIR__ . '/common.php'; /** * CakePHP 3 Project Template configuration */ // CakePHP 3 Project Template shared dirs set('shared_dirs', ['logs', 'tmp']); // CakePHP 3 Project Template shared files set('shared_files', ['config/app.php']); /** * Create plugins' symlinks */ task('deploy:init', function () { run('{{release_path}}/bin/cake plugin assets symlink'); })->desc('Initialization'); /** * Run migrations */ task('deploy:run_migrations', function () { run('{{release_path}}/bin/cake migrations migrate'); run('{{release_path}}/bin/cake orm_cache clear'); run('{{release_path}}/bin/cake orm_cache build'); })->desc('Run migrations'); /** * Main task */ task('deploy', ['deploy:prepare', 'deploy:lock', 'deploy:release', 'deploy:update_code', 'deploy:shared', 'deploy:vendors', 'deploy:init', 'deploy:run_migrations', 'deploy:symlink', 'deploy:unlock', 'cleanup'])->desc('Deploy your project'); after('deploy', 'success');
<?php namespace Bob\BuildConfig; task("default", array("test")); desc("Runs all tests."); task("test", array("phpunit.xml", "composer.json"), function () { sh("./vendor/bin/phpunit"); }); fileTask("phpunit.xml", array("phpunit.dist.xml"), function ($task) { copy($task->prerequisites[0], $task->name); }); fileTask("composer.json", array("composer.lock"), function ($task) { if (!file_exists("composer.phar")) { file_put_contents("composer.phar", file_get_contents("http://getcomposer.org/composer.phar")); } php("composer.phar install --dev"); });
task('cachetool:clear:apc', function () { $releasePath = env('release_path'); $env = env(); $options = $env->has('cachetool') ? $env->get('cachetool') : get('cachetool'); if (strlen($options)) { $options = "--fcgi={$options}"; } cd($releasePath); $hasCachetool = run("if [ -e {$releasePath}/cachetool.phar ]; then echo 'true'; fi"); if ('true' !== $hasCachetool) { run("curl -sO http://gordalina.github.io/cachetool/downloads/cachetool.phar"); } run("{{bin/php}} cachetool.phar apc:cache:clear system {$options}"); })->desc('Clearing APC system cache'); /** * Clear opcache cache */ task('cachetool:clear:opcache', function () { $releasePath = env('release_path'); $env = env(); $options = $env->has('cachetool') ? $env->get('cachetool') : get('cachetool'); if (strlen($options)) { $options = "--fcgi={$options}"; } cd($releasePath); $hasCachetool = run("if [ -e {$releasePath}/cachetool.phar ]; then echo 'true'; fi"); if ('true' !== $hasCachetool) { run("curl -sO http://gordalina.github.io/cachetool/downloads/cachetool.phar"); } run("{{bin/php}} cachetool.phar opcache:reset {$options}"); })->desc('Clearing OPcode cache');
env('current', function () { return run("readlink {{deploy_path}}/current")->toString(); }); /** * Show current release number. */ task('current', function () { writeln('Current release: ' . basename(env('current'))); })->desc('Show current release.'); /** * Cleanup old releases. */ task('cleanup', function () { $releases = env('releases_list'); $keep = get('keep_releases'); while ($keep > 0) { array_shift($releases); --$keep; } foreach ($releases as $release) { run("rm -rf {{deploy_path}}/releases/{$release}"); } run("cd {{deploy_path}} && if [ -e release ]; then rm release; fi"); run("cd {{deploy_path}} && if [ -h release ]; then rm release; fi"); })->desc('Cleaning up old releases'); /** * Success message */ task('success', function () { writeln("<info>Successfully deployed!</info>"); })->once()->setPrivate();
<?php /* (c) Sergio Carracedo <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Deployer; require_once __DIR__ . '/common.php'; task('deploy', ['deploy:prepare', 'deploy:lock', 'deploy:release', 'deploy:update_code', 'deploy:shared', 'deploy:symlink', 'deploy:unlock', 'cleanup']); //Set drupal site. Change if you use different site set('drupal_site', 'default'); //Drupal 8 shared dirs set('shared_dirs', ['sites/{{drupal_site}}/files']); //Drupal 8 shared files set('shared_files', ['sites/{{drupal_site}}/settings.php', 'sites/{{drupal_site}}/services.yml']); //Drupal 8 Writable dirs set('writable_dirs', ['sites/{{drupal_site}}/files']);
<?php /* (c) Anton Medvedev <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Deployer; set('bin/npm', function () { return (string) run('which npm'); }); desc('Install npm packages'); task('npm:install', function () { $releases = get('releases_list'); if (isset($releases[1])) { if (run("if [ -d {{deploy_path}}/releases/{$releases[1]}/node_modules ]; then echo 'true'; fi")->toBool()) { run("cp --recursive {{deploy_path}}/releases/{$releases[1]}/node_modules {{release_path}}"); } } run("cd {{release_path}} && {{bin/npm}} install"); });
<?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']);
<?php /* (c) Lasse Lehtinen <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * Restart php-fpm */ task('php-fpm:restart', function () { run('service php-fpm restart'); })->desc('Restarting php-fpm process'); /** * Reload php-fpm */ task('php-fpm:reload', function () { run('service php-fpm reload'); })->desc('Reloading php-fpm process');
<?php if (!class_exists('EkAndreas\\DockerLaravel\\Helpers')) { include_once 'src/DockerLaravel/Helpers.php'; } use EkAndreas\DockerLaravel\Helpers; $dir = Helpers::getProjectDir(); require_once $dir . '/vendor/autoload.php'; include_once 'common.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('docker:cleanup', function () { Helpers::cleanup(); });
<?php date_default_timezone_set('Europe/Stockholm'); include_once 'vendor/ekandreas/docker-bedrock/recipe.php'; include_once 'vendor/ekandreas/dipwpe/pull.php'; server('nordiciron.dev', 'default')->env('container', 'bedrock')->stage('development'); server('production', 'andreasek.se', 22)->env('deploy_path', '/mnt/persist/www/nordiciron.com')->user('root')->env('branch', 'master')->env('remote.name', 'nordiciron')->env('remote.database', 'nordiciron')->env('remote.ssh', '*****@*****.**')->env('remote.domain', 'www.nordiciron.com')->env('local.domain', 'nordiciron.dev')->env('remote.path', '/mnt/persist/www/nordiciron.com')->env('local.is_elastic', false)->stage('production')->identityFile(); set('repository', 'git@github.com:ekandreas/nordiciron.git'); // Symlink the .env file for Bedrock set('env', 'prod'); set('keep_releases', 10); set('shared_dirs', ['web/app/uploads']); set('shared_files', ['.env', 'web/.htaccess', 'web/robots.txt']); set('env_vars', '/usr/bin/env'); task('deploy:restart', function () { writeln('Purge cache...'); //run("curl -s http://www.skolporten.se/wp/wp-admin/admin-ajax.php?action=purge"); })->desc('Restarting apache2 and varnish'); task('deploy', ['deploy:prepare', 'deploy:release', 'deploy:update_code', 'deploy:vendors', 'deploy:shared', 'deploy:symlink', 'cleanup', 'deploy:restart', 'success'])->desc('Deploy your Bedrock project, eg dep deploy production');
}); 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'); curl_setopt($ch, CURLOPT_URL, $uri); $release = json_decode(curl_exec($ch)); $releaseId = $release->id; $uri = 'https://api.github.com/repos/' . get('repository') . '/releases/' . $releaseId; $ch = getGithubCurl(); curl_setopt($ch, CURLOPT_URL, $uri); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); curl_exec($ch); }); set('username', 'mneuhaus'); set('repository', 'mia3/koseki'); task('release:patch', ['release:askPasswort', 'release:increaseVersionPatch', 'release:commitComposer', 'release:tagRelease', 'release:pushTags', 'release:createGithubRelease']); task('release:minor', ['release:askPasswort', 'release:increaseVersionMinor', 'release:commitComposer', 'release:tagRelease', 'release:pushTags', 'release:createGithubRelease']); task('release:major', ['release:askPasswort', 'release:increaseVersionMajor', 'release:commitComposer', 'release:tagRelease', 'release:pushTags', 'release:createGithubRelease']); task('release:replaceCurrent', ['release:askPasswort', 'release:fetchVersion', 'release:destroyGithubRelease', 'release:removeCurrentTagFromRemote', 'release:tagRelease', 'release:pushTags', 'release:createGithubRelease']);
task('local-config', function () { if (askConfirmation("Local configuration.\n\nThis will overwrite any existing file without further warning!\n\nAre you sure you want to continue?")) { /** * Paser value for template compiler * * @param array $matches * @return string */ $paser = function ($matches) { if (isset($matches[1])) { if ($matches[1] === 'release_path') { $matches[1] = 'deploy_path'; } $value = env()->get($matches[1]); if (is_null($value) || is_bool($value) || is_array($value)) { $value = var_export($value, true); } } else { $value = $matches[0]; } return $value; }; /** * Template compiler * * @param string $contents * @return string */ $compiler = function ($contents) use($paser) { $contents = preg_replace_callback('/\\{\\{\\s*([\\w\\.]+)\\s*\\}\\}/', $paser, $contents); return $contents; }; $finder = new \Symfony\Component\Finder\Finder(); $iterator = $finder->ignoreDotFiles(false)->files()->name('/\\.tpl$/')->in(getcwd() . '/deployer/templates'); $tmpDir = sys_get_temp_dir(); $releaseDir = env('deploy_path'); /* @var $file \Symfony\Component\Finder\SplFileInfo */ foreach ($iterator as $file) { $success = false; // Make tmp file $tmpFile = tempnam($tmpDir, 'tmp'); if (!empty($tmpFile)) { try { $contents = $compiler($file->getContents()); // cookie validation key if (basename($file) === 'web.php.tpl') { $length = 32; $bytes = openssl_random_pseudo_bytes($length); $key = strtr(substr(base64_encode($bytes), 0, $length), '+/=', '_-.'); $contents = preg_replace('/(("|\')cookieValidationKey("|\')\\s*=>\\s*)(""|\'\')/', "\\1'{$key}'", $contents); } $target = preg_replace('/\\.tpl$/', '', $file->getRelativePathname()); // Put contents and upload tmp file to server if (file_put_contents($tmpFile, $contents) > 0) { if (basename($file) === 'yii.tpl') { upload($tmpFile, "{$releaseDir}/" . $target); run('chmod +x ' . "{$releaseDir}/" . $target); } else { run("mkdir -p {$releaseDir}/" . dirname($target)); upload($tmpFile, "{$releaseDir}/" . $target); } $success = true; } } catch (\Exception $e) { $success = false; } // Delete tmp file unlink($tmpFile); } if ($success) { writeln(sprintf("<info>✔</info> %s", $file->getRelativePathname())); } else { writeln(sprintf("<fg=red>✘</fg=red> %s", $file->getRelativePathname())); } } $theme = env('app.theme'); $finder = new \Symfony\Component\Finder\Finder(); $iterator = $finder->ignoreDotFiles(false)->files()->name('/\\.*$/')->in(getcwd() . '/themes/' . $theme . '/build'); foreach ($iterator as $file) { upload($file, "{$releaseDir}/" . $file->getRelativePathname()); writeln(sprintf("<info>✔</info> %s", $file->getRelativePathname())); } } })->desc('Configures your local development environment')->onlyForStage('local');
}); after('deploy:symlink', 'deploy:cron:enable'); task('deploy:database:update', function () { run('php {{release_path}}/' . trim(get('bin_dir'), '/') . '/console doctrine:schema:update --env={{env}} --force'); }); after('deploy:vendors', 'deploy:database:update'); task('elastica:populate', function () { run('php {{release_path}}/' . trim(get('bin_dir'), '/') . '/console fos:elastica:populate --env=\'prod\''); }); task('php:restart', function () { run('sudo service {{php_fpm}} restart'); }); after('deploy', 'php:restart'); task('elastica:populate', function () { run('php {{release_path}}/' . trim(get('bin_dir'), '/') . '/console fos:elastica:populate --env=\'prod\''); }); task('elastica:populate:current', function () { run('php {{deploy_path}}/current/' . trim(get('bin_dir'), '/') . '/console fos:elastica:populate --env=\'prod\''); }); task('seo:dump', function () { run('php {{release_path}}/' . trim(get('bin_dir'), '/') . '/console seo:metatag:patterns --env=\'prod\''); run('php {{release_path}}/' . trim(get('bin_dir'), '/') . '/console seo:sitemap --env=\'prod\''); }); task('deploy:cleanup', function () { run('rm -f {{release_path}}/Vagrantfile*'); run('rm -f {{release_path}}/deploy.php'); run('rm -rf {{release_path}}/.git'); run('rm -f {{release_path}}/README*'); run('rm -f {{release_path}}/build.xml'); }); after('cleanup', 'deploy:cleanup');
task('deploy:configure', function () { /** * Paser value for template compiler * * @param array $matches * @return string */ $paser = function ($matches) { if (isset($matches[1])) { $value = env()->get($matches[1]); if (is_null($value) || is_bool($value) || is_array($value)) { $value = var_export($value, true); } } else { $value = $matches[0]; } return $value; }; /** * Template compiler * * @param string $contents * @return string */ $compiler = function ($contents) use($paser) { $contents = preg_replace_callback('/\\{\\{\\s*([\\w\\.]+)\\s*\\}\\}/', $paser, $contents); return $contents; }; $configFiles = '/deployer/environments/prod'; $stage = env('app.stage'); if ($stage == 'dev') { $configFiles = '/deployer/environments/dev'; } $finder = new \Symfony\Component\Finder\Finder(); $iterator = $finder->ignoreDotFiles(false)->files()->name('/\\.tpl$/')->in(getcwd() . $configFiles); $tmpDir = sys_get_temp_dir(); $releaseDir = env('release_path'); /* @var $file \Symfony\Component\Finder\SplFileInfo */ foreach ($iterator as $file) { $success = false; // Make tmp file $tmpFile = tempnam($tmpDir, 'tmp'); if (!empty($tmpFile)) { try { $contents = $compiler($file->getContents()); // cookie validation keys if (basename($file) === 'main-local.php.tpl') { $length = 32; $bytes = openssl_random_pseudo_bytes($length); $key = strtr(substr(base64_encode($bytes), 0, $length), '+/=', '_-.'); $contents = preg_replace('/(("|\')cookieValidationKey("|\')\\s*=>\\s*)(""|\'\')/', "\\1'{$key}'", $contents); } $target = preg_replace('/\\.tpl$/', '', $file->getRelativePathname()); // Put contents and upload tmp file to server if (file_put_contents($tmpFile, $contents) > 0) { if (basename($file) === 'yii.tpl') { upload($tmpFile, "{$releaseDir}/" . $target); run('chmod +x ' . "{$releaseDir}/" . $target); } else { run("mkdir -p {$releaseDir}/" . dirname($target)); upload($tmpFile, "{$releaseDir}/" . $target); } $success = true; } } catch (\Exception $e) { $success = false; } // Delete tmp file unlink($tmpFile); } if ($success) { writeln(sprintf("<info>✔</info> %s", $file->getRelativePathname())); } else { writeln(sprintf("<fg=red>✘</fg=red> %s", $file->getRelativePathname())); } } })->desc('Make configure files for your stage');
* * NOTE: you should add the following permission to the sudo file (with visudo command) * * user_name ALL=(ALL) NOPASSWD: /usr/bin/setfacl */ require 'recipe/common.php'; serverList('deploy/servers.yml'); /** * Do not use sudo to setup writable folders. * You should setup access to setfacl via sudoers file on the server */ set('writable_use_sudo', false); set('repository', '<repo_url>'); set('shared_dirs', ['data', 'app/frontend/runtime', 'app/backend/runtime', 'app/common/runtime', 'app/console/runtime', 'app/backend/web/media', 'app/frontend/web/media']); set('shared_files', ['.env']); set('writable_dirs', ['data', 'app/frontend/runtime', 'app/backend/runtime', 'app/common/runtime', 'app/console/runtime', 'app/backend/web/media', 'app/frontend/web/media', 'app/backend/web/assets', 'app/frontend/web/assets']); /** * Migrate database */ task('database:migrate', function () { run('php {{release_path}}/yii migrate/up --interactive=0'); })->desc('Migrate database'); /** * Saving version of the application */ task('save_version', function () { run('cd {{release_path}} && git rev-parse --short HEAD > .version'); })->desc('Saving version'); task('prepare', ['deploy:prepare', 'deploy:release', 'deploy:update_code', 'deploy:shared', 'deploy:writable', 'deploy:vendors', 'deploy:symlink', 'cleanup'])->desc('Prepare library, using first time deploy'); task('deploy', ['deploy:prepare', 'deploy:release', 'deploy:update_code', 'deploy:shared', 'deploy:writable', 'deploy:vendors', 'database:migrate', 'save_version', 'deploy:symlink', 'cleanup'])->desc('Deploy'); after('deploy', 'success');
}); }); desc('bleem'); task('bleem', function () { p(0); }); after('bleem:baz', function () { p(3); }); desc('foo'); task('foo', function () { p(5); }); desc('bar'); task('bar', function () { p(8); }); task('foo', function () { p(6); }); before('foo', function () { p(4); }); after('foo', function () { p(7); }); task('foo', 'bleem:baz'); desc('default'); task('default', 'foo'); task('default', 'bar');
<div class="cell" style="width: 100px;"> ได้คะแนน </div> <div class="cell" style="width: 100px;"> เวลารวม </div> </div> <?php $query = 'SELECT * FROM `result` WHERE `user_id` = ' . $_GET['userid'] . ' ORDER BY `result_id` DESC limit 100'; $sql->prepare($query); //if(!isAdmin()) $sql->bind_param('d', $_SESSION[$config['name_short']]['user_id']); $sql->execute(); $sql->bind_result($result_id, $user_id, $task_id, $time, $text, $score, $timeused, $message); while ($sql->fetch()) { $user = user($user_id); $task = task($task_id); echo ' <div class="row" style="text-align: center;"> <div class="cell"> ' . $result_id . ' <a href="javascript:code_watch(\'' . $task["task_id"] . '\',\'' . $user["user"] . '\')"><img style="height:30px" src="addon/img/code_icon.png"></a> </div> <div class="cell"> ' . D('d m y H:M:S', $time) . ' </div> <div class="cell"> ' . $user['display'] . ' ' . ($my['level'] == 0 ? '(' . $user['user'] . ')' : '') . ' </div> <div class="cell"> <a href="doc.php?id=' . $task['task_id'] . '" target="_blank">' . $task['name'] . '</a> </div>
<?php /* (c) Anton Medvedev <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once __DIR__ . '/common.php'; // CodeIgniter shared dirs set('shared_dirs', ['application/cache', 'application/logs']); // CodeIgniter writable dirs set('writable_dirs', ['application/cache', 'application/logs']); /** * Main task */ task('deploy', ['deploy:prepare', 'deploy:release', 'deploy:update_code', 'deploy:vendors', 'deploy:shared', 'deploy:symlink', 'cleanup'])->desc('Deploy your project'); after('deploy', 'success');
<?php /* (c) Anton Medvedev <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Deployer; desc('Rollback to previous release'); task('rollback', function () { $releases = get('releases_list'); if (isset($releases[1])) { $releaseDir = "{{deploy_path}}/releases/{$releases[1]}"; // Symlink to old release. run("cd {{deploy_path}} && {{bin/symlink}} {$releaseDir} current"); // Remove release run("rm -rf {{deploy_path}}/releases/{$releases[0]}"); if (isVerbose()) { writeln("Rollback to `{$releases[1]}` release was successful."); } } else { writeln("<comment>No more releases you can revert to.</comment>"); } });
task('deploy:cloudflare', function () { $config = get('cloudflare', []); //validate config and set headers if (!empty($config['service_key'])) { $headers = ['X-Auth-User-Service-Key' => $config['service_key']]; } elseif (!empty($config['email']) && !empty($config['api_key'])) { $headers = ['X-Auth-Key' => $config['api_key'], 'X-Auth-Email' => $config['email']]; } else { throw new \RuntimeException("Set a service key or email / api key"); } $headers['Content-Type'] = 'application/json'; if (empty($config['domain'])) { throw new RuntimeException("Set a domain"); } $makeRequest = function ($url, $opts = []) use($headers) { $ch = curl_init("https://api.cloudflare.com/client/v4/{$url}"); foreach ($headers as $key => $value) { $parsedHeaders[] = "{$key}: {$value}"; } curl_setopt_array($ch, [CURLOPT_HTTPHEADER => $parsedHeaders, CURLOPT_RETURNTRANSFER => true]); curl_setopt_array($ch, $opts); $res = curl_exec($ch); if (curl_errno($ch)) { throw new \RuntimeException("Error making curl request (result: {$res})"); } curl_close($ch); return $res; }; // get the mysterious zone id from Cloud Flare $zones = json_decode($makeRequest("zones?name={$config['domain']}"), true); if (empty($zones['success']) || !empty($zones['errors'])) { throw new \RuntimeException("Problem with zone data"); } else { $zoneId = current($zones['result'])['id']; } // make purge request $makeRequest("zones/{$zoneId}/purge_cache", [CURLOPT_CUSTOMREQUEST => 'DELETE', CURLOPT_POSTFIELDS => json_encode(['purge_everything' => true])]); });
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}}'); }); }