[TASK] Reorganize and cleanup
This commit is contained in:
parent
d5ea903e4d
commit
0bb546a16f
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Evoweb\DeployerConfig\Config;
|
namespace Evoweb\DeployerConfig\Config;
|
||||||
|
|
||||||
|
use Deployer\Deployer;
|
||||||
use Deployer\Exception\Exception;
|
use Deployer\Exception\Exception;
|
||||||
use Evoweb\DeployerConfig\Tasks\Deploy;
|
use Evoweb\DeployerConfig\Tasks\Deploy;
|
||||||
use Evoweb\DeployerConfig\Tasks\Local;
|
use Evoweb\DeployerConfig\Tasks\Local;
|
||||||
|
|||||||
@ -8,6 +8,7 @@ use Deployer\Deployer;
|
|||||||
use Deployer\Task\GroupTask;
|
use Deployer\Task\GroupTask;
|
||||||
use Deployer\Task\Task;
|
use Deployer\Task\Task;
|
||||||
use Evoweb\DeployerConfig\Config\Deployment;
|
use Evoweb\DeployerConfig\Config\Deployment;
|
||||||
|
use InvalidArgumentException;
|
||||||
use phpDocumentor\Reflection\DocBlockFactory;
|
use phpDocumentor\Reflection\DocBlockFactory;
|
||||||
use ReflectionMethod;
|
use ReflectionMethod;
|
||||||
|
|
||||||
@ -36,11 +37,14 @@ abstract class AbstractTasks
|
|||||||
array_walk($this->tasks, [$this, 'registerTask']);
|
array_walk($this->tasks, [$this, 'registerTask']);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function registerTask(array $config, string $name): void
|
protected function registerTask(array|string $body, string $name): void
|
||||||
{
|
{
|
||||||
$body = $config['body'] ?? '';
|
if (!is_array($body)) {
|
||||||
if (is_string($body) && !method_exists($this, $body)) {
|
$name = $body;
|
||||||
return;
|
$body = lcfirst(str_replace('_', '', ucwords(strtolower(preg_replace('/[^:]+:/', '', $body)), '_')));
|
||||||
|
if (!method_exists($this, $body)) {
|
||||||
|
print_r('not found ' . $body . "\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_callable([$this, $body])) {
|
if (is_callable([$this, $body])) {
|
||||||
@ -53,13 +57,9 @@ abstract class AbstractTasks
|
|||||||
} elseif (is_array($body)) {
|
} elseif (is_array($body)) {
|
||||||
$task = new GroupTask($name, $body);
|
$task = new GroupTask($name, $body);
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException('Task body should be a function or an array.');
|
throw new InvalidArgumentException('Task body should be a function or an array.');
|
||||||
}
|
}
|
||||||
|
|
||||||
array_map(function ($selector) use ($task) {
|
|
||||||
$task->addSelector($selector);
|
|
||||||
}, $config['stages'] ?? []);
|
|
||||||
|
|
||||||
$deployer = Deployer::get();
|
$deployer = Deployer::get();
|
||||||
$deployer->tasks->set($name, $task);
|
$deployer->tasks->set($name, $task);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,40 +10,36 @@ class Deploy extends AbstractTasks
|
|||||||
{
|
{
|
||||||
protected array $tasks = [
|
protected array $tasks = [
|
||||||
'deploy:prepare' => [
|
'deploy:prepare' => [
|
||||||
'body' => [
|
'local:info',
|
||||||
'local:info',
|
'local:setup',
|
||||||
'local:setup',
|
'remote:prepare',
|
||||||
'remote:prepare',
|
'rsync:warmup',
|
||||||
'rsync:warmup',
|
'local:lock',
|
||||||
'local:lock',
|
'local:release',
|
||||||
'local:release',
|
'local:update_code',
|
||||||
'local:update_code',
|
'local:env',
|
||||||
'local:env',
|
'local:shared',
|
||||||
'local:shared',
|
'local:writable',
|
||||||
'local:writable',
|
'local:write_release',
|
||||||
'local:write_release',
|
'local:create_folder',
|
||||||
'local:create_folder',
|
'local:vendors',
|
||||||
'local:vendors',
|
|
||||||
]
|
|
||||||
],
|
],
|
||||||
|
|
||||||
'deploy:publish' => [
|
'deploy:publish' => [
|
||||||
'body' => [
|
'local:clear_paths',
|
||||||
'local:clear_paths',
|
'local:symlink',
|
||||||
'local:symlink',
|
'local:cleanup',
|
||||||
'local:cleanup',
|
'rsync:remote',
|
||||||
'rsync:remote',
|
'remote:change_group',
|
||||||
'remote:change_group',
|
'remote:writable',
|
||||||
'remote:writable',
|
'remote:db_compare',
|
||||||
'remote:db_compare',
|
'remote:fix_folder_structure',
|
||||||
'remote:fix_folder_structure',
|
'rsync:switch_current',
|
||||||
'rsync:switch_current',
|
'remote:clear_cache',
|
||||||
'remote:clear_cache',
|
'remote:clear_opcache',
|
||||||
'remote:clear_opcache',
|
'local:echo_release_number',
|
||||||
'local:echo_release_number',
|
'local:unlock',
|
||||||
'local:unlock',
|
'deploy:success',
|
||||||
'deploy:success'
|
|
||||||
]
|
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@ -24,28 +24,28 @@ use function Deployer\timestamp;
|
|||||||
class Local extends AbstractTasks
|
class Local extends AbstractTasks
|
||||||
{
|
{
|
||||||
protected array $tasks = [
|
protected array $tasks = [
|
||||||
'local:info' => ['body' => 'localInfo'],
|
'local:info',
|
||||||
'local:setup' => ['body' => 'localSetup'],
|
'local:setup',
|
||||||
'local:lock' => ['body' => 'localLock'],
|
'local:lock',
|
||||||
'local:unlock' => ['body' => 'localUnlock'],
|
'local:unlock',
|
||||||
'local:release' => ['body' => 'localRelease'],
|
'local:release',
|
||||||
'local:update_code' => ['body' => 'localUpdateCode'],
|
'local:update_code',
|
||||||
'local:env' => ['body' => 'localEnv'],
|
'local:env',
|
||||||
'local:shared' => ['body' => 'localShared'],
|
'local:shared',
|
||||||
'local:writable' => ['body' => 'localWritable'],
|
'local:writable',
|
||||||
'local:write_release' => ['body' => 'localWriteRelease'],
|
'local:write_release',
|
||||||
'local:create_folder' => ['body' => 'localCreateFolder'],
|
'local:create_folder',
|
||||||
'local:vendors' => ['body' => 'localVendors'],
|
'local:vendors',
|
||||||
'local:clear_paths' => ['body' => 'localClearPaths'],
|
'local:clear_paths',
|
||||||
'local:symlink' => ['body' => 'localSymlink'],
|
'local:symlink',
|
||||||
'local:cleanup' => ['body' => 'localCleanup'],
|
'local:cleanup',
|
||||||
'local:echo_release_number' => ['body' => 'localEchoReleaseNumber'],
|
'local:echo_release_number',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays info about deployment
|
* Displays info about deployment
|
||||||
*/
|
*/
|
||||||
public function localInfo(): void
|
public function info(): void
|
||||||
{
|
{
|
||||||
info("deploying <fg=green;options=bold>{{what}}</> to <fg=magenta;options=bold>{{where}}</>");
|
info("deploying <fg=green;options=bold>{{what}}</> to <fg=magenta;options=bold>{{where}}</>");
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ class Local extends AbstractTasks
|
|||||||
/**
|
/**
|
||||||
* Prepares host for deploy
|
* Prepares host for deploy
|
||||||
*/
|
*/
|
||||||
public function localSetup(): void
|
public function setup(): void
|
||||||
{
|
{
|
||||||
runLocally(
|
runLocally(
|
||||||
<<<EOF
|
<<<EOF
|
||||||
@ -75,7 +75,7 @@ class Local extends AbstractTasks
|
|||||||
/**
|
/**
|
||||||
* Locks deploy
|
* Locks deploy
|
||||||
*/
|
*/
|
||||||
public function localLock(): void
|
public function lock(): void
|
||||||
{
|
{
|
||||||
$user = escapeshellarg(get('user'));
|
$user = escapeshellarg(get('user'));
|
||||||
$locked = runLocally("[ -f {{deploy_path}}/.dep/deploy.lock ] && echo +locked || echo $user > {{deploy_path}}/.dep/deploy.lock");
|
$locked = runLocally("[ -f {{deploy_path}}/.dep/deploy.lock ] && echo +locked || echo $user > {{deploy_path}}/.dep/deploy.lock");
|
||||||
@ -91,7 +91,7 @@ class Local extends AbstractTasks
|
|||||||
/**
|
/**
|
||||||
* Unlocks deploy
|
* Unlocks deploy
|
||||||
*/
|
*/
|
||||||
public function localUnlock(): void
|
public function unlock(): void
|
||||||
{
|
{
|
||||||
// always success
|
// always success
|
||||||
runLocally("rm -f {{deploy_path}}/.dep/deploy.lock");
|
runLocally("rm -f {{deploy_path}}/.dep/deploy.lock");
|
||||||
@ -100,7 +100,7 @@ class Local extends AbstractTasks
|
|||||||
/**
|
/**
|
||||||
* Prepares release
|
* Prepares release
|
||||||
*/
|
*/
|
||||||
public function localRelease(): void
|
public function release(): void
|
||||||
{
|
{
|
||||||
// Clean up if there is unfinished release.
|
// Clean up if there is unfinished release.
|
||||||
if (testLocally('[ -h {{deploy_path}}/release ]')) {
|
if (testLocally('[ -h {{deploy_path}}/release ]')) {
|
||||||
@ -163,7 +163,7 @@ class Local extends AbstractTasks
|
|||||||
/**
|
/**
|
||||||
* Updates code
|
* Updates code
|
||||||
*/
|
*/
|
||||||
public function localUpdateCode(): void
|
public function updateCode(): void
|
||||||
{
|
{
|
||||||
$git = get('bin/git');
|
$git = get('bin/git');
|
||||||
$repository = get('repository');
|
$repository = get('repository');
|
||||||
@ -216,7 +216,7 @@ class Local extends AbstractTasks
|
|||||||
/**
|
/**
|
||||||
* Configure .env file
|
* Configure .env file
|
||||||
*/
|
*/
|
||||||
public function localEnv(): void
|
public function env(): void
|
||||||
{
|
{
|
||||||
if (testLocally('[ ! -e {{release_or_current_path}}/.env ] && [ -f {{release_or_current_path}}/{{dotenv_example}} ]')) {
|
if (testLocally('[ ! -e {{release_or_current_path}}/.env ] && [ -f {{release_or_current_path}}/{{dotenv_example}} ]')) {
|
||||||
runLocally('cp {{release_or_current_path}}/{{dotenv_example}} {{release_or_current_path}}/.env');
|
runLocally('cp {{release_or_current_path}}/{{dotenv_example}} {{release_or_current_path}}/.env');
|
||||||
@ -226,7 +226,7 @@ class Local extends AbstractTasks
|
|||||||
/**
|
/**
|
||||||
* Creates symlinks for shared files and dirs
|
* Creates symlinks for shared files and dirs
|
||||||
*/
|
*/
|
||||||
public function localShared(): void
|
public function shared(): void
|
||||||
{
|
{
|
||||||
$sharedPath = "{{deploy_path}}/shared";
|
$sharedPath = "{{deploy_path}}/shared";
|
||||||
|
|
||||||
@ -298,7 +298,7 @@ class Local extends AbstractTasks
|
|||||||
/**
|
/**
|
||||||
* Makes writable dirs
|
* Makes writable dirs
|
||||||
*/
|
*/
|
||||||
public function localWritable(): void
|
public function writable(): void
|
||||||
{
|
{
|
||||||
$dirs = join(' ', get('writable_dirs'));
|
$dirs = join(' ', get('writable_dirs'));
|
||||||
$mode = get('writable_mode');
|
$mode = get('writable_mode');
|
||||||
@ -385,15 +385,15 @@ class Local extends AbstractTasks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function localWriteRelease(): void
|
public function writeRelease(): void
|
||||||
{
|
{
|
||||||
runLocally('echo ' . getEnv('CI_COMMIT_REF_NAME') . ' > {{release_path}}/release');
|
runLocally('echo {{target}} > {{release_path}}/release');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creating necessary folders
|
* Creating necessary folders
|
||||||
*/
|
*/
|
||||||
public function localCreateFolder(): void
|
public function createFolder(): void
|
||||||
{
|
{
|
||||||
$sudo = $this->getSudo();
|
$sudo = $this->getSudo();
|
||||||
|
|
||||||
@ -411,7 +411,7 @@ class Local extends AbstractTasks
|
|||||||
/**
|
/**
|
||||||
* Installing vendors
|
* Installing vendors
|
||||||
*/
|
*/
|
||||||
public function localVendors(): void
|
public function vendors(): void
|
||||||
{
|
{
|
||||||
if (!$this->commandExist('unzip')) {
|
if (!$this->commandExist('unzip')) {
|
||||||
info(
|
info(
|
||||||
@ -429,7 +429,7 @@ class Local extends AbstractTasks
|
|||||||
/**
|
/**
|
||||||
* Cleanup files and/or directories
|
* Cleanup files and/or directories
|
||||||
*/
|
*/
|
||||||
public function localClearPaths(): void
|
public function clearPaths(): void
|
||||||
{
|
{
|
||||||
$paths = get('clear_paths');
|
$paths = get('clear_paths');
|
||||||
$sudo = get('clear_use_sudo') ? 'sudo' : '';
|
$sudo = get('clear_use_sudo') ? 'sudo' : '';
|
||||||
@ -448,7 +448,7 @@ class Local extends AbstractTasks
|
|||||||
/**
|
/**
|
||||||
* Creating symlink to release
|
* Creating symlink to release
|
||||||
*/
|
*/
|
||||||
public function localSymlink(): void
|
public function symlink(): void
|
||||||
{
|
{
|
||||||
if (get('use_atomic_symlink')) {
|
if (get('use_atomic_symlink')) {
|
||||||
runLocally("mv -T {{deploy_path}}/release {{current_path}}");
|
runLocally("mv -T {{deploy_path}}/release {{current_path}}");
|
||||||
@ -464,7 +464,7 @@ class Local extends AbstractTasks
|
|||||||
/**
|
/**
|
||||||
* Cleaning up old releases
|
* Cleaning up old releases
|
||||||
*/
|
*/
|
||||||
public function localCleanup(): void
|
public function cleanup(): void
|
||||||
{
|
{
|
||||||
$releases = get('releases_list');
|
$releases = get('releases_list');
|
||||||
$keep = get('keep_releases');
|
$keep = get('keep_releases');
|
||||||
@ -479,7 +479,7 @@ class Local extends AbstractTasks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function localEchoReleaseNumber(): void
|
public function echoReleaseNumber(): void
|
||||||
{
|
{
|
||||||
info('Folder of this release is: {{release_path}}');
|
info('Folder of this release is: {{release_path}}');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,19 +14,19 @@ use function Deployer\writeln;
|
|||||||
class Remote extends AbstractTasks
|
class Remote extends AbstractTasks
|
||||||
{
|
{
|
||||||
protected array $tasks = [
|
protected array $tasks = [
|
||||||
'remote:prepare' => ['body' => 'remotePrepare'],
|
'remote:prepare',
|
||||||
'remote:change_group' => ['body' => 'remoteChangeGroup'],
|
'remote:change_group',
|
||||||
'remote:writable' => ['body' => 'remoteWritable'],
|
'remote:writable',
|
||||||
'remote:db_compare' => ['body' => 'remoteDbCompare'],
|
'remote:db_compare',
|
||||||
'remote:fix_folder_structure' => ['body' => 'remoteFixFolderStructure'],
|
'remote:fix_folder_structure',
|
||||||
'remote:clear_cache' => ['body' => 'remoteClearCache'],
|
'remote:clear_cache',
|
||||||
'remote:clear_opcache' => ['body' => 'remoteClearOpcache'],
|
'remote:clear_opcache',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare remote path exists
|
* Prepare remote path exists
|
||||||
*/
|
*/
|
||||||
public function remotePrepare(): void
|
public function prepare(): void
|
||||||
{
|
{
|
||||||
if (!$this->hasArray('prepare_dirs')) {
|
if (!$this->hasArray('prepare_dirs')) {
|
||||||
return;
|
return;
|
||||||
@ -43,7 +43,7 @@ class Remote extends AbstractTasks
|
|||||||
/**
|
/**
|
||||||
* Change usergroup for the hole project
|
* Change usergroup for the hole project
|
||||||
*/
|
*/
|
||||||
public function remoteChangeGroup(): void
|
public function changeGroup(): void
|
||||||
{
|
{
|
||||||
if ($this->get('http_group')) {
|
if ($this->get('http_group')) {
|
||||||
$sudo = get('writable_use_sudo') ? 'sudo' : '';
|
$sudo = get('writable_use_sudo') ? 'sudo' : '';
|
||||||
@ -61,7 +61,7 @@ class Remote extends AbstractTasks
|
|||||||
/**
|
/**
|
||||||
* Set files and/or folders writable
|
* Set files and/or folders writable
|
||||||
*/
|
*/
|
||||||
public function remoteWritable(): void
|
public function writable(): void
|
||||||
{
|
{
|
||||||
if ($this->hasArray('writable_dirs') || $this->hasArray('writable_files')) {
|
if ($this->hasArray('writable_dirs') || $this->hasArray('writable_files')) {
|
||||||
$sudo = get('writable_use_sudo') ? 'sudo' : '';
|
$sudo = get('writable_use_sudo') ? 'sudo' : '';
|
||||||
@ -104,7 +104,7 @@ class Remote extends AbstractTasks
|
|||||||
/**
|
/**
|
||||||
* Database migration
|
* Database migration
|
||||||
*/
|
*/
|
||||||
public function remoteDbCompare(): void
|
public function dbCompare(): void
|
||||||
{
|
{
|
||||||
$path = parse('{{app_container_path}}') ?: parse('{{remote_path}}');
|
$path = parse('{{app_container_path}}') ?: parse('{{remote_path}}');
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ class Remote extends AbstractTasks
|
|||||||
/**
|
/**
|
||||||
* Fix folder structure
|
* Fix folder structure
|
||||||
*/
|
*/
|
||||||
public function remoteFixFolderStructure(): void
|
public function fixFolderStructure(): void
|
||||||
{
|
{
|
||||||
$path = parse('{{app_container_path}}') ?: parse('{{remote_path}}');
|
$path = parse('{{app_container_path}}') ?: parse('{{remote_path}}');
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ class Remote extends AbstractTasks
|
|||||||
/**
|
/**
|
||||||
* Clear cache via typo3 cache:flush
|
* Clear cache via typo3 cache:flush
|
||||||
*/
|
*/
|
||||||
public function remoteClearCache(): void
|
public function clearCache(): void
|
||||||
{
|
{
|
||||||
$path = parse('{{app_container_path}}') ?: parse('{{remote_path}}');
|
$path = parse('{{app_container_path}}') ?: parse('{{remote_path}}');
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ class Remote extends AbstractTasks
|
|||||||
/**
|
/**
|
||||||
* Clear opcache via curl on {CI_HOST}/cache.php
|
* Clear opcache via curl on {CI_HOST}/cache.php
|
||||||
*/
|
*/
|
||||||
public function remoteClearOpcache(): void
|
public function clearOpcache(): void
|
||||||
{
|
{
|
||||||
$webDomain = rtrim($this->get('web_domain'), '/');
|
$webDomain = rtrim($this->get('web_domain'), '/');
|
||||||
$htaccess = $this->has('htaccess') ? '--user ' . $this->get('htaccess') : '';
|
$htaccess = $this->has('htaccess') ? '--user ' . $this->get('htaccess') : '';
|
||||||
|
|||||||
@ -42,9 +42,9 @@ class Rsync extends AbstractTasks
|
|||||||
];
|
];
|
||||||
|
|
||||||
protected array $tasks = [
|
protected array $tasks = [
|
||||||
'rsync:warmup' => ['body' => 'warmup'],
|
'rsync:warmup',
|
||||||
'rsync:remote' => ['body' => 'remote'],
|
'rsync:remote',
|
||||||
'rsync:switch_current' => ['body' => 'switchCurrent'],
|
'rsync:switch_current',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected function setDefaultConfiguration(): void
|
protected function setDefaultConfiguration(): void
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user