@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | |
26 | 26 | $currentBuild = $environment->CurrentBuild(); |
27 | 27 | $currentSha = $currentBuild ? $currentBuild->SHA : '-'; |
28 | - if($currentSha !== $options['sha']) { |
|
28 | + if ($currentSha !== $options['sha']) { |
|
29 | 29 | $strategy->setChange('Code version', $currentSha, $options['sha']); |
30 | 30 | } |
31 | 31 | $strategy->setActionTitle('Confirm deployment'); |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | |
67 | 67 | // Use a package generator if specified, otherwise run a direct deploy, which is the default behaviour |
68 | 68 | // if build_filename isn't specified |
69 | - if($this->packageGenerator) { |
|
69 | + if ($this->packageGenerator) { |
|
70 | 70 | $log->write(sprintf('Using package generator "%s"', get_class($this->packageGenerator))); |
71 | 71 | |
72 | 72 | try { |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | throw $e; |
77 | 77 | } |
78 | 78 | |
79 | - if(empty($args['build_filename'])) { |
|
79 | + if (empty($args['build_filename'])) { |
|
80 | 80 | throw new RuntimeException('Failed to generate package.'); |
81 | 81 | } |
82 | 82 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | $cleanup->run(function($type, $buffer) use($log) { |
120 | 120 | $log->write($buffer); |
121 | 121 | }); |
122 | - if(!$cleanup->isSuccessful()) { |
|
122 | + if (!$cleanup->isSuccessful()) { |
|
123 | 123 | $this->extend('cleanupFailure', $environment, $sha, $log, $project); |
124 | 124 | $log->write('Warning: Cleanup failed, but fine to continue. Needs manual cleanup sometime.'); |
125 | 125 | } |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | $command->run(function($type, $buffer) use($log) { |
195 | 195 | $log->write($buffer); |
196 | 196 | }); |
197 | - if(!$command->isSuccessful()) { |
|
197 | + if (!$command->isSuccessful()) { |
|
198 | 198 | $this->extend('maintenanceEnableFailure', $environment, $log); |
199 | 199 | throw new RuntimeException($command->getErrorOutput()); |
200 | 200 | } |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | $command->run(function($type, $buffer) use($log) { |
211 | 211 | $log->write($buffer); |
212 | 212 | }); |
213 | - if(!$command->isSuccessful()) { |
|
213 | + if (!$command->isSuccessful()) { |
|
214 | 214 | $this->extend('maintenanceDisableFailure', $environment, $log); |
215 | 215 | throw new RuntimeException($command->getErrorOutput()); |
216 | 216 | } |
@@ -232,25 +232,25 @@ discard block |
||
232 | 232 | * @inheritdoc |
233 | 233 | */ |
234 | 234 | public function dataTransfer(\DNDataTransfer $dataTransfer, \DeploynautLogFile $log) { |
235 | - if($dataTransfer->Direction == 'get') { |
|
235 | + if ($dataTransfer->Direction == 'get') { |
|
236 | 236 | $this->dataTransferBackup($dataTransfer, $log); |
237 | 237 | } else { |
238 | 238 | $environment = $dataTransfer->Environment(); |
239 | 239 | $project = $environment->Project(); |
240 | - $workingDir = TEMP_FOLDER . DIRECTORY_SEPARATOR . 'deploynaut-transfer-' . $dataTransfer->ID; |
|
240 | + $workingDir = TEMP_FOLDER.DIRECTORY_SEPARATOR.'deploynaut-transfer-'.$dataTransfer->ID; |
|
241 | 241 | $archive = $dataTransfer->DataArchive(); |
242 | 242 | |
243 | 243 | // extract the sspak contents, we'll need these so capistrano can restore that content |
244 | 244 | try { |
245 | 245 | $archive->extractArchive($workingDir); |
246 | - } catch(Exception $e) { |
|
246 | + } catch (Exception $e) { |
|
247 | 247 | $log->write($e->getMessage()); |
248 | 248 | throw new RuntimeException($e->getMessage()); |
249 | 249 | } |
250 | 250 | |
251 | 251 | // validate the contents match the requested transfer mode |
252 | 252 | $result = $archive->validateArchiveContents($dataTransfer->Mode); |
253 | - if(!$result->valid()) { |
|
253 | + if (!$result->valid()) { |
|
254 | 254 | // do some cleaning, get rid of the extracted archive lying around |
255 | 255 | $process = new AbortableProcess(sprintf('rm -rf %s', escapeshellarg($workingDir))); |
256 | 256 | $process->setTimeout(120); |
@@ -280,41 +280,41 @@ discard block |
||
280 | 280 | $name = $environment->getFullName(); |
281 | 281 | $env = $environment->Project()->getProcessEnv(); |
282 | 282 | |
283 | - if(!$args) { |
|
283 | + if (!$args) { |
|
284 | 284 | $args = array(); |
285 | 285 | } |
286 | - $args['history_path'] = realpath(DEPLOYNAUT_LOG_PATH . '/'); |
|
286 | + $args['history_path'] = realpath(DEPLOYNAUT_LOG_PATH.'/'); |
|
287 | 287 | $args['environment_id'] = $environment->ID; |
288 | 288 | |
289 | 289 | // Inject env string directly into the command. |
290 | 290 | // Capistrano doesn't like the $process->setEnv($env) we'd normally do below. |
291 | 291 | $envString = ''; |
292 | - if(!empty($env)) { |
|
292 | + if (!empty($env)) { |
|
293 | 293 | $envString .= 'env '; |
294 | - foreach($env as $key => $value) { |
|
294 | + foreach ($env as $key => $value) { |
|
295 | 295 | $envString .= "$key=\"$value\" "; |
296 | 296 | } |
297 | 297 | } |
298 | 298 | |
299 | 299 | $data = DNData::inst(); |
300 | 300 | // Generate a capfile from a template |
301 | - $capTemplate = file_get_contents(BASE_PATH . '/deploynaut/Capfile.template'); |
|
301 | + $capTemplate = file_get_contents(BASE_PATH.'/deploynaut/Capfile.template'); |
|
302 | 302 | $cap = str_replace( |
303 | 303 | array('<config root>', '<ssh key>', '<base path>'), |
304 | 304 | array($data->getEnvironmentDir(), DEPLOYNAUT_SSH_KEY, BASE_PATH), |
305 | 305 | $capTemplate |
306 | 306 | ); |
307 | 307 | |
308 | - if(defined('DEPLOYNAUT_CAPFILE')) { |
|
308 | + if (defined('DEPLOYNAUT_CAPFILE')) { |
|
309 | 309 | $capFile = DEPLOYNAUT_CAPFILE; |
310 | 310 | } else { |
311 | - $capFile = ASSETS_PATH . '/Capfile'; |
|
311 | + $capFile = ASSETS_PATH.'/Capfile'; |
|
312 | 312 | } |
313 | 313 | file_put_contents($capFile, $cap); |
314 | 314 | |
315 | - $command = "{$envString}cap -f " . escapeshellarg($capFile) . " -vv $name $action ROLES=$roles"; |
|
316 | - foreach($args as $argName => $argVal) { |
|
317 | - $command .= ' -s ' . escapeshellarg($argName) . '=' . escapeshellarg($argVal); |
|
315 | + $command = "{$envString}cap -f ".escapeshellarg($capFile)." -vv $name $action ROLES=$roles"; |
|
316 | + foreach ($args as $argName => $argVal) { |
|
317 | + $command .= ' -s '.escapeshellarg($argName).'='.escapeshellarg($argVal); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | $log->write(sprintf('Running command: %s', $command)); |
@@ -348,16 +348,16 @@ discard block |
||
348 | 348 | $filepathBase = $dataArchive->generateFilepath($dataTransfer); |
349 | 349 | mkdir($filepathBase, 0700, true); |
350 | 350 | |
351 | - $databasePath = $filepathBase . DIRECTORY_SEPARATOR . 'database.sql.gz'; |
|
351 | + $databasePath = $filepathBase.DIRECTORY_SEPARATOR.'database.sql.gz'; |
|
352 | 352 | |
353 | 353 | // Backup database |
354 | - if(in_array($dataTransfer->Mode, array('all', 'db'))) { |
|
354 | + if (in_array($dataTransfer->Mode, array('all', 'db'))) { |
|
355 | 355 | $log->write(sprintf('Backup of database from "%s" started', $name)); |
356 | 356 | $command = $this->getCommand('data:getdb', 'db', $environment, array('data_path' => $databasePath), $log); |
357 | 357 | $command->run(function($type, $buffer) use($log) { |
358 | 358 | $log->write($buffer); |
359 | 359 | }); |
360 | - if(!$command->isSuccessful()) { |
|
360 | + if (!$command->isSuccessful()) { |
|
361 | 361 | $this->extend('dataTransferFailure', $environment, $log); |
362 | 362 | throw new RuntimeException($command->getErrorOutput()); |
363 | 363 | } |
@@ -365,13 +365,13 @@ discard block |
||
365 | 365 | } |
366 | 366 | |
367 | 367 | // Backup assets |
368 | - if(in_array($dataTransfer->Mode, array('all', 'assets'))) { |
|
368 | + if (in_array($dataTransfer->Mode, array('all', 'assets'))) { |
|
369 | 369 | $log->write(sprintf('Backup of assets from "%s" started', $name)); |
370 | 370 | $command = $this->getCommand('data:getassets', 'web', $environment, array('data_path' => $filepathBase), $log); |
371 | 371 | $command->run(function($type, $buffer) use($log) { |
372 | 372 | $log->write($buffer); |
373 | 373 | }); |
374 | - if(!$command->isSuccessful()) { |
|
374 | + if (!$command->isSuccessful()) { |
|
375 | 375 | $this->extend('dataTransferFailure', $environment, $log); |
376 | 376 | throw new RuntimeException($command->getErrorOutput()); |
377 | 377 | } |
@@ -386,12 +386,12 @@ discard block |
||
386 | 386 | $log->write('Creating sspak...'); |
387 | 387 | |
388 | 388 | $sspakFilename = sprintf('%s.sspak', $dataArchive->generateFilename($dataTransfer)); |
389 | - $sspakFilepath = $filepathBase . DIRECTORY_SEPARATOR . $sspakFilename; |
|
389 | + $sspakFilepath = $filepathBase.DIRECTORY_SEPARATOR.$sspakFilename; |
|
390 | 390 | |
391 | 391 | try { |
392 | 392 | $dataArchive->attachFile($sspakFilepath, $dataTransfer); |
393 | 393 | $dataArchive->setArchiveFromFiles($filepathBase); |
394 | - } catch(Exception $e) { |
|
394 | + } catch (Exception $e) { |
|
395 | 395 | $log->write($e->getMessage()); |
396 | 396 | throw new RuntimeException($e->getMessage()); |
397 | 397 | } |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | $process = new AbortableProcess(sprintf('rm -rf %s/assets && rm -f %s', escapeshellarg($filepathBase), escapeshellarg($databasePath))); |
403 | 403 | $process->setTimeout(120); |
404 | 404 | $process->run(); |
405 | - if(!$process->isSuccessful()) { |
|
405 | + if (!$process->isSuccessful()) { |
|
406 | 406 | $log->write('Could not delete temporary files'); |
407 | 407 | throw new RuntimeException($process->getErrorOutput()); |
408 | 408 | } |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | $command->run(function($type, $buffer) use($log) { |
422 | 422 | $log->write($buffer); |
423 | 423 | }); |
424 | - if(!$command->isSuccessful()) { |
|
424 | + if (!$command->isSuccessful()) { |
|
425 | 425 | $log->write(sprintf('Rebuild of "%s" failed: %s', $name, $command->getErrorOutput())); |
426 | 426 | throw new RuntimeException($command->getErrorOutput()); |
427 | 427 | } |
@@ -451,14 +451,14 @@ discard block |
||
451 | 451 | }; |
452 | 452 | |
453 | 453 | // Restore database into target environment |
454 | - if(in_array($dataTransfer->Mode, array('all', 'db'))) { |
|
454 | + if (in_array($dataTransfer->Mode, array('all', 'db'))) { |
|
455 | 455 | $log->write(sprintf('Restore of database to "%s" started', $name)); |
456 | - $args = array('data_path' => $workingDir . DIRECTORY_SEPARATOR . 'database.sql'); |
|
456 | + $args = array('data_path' => $workingDir.DIRECTORY_SEPARATOR.'database.sql'); |
|
457 | 457 | $command = $this->getCommand('data:pushdb', 'db', $environment, $args, $log); |
458 | 458 | $command->run(function($type, $buffer) use($log) { |
459 | 459 | $log->write($buffer); |
460 | 460 | }); |
461 | - if(!$command->isSuccessful()) { |
|
461 | + if (!$command->isSuccessful()) { |
|
462 | 462 | $cleanupFn(); |
463 | 463 | $log->write(sprintf('Restore of database to "%s" failed: %s', $name, $command->getErrorOutput())); |
464 | 464 | $this->extend('dataTransferFailure', $environment, $log); |
@@ -468,14 +468,14 @@ discard block |
||
468 | 468 | } |
469 | 469 | |
470 | 470 | // Restore assets into target environment |
471 | - if(in_array($dataTransfer->Mode, array('all', 'assets'))) { |
|
471 | + if (in_array($dataTransfer->Mode, array('all', 'assets'))) { |
|
472 | 472 | $log->write(sprintf('Restore of assets to "%s" started', $name)); |
473 | - $args = array('data_path' => $workingDir . DIRECTORY_SEPARATOR . 'assets'); |
|
473 | + $args = array('data_path' => $workingDir.DIRECTORY_SEPARATOR.'assets'); |
|
474 | 474 | $command = $this->getCommand('data:pushassets', 'web', $environment, $args, $log); |
475 | 475 | $command->run(function($type, $buffer) use($log) { |
476 | 476 | $log->write($buffer); |
477 | 477 | }); |
478 | - if(!$command->isSuccessful()) { |
|
478 | + if (!$command->isSuccessful()) { |
|
479 | 479 | $cleanupFn(); |
480 | 480 | $log->write(sprintf('Restore of assets to "%s" failed: %s', $name, $command->getErrorOutput())); |
481 | 481 | $this->extend('dataTransferFailure', $environment, $log); |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | $timeout = 600; |
501 | 501 | $tick = 60; |
502 | 502 | |
503 | - if(!$url) { |
|
503 | + if (!$url) { |
|
504 | 504 | $log->write('Skipping site accessible check: no URL found.'); |
505 | 505 | return true; |
506 | 506 | } |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | // query the site every second. Note that if the URL doesn't respond, |
532 | 532 | // curl_exec will take 5 seconds to timeout (see CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT above) |
533 | 533 | do { |
534 | - if(time() > $start + $timeout) { |
|
534 | + if (time() > $start + $timeout) { |
|
535 | 535 | $log->write(sprintf(' * Failed: check for %s timed out after %smin', $url, $timeout / 60)); |
536 | 536 | return false; |
537 | 537 | } |
@@ -540,13 +540,13 @@ discard block |
||
540 | 540 | |
541 | 541 | // check the HTTP response code for HTTP protocols |
542 | 542 | $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
543 | - if($status && !in_array($status, [500, 501, 502, 503, 504])) { |
|
543 | + if ($status && !in_array($status, [500, 501, 502, 503, 504])) { |
|
544 | 544 | $success = true; |
545 | 545 | } |
546 | 546 | |
547 | 547 | // check for any curl errors, mostly for checking the response state of non-HTTP protocols, |
548 | 548 | // but applies to checks of any protocol |
549 | - if($response && !curl_errno($ch)) { |
|
549 | + if ($response && !curl_errno($ch)) { |
|
550 | 550 | $success = true; |
551 | 551 | } |
552 | 552 | |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | } |
575 | 575 | |
576 | 576 | sleep(1); |
577 | - } while(!$success); |
|
577 | + } while (!$success); |
|
578 | 578 | |
579 | 579 | curl_close($ch); |
580 | 580 | $log->write(' * Success: site is accessible!'); |