@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | namespace Deployer; |
| 4 | 4 | |
| 5 | -set('db_type', function () { |
|
| 5 | +set('db_type', function() { |
|
| 6 | 6 | $supportedDbTypes = [ |
| 7 | 7 | 'none', |
| 8 | 8 | 'mysql', |
@@ -12,20 +12,20 @@ discard block |
||
| 12 | 12 | return askChoice(' What DB to install? ', $supportedDbTypes, 0); |
| 13 | 13 | }); |
| 14 | 14 | |
| 15 | -set('db_name', function () { |
|
| 15 | +set('db_name', function() { |
|
| 16 | 16 | return ask(' DB name: ', 'prod'); |
| 17 | 17 | }); |
| 18 | 18 | |
| 19 | -set('db_user', function () { |
|
| 19 | +set('db_user', function() { |
|
| 20 | 20 | return ask(' DB user: ', 'deployer'); |
| 21 | 21 | }); |
| 22 | 22 | |
| 23 | -set('db_password', function () { |
|
| 23 | +set('db_password', function() { |
|
| 24 | 24 | return askHiddenResponse(' DB password: '); |
| 25 | 25 | }); |
| 26 | 26 | |
| 27 | 27 | desc('Provision databases'); |
| 28 | -task('provision:databases', function () { |
|
| 28 | +task('provision:databases', function() { |
|
| 29 | 29 | set('remote_user', get('provision_user')); |
| 30 | 30 | |
| 31 | 31 | $dbType = get('db_type'); |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | ->limit(1); |
| 38 | 38 | |
| 39 | 39 | desc('Provision MySQL'); |
| 40 | -task('provision:mysql', function () { |
|
| 40 | +task('provision:mysql', function() { |
|
| 41 | 41 | run('apt-get install -y mysql-server', env: ['DEBIAN_FRONTEND' => 'noninteractive'], timeout: 900); |
| 42 | 42 | run("mysql --user=\"root\" -e \"CREATE USER IF NOT EXISTS '{{db_user}}'@'0.0.0.0' IDENTIFIED BY '%secret%';\"", secret: get('db_password')); |
| 43 | 43 | run("mysql --user=\"root\" -e \"CREATE USER IF NOT EXISTS '{{db_user}}'@'%' IDENTIFIED BY '%secret%';\"", secret: get('db_password')); |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | }); |
| 49 | 49 | |
| 50 | 50 | desc('Provision MariaDB'); |
| 51 | -task('provision:mariadb', function () { |
|
| 51 | +task('provision:mariadb', function() { |
|
| 52 | 52 | run('apt-get install -y mariadb-server', env: ['DEBIAN_FRONTEND' => 'noninteractive'], timeout: 900); |
| 53 | 53 | run("mysql --user=\"root\" -e \"CREATE USER IF NOT EXISTS '{{db_user}}'@'0.0.0.0' IDENTIFIED BY '%secret%';\"", secret: get('db_password')); |
| 54 | 54 | run("mysql --user=\"root\" -e \"CREATE USER IF NOT EXISTS '{{db_user}}'@'%' IDENTIFIED BY '%secret%';\"", secret: get('db_password')); |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | }); |
| 60 | 60 | |
| 61 | 61 | desc('Provision PostgreSQL'); |
| 62 | -task('provision:postgresql', function () { |
|
| 62 | +task('provision:postgresql', function() { |
|
| 63 | 63 | run('apt-get install -y postgresql postgresql-contrib', env: ['DEBIAN_FRONTEND' => 'noninteractive'], timeout: 900); |
| 64 | 64 | run("sudo -u postgres psql <<< $'CREATE DATABASE {{db_name}};'"); |
| 65 | 65 | run("sudo -u postgres psql <<< $'CREATE USER {{db_user}} WITH ENCRYPTED PASSWORD \'%secret%\';'", secret: get('db_password')); |
@@ -4,16 +4,16 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | namespace Deployer; |
| 6 | 6 | |
| 7 | -set('domain', function () { |
|
| 7 | +set('domain', function() { |
|
| 8 | 8 | return ask(' Domain: ', get('hostname')); |
| 9 | 9 | }); |
| 10 | 10 | |
| 11 | -set('public_path', function () { |
|
| 11 | +set('public_path', function() { |
|
| 12 | 12 | return ask(' Public path: ', 'public'); |
| 13 | 13 | }); |
| 14 | 14 | |
| 15 | 15 | desc('Configures a server'); |
| 16 | -task('provision:server', function () { |
|
| 16 | +task('provision:server', function() { |
|
| 17 | 17 | set('remote_user', get('provision_user')); |
| 18 | 18 | run('usermod -a -G www-data caddy'); |
| 19 | 19 | run("mkdir -p /var/deployer"); |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | })->oncePerNode(); |
| 23 | 23 | |
| 24 | 24 | desc('Provision website'); |
| 25 | -task('provision:website', function () { |
|
| 25 | +task('provision:website', function() { |
|
| 26 | 26 | $restoreBecome = become('deployer'); |
| 27 | 27 | |
| 28 | 28 | run("[ -d {{deploy_path}} ] || mkdir -p {{deploy_path}}"); |
@@ -66,11 +66,11 @@ discard block |
||
| 66 | 66 | })->limit(1); |
| 67 | 67 | |
| 68 | 68 | desc('Shows access logs'); |
| 69 | -task('logs:access', function () { |
|
| 69 | +task('logs:access', function() { |
|
| 70 | 70 | run('tail -f {{deploy_path}}/log/access.log'); |
| 71 | 71 | })->verbose(); |
| 72 | 72 | |
| 73 | 73 | desc('Shows caddy syslog'); |
| 74 | -task('logs:caddy', function () { |
|
| 74 | +task('logs:caddy', function() { |
|
| 75 | 75 | run('sudo journalctl -u caddy -f'); |
| 76 | 76 | })->verbose(); |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | // Name of lsb_release like: focal, bionic, etc. |
| 18 | 18 | // As only Ubuntu 20.04 LTS is supported for provision should be the `focal`. |
| 19 | -set('lsb_release', function () { |
|
| 19 | +set('lsb_release', function() { |
|
| 20 | 20 | return run("lsb_release -s -c"); |
| 21 | 21 | }); |
| 22 | 22 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | set('provision_user', 'root'); |
| 44 | 44 | |
| 45 | 45 | desc('Checks pre-required state'); |
| 46 | -task('provision:check', function () { |
|
| 46 | +task('provision:check', function() { |
|
| 47 | 47 | set('remote_user', get('provision_user')); |
| 48 | 48 | |
| 49 | 49 | $release = run('cat /etc/os-release'); |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | })->oncePerNode(); |
| 69 | 69 | |
| 70 | 70 | desc('Collects required params'); |
| 71 | -task('provision:configure', function () { |
|
| 71 | +task('provision:configure', function() { |
|
| 72 | 72 | set('remote_user', get('provision_user')); |
| 73 | 73 | |
| 74 | 74 | $params = [ |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | |
| 122 | 122 | desc('Adds repositories and update'); |
| 123 | -task('provision:update', function () { |
|
| 123 | +task('provision:update', function() { |
|
| 124 | 124 | set('remote_user', get('provision_user')); |
| 125 | 125 | |
| 126 | 126 | // PHP |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | ->verbose(); |
| 138 | 138 | |
| 139 | 139 | desc('Upgrades all packages'); |
| 140 | -task('provision:upgrade', function () { |
|
| 140 | +task('provision:upgrade', function() { |
|
| 141 | 141 | set('remote_user', get('provision_user')); |
| 142 | 142 | run('apt-get upgrade -y', env: ['DEBIAN_FRONTEND' => 'noninteractive'], timeout: 900); |
| 143 | 143 | }) |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | ->verbose(); |
| 146 | 146 | |
| 147 | 147 | desc('Installs packages'); |
| 148 | -task('provision:install', function () { |
|
| 148 | +task('provision:install', function() { |
|
| 149 | 149 | set('remote_user', get('provision_user')); |
| 150 | 150 | $packages = [ |
| 151 | 151 | 'acl', |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | ->oncePerNode(); |
| 181 | 181 | |
| 182 | 182 | desc('Configures the ssh'); |
| 183 | -task('provision:ssh', function () { |
|
| 183 | +task('provision:ssh', function() { |
|
| 184 | 184 | set('remote_user', get('provision_user')); |
| 185 | 185 | run("sed -i 's/PasswordAuthentication .*/PasswordAuthentication no/' /etc/ssh/sshd_config"); |
| 186 | 186 | run('ssh-keygen -A'); |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | })->oncePerNode(); |
| 193 | 193 | |
| 194 | 194 | desc('Setups a firewall'); |
| 195 | -task('provision:firewall', function () { |
|
| 195 | +task('provision:firewall', function() { |
|
| 196 | 196 | set('remote_user', get('provision_user')); |
| 197 | 197 | run('ufw allow 22'); |
| 198 | 198 | run('ufw allow 80'); |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | })->oncePerNode(); |
| 202 | 202 | |
| 203 | 203 | desc('Verifies what provision was successful'); |
| 204 | -task('provision:verify', function () { |
|
| 204 | +task('provision:verify', function() { |
|
| 205 | 205 | fetch('{{domain}}', 'get', [], null, $info, true); |
| 206 | 206 | if ($info['http_code'] === 404) { |
| 207 | 207 | info("provisioned successfully!"); |
@@ -8,14 +8,14 @@ |
||
| 8 | 8 | 'VAR' => 'global', |
| 9 | 9 | ]); |
| 10 | 10 | |
| 11 | -task('test', function () { |
|
| 11 | +task('test', function() { |
|
| 12 | 12 | info('global=' . run('echo $VAR')); |
| 13 | 13 | info('local=' . run('echo $VAR', env: ['VAR' => 'local'])); |
| 14 | 14 | info('dotenv=' . run('echo $KEY')); |
| 15 | 15 | info('dotenv=' . run('echo $KEY', env: ['KEY' => 'local'])); |
| 16 | 16 | }); |
| 17 | 17 | |
| 18 | -before('test', function () { |
|
| 18 | +before('test', function() { |
|
| 19 | 19 | run('mkdir -p {{deploy_path}}'); |
| 20 | 20 | run('echo KEY="\'Hello, world!\'" > {{deploy_path}}/.env'); |
| 21 | 21 | set('dotenv', '{{deploy_path}}/.env'); |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * }); |
| 51 | 51 | * ``` |
| 52 | 52 | */ |
| 53 | -function host(string ...$hostname): Host|ObjectProxy |
|
| 53 | +function host(string ...$hostname): Host | ObjectProxy |
|
| 54 | 54 | { |
| 55 | 55 | $deployer = Deployer::get(); |
| 56 | 56 | if (count($hostname) === 1 && $deployer->hosts->has($hostname[0])) { |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $deployer->hosts->set($aliases[0], $host); |
| 71 | 71 | return $host; |
| 72 | 72 | } else { |
| 73 | - $hosts = array_map(function ($hostname) use ($deployer): Host { |
|
| 73 | + $hosts = array_map(function($hostname) use ($deployer): Host { |
|
| 74 | 74 | $host = new Host($hostname); |
| 75 | 75 | $deployer->hosts->set($hostname, $host); |
| 76 | 76 | return $host; |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * localhost('ci'); // Alias and hostname will be "ci". |
| 88 | 88 | * ``` |
| 89 | 89 | */ |
| 90 | -function localhost(string ...$hostnames): Localhost|ObjectProxy |
|
| 90 | +function localhost(string ...$hostnames): Localhost | ObjectProxy |
|
| 91 | 91 | { |
| 92 | 92 | $deployer = Deployer::get(); |
| 93 | 93 | $hostnames = Range::expand($hostnames); |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | $deployer->hosts->set($host->getAlias(), $host); |
| 98 | 98 | return $host; |
| 99 | 99 | } else { |
| 100 | - $hosts = array_map(function ($hostname) use ($deployer): Localhost { |
|
| 100 | + $hosts = array_map(function($hostname) use ($deployer): Localhost { |
|
| 101 | 101 | $host = new Localhost($hostname); |
| 102 | 102 | $deployer->hosts->set($host->getAlias(), $host); |
| 103 | 103 | return $host; |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | * @param callable|array|null $body Callable task, array of other tasks names or nothing to get a defined tasks |
| 184 | 184 | * @return Task |
| 185 | 185 | */ |
| 186 | -function task(string $name, callable|array|null $body = null): Task |
|
| 186 | +function task(string $name, callable | array | null $body = null): Task |
|
| 187 | 187 | { |
| 188 | 188 | $deployer = Deployer::get(); |
| 189 | 189 | |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | * |
| 236 | 236 | * @return ?Task |
| 237 | 237 | */ |
| 238 | -function before(string $task, string|callable $do): ?Task |
|
| 238 | +function before(string $task, string | callable $do): ?Task |
|
| 239 | 239 | { |
| 240 | 240 | if (is_closure($do)) { |
| 241 | 241 | $newTask = task("before:$task", $do); |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | * |
| 256 | 256 | * @return ?Task |
| 257 | 257 | */ |
| 258 | -function after(string $task, string|callable $do): ?Task |
|
| 258 | +function after(string $task, string | callable $do): ?Task |
|
| 259 | 259 | { |
| 260 | 260 | if (is_closure($do)) { |
| 261 | 261 | $newTask = task("after:$task", $do); |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | * |
| 277 | 277 | * @return ?Task |
| 278 | 278 | */ |
| 279 | -function fail(string $task, string|callable $do): ?Task |
|
| 279 | +function fail(string $task, string | callable $do): ?Task |
|
| 280 | 280 | { |
| 281 | 281 | if (is_callable($do)) { |
| 282 | 282 | $newTask = task("fail:$task", $do); |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | { |
| 338 | 338 | $currentBecome = get('become'); |
| 339 | 339 | set('become', $user); |
| 340 | - return function () use ($currentBecome) { |
|
| 340 | + return function() use ($currentBecome) { |
|
| 341 | 341 | set('become', $currentBecome); |
| 342 | 342 | }; |
| 343 | 343 | } |
@@ -400,14 +400,14 @@ discard block |
||
| 400 | 400 | ?int $idleTimeout = null, |
| 401 | 401 | ): string { |
| 402 | 402 | $runParams = new RunParams( |
| 403 | - shell: currentHost()->getShell(), |
|
| 404 | - cwd: $cwd ?? has('working_path') ? get('working_path') : null, |
|
| 405 | - env: array_merge_alternate(get('env', []), $env ?? []), |
|
| 406 | - nothrow: $nothrow, |
|
| 407 | - timeout: $timeout ?? get('default_timeout', 300), |
|
| 408 | - idleTimeout: $idleTimeout, |
|
| 409 | - forceOutput: $forceOutput, |
|
| 410 | - secrets: empty($secret) ? null : ['secret' => $secret], |
|
| 403 | + shell : currentHost()->getShell(), |
|
| 404 | + cwd : $cwd ?? has('working_path') ? get('working_path') : null, |
|
| 405 | + env : array_merge_alternate(get('env', []), $env ?? []), |
|
| 406 | + nothrow : $nothrow, |
|
| 407 | + timeout : $timeout ?? get('default_timeout', 300), |
|
| 408 | + idleTimeout : $idleTimeout, |
|
| 409 | + forceOutput : $forceOutput, |
|
| 410 | + secrets : empty($secret) ? null : ['secret' => $secret], |
|
| 411 | 411 | ); |
| 412 | 412 | |
| 413 | 413 | $dotenv = get('dotenv', false); |
@@ -415,7 +415,7 @@ discard block |
||
| 415 | 415 | $runParams->dotenv = $dotenv; |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | - $run = function (string $command, ?RunParams $params = null) use ($runParams): string { |
|
| 418 | + $run = function(string $command, ?RunParams $params = null) use ($runParams) : string { |
|
| 419 | 419 | $params = $params ?? $runParams; |
| 420 | 420 | $host = currentHost(); |
| 421 | 421 | $command = parse($command); |
@@ -490,14 +490,14 @@ discard block |
||
| 490 | 490 | ?string $shell = null, |
| 491 | 491 | ): string { |
| 492 | 492 | $runParams = new RunParams( |
| 493 | - shell: $shell ?? 'bash -s', |
|
| 494 | - cwd: $cwd, |
|
| 495 | - env: $env, |
|
| 496 | - nothrow: $nothrow, |
|
| 497 | - timeout: $timeout, |
|
| 498 | - idleTimeout: $idleTimeout, |
|
| 499 | - forceOutput: $forceOutput, |
|
| 500 | - secrets: empty($secret) ? null : ['secret' => $secret], |
|
| 493 | + shell : $shell ?? 'bash -s', |
|
| 494 | + cwd : $cwd, |
|
| 495 | + env : $env, |
|
| 496 | + nothrow : $nothrow, |
|
| 497 | + timeout : $timeout, |
|
| 498 | + idleTimeout : $idleTimeout, |
|
| 499 | + forceOutput : $forceOutput, |
|
| 500 | + secrets : empty($secret) ? null : ['secret' => $secret], |
|
| 501 | 501 | ); |
| 502 | 502 | |
| 503 | 503 | $process = Deployer::get()->processRunner; |
@@ -38,7 +38,7 @@ |
||
| 38 | 38 | $this->pop->command($host, 'run', $command); |
| 39 | 39 | |
| 40 | 40 | $terminalOutput = $this->pop->callback($host, $params->forceOutput); |
| 41 | - $callback = function ($type, $buffer) use ($host, $terminalOutput) { |
|
| 41 | + $callback = function($type, $buffer) use ($host, $terminalOutput) { |
|
| 42 | 42 | $this->logger->printBuffer($host, $type, $buffer); |
| 43 | 43 | $terminalOutput($type, $buffer); |
| 44 | 44 | }; |
@@ -78,7 +78,7 @@ |
||
| 78 | 78 | ->setTimeout($params->timeout) |
| 79 | 79 | ->setIdleTimeout($params->idleTimeout); |
| 80 | 80 | |
| 81 | - $callback = function ($type, $buffer) use ($params, $host) { |
|
| 81 | + $callback = function($type, $buffer) use ($params, $host) { |
|
| 82 | 82 | $this->logger->printBuffer($host, $type, $buffer); |
| 83 | 83 | $this->pop->callback($host, $params->forceOutput)($type, $buffer); |
| 84 | 84 | }; |