Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/test/magento/deploy_brancher.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

$productionStage = $configuration->addStage('test', 'banaan.store');
$productionStage->addBrancherServer('hndeployintegr8')
->setBrancherTimeout(3000)
->setLabels(['gitref='. (\getenv('GITHUB_SHA') ?: 'unknown')]);

return $configuration;
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"doctrine/annotations": "^1.6",
"guzzlehttp/guzzle": "^7.5",
"hypernode/api-client": "^0.5",
"hypernode/deploy-configuration": "^3.5",
"hypernode/deploy-configuration": "^3.6",
"php-di/php-di": "^7.0",
"psr/log": "^1.0",
"symfony/console": "^5.4",
Expand Down
20 changes: 10 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 37 additions & 6 deletions src/Brancher/BrancherHypernodeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,20 @@ public function createForHypernode(string $hypernode, array $data = []): string
*
* @param string $brancherHypernode Name of the brancher Hypernode
* @param int $timeout Maximum time to wait for availability
* @param int $reachabilityCheckCount Number of consecutive successful checks required
* @param int $reachabilityCheckInterval Seconds between reachability checks
* @return void
* @throws CreateBrancherHypernodeFailedException
* @throws HypernodeApiClientException
* @throws HypernodeApiServerException
* @throws TimeoutException
*/
public function waitForAvailability(string $brancherHypernode, int $timeout = 1500): void
{
public function waitForAvailability(
string $brancherHypernode,
int $timeout = 1500,
int $reachabilityCheckCount = 6,
int $reachabilityCheckInterval = 10
): void {
$latest = microtime(true);
$timeElapsed = 0;
$resolved = false;
Expand Down Expand Up @@ -175,7 +181,7 @@ public function waitForAvailability(string $brancherHypernode, int $timeout = 15
);
}

$resolved = false;
$consecutiveSuccesses = 0;
while ($timeElapsed < $timeout) {
$now = microtime(true);
$timeElapsed += $now - $latest;
Expand All @@ -184,12 +190,37 @@ public function waitForAvailability(string $brancherHypernode, int $timeout = 15
$connection = @fsockopen(sprintf("%s.hypernode.io", $brancherHypernode), 22);
if ($connection) {
fclose($connection);
$resolved = true;
break;
$consecutiveSuccesses++;
$this->log->info(
sprintf(
'Brancher Hypernode %s reachability check %d/%d succeeded.',
$brancherHypernode,
$consecutiveSuccesses,
$reachabilityCheckCount
)
);

if ($consecutiveSuccesses >= $reachabilityCheckCount) {
break;
}
sleep($reachabilityCheckInterval);
} else {
if ($consecutiveSuccesses > 0) {
$this->log->info(
sprintf(
'Brancher Hypernode %s reachability check failed, resetting counter (was at %d/%d).',
$brancherHypernode,
$consecutiveSuccesses,
$reachabilityCheckCount
)
);
}
$consecutiveSuccesses = 0;
sleep($reachabilityCheckInterval);
}
}

if (!$resolved) {
if ($consecutiveSuccesses < $reachabilityCheckCount) {
throw new TimeoutException(
sprintf('Timed out waiting for brancher Hypernode %s to become reachable', $brancherHypernode)
);
Expand Down
14 changes: 13 additions & 1 deletion src/DeployRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class DeployRunner
public const TASK_BUILD = 'build';
public const TASK_DEPLOY = 'deploy';

public const DEFAULT_BRANCHER_TIMEOUT = 1500;
public const DEFAULT_BRANCHER_REACHABILITY_CHECK_COUNT = 6;
public const DEFAULT_BRANCHER_REACHABILITY_CHECK_INTERVAL = 10;

private TaskFactory $taskFactory;
private InputInterface $input;
private LoggerInterface $log;
Expand Down Expand Up @@ -274,6 +278,9 @@ private function maybeConfigureBrancherServer(Server $server, bool $reuseBranche
if ($isBrancher && $parentApp) {
$settings = $serverOptions[Server::OPTION_HN_BRANCHER_SETTINGS] ?? [];
$labels = $serverOptions[Server::OPTION_HN_BRANCHER_LABELS] ?? [];
$timeout = $serverOptions[Server::OPTION_HN_BRANCHER_TIMEOUT] ?? self::DEFAULT_BRANCHER_TIMEOUT;
$reachabilityCheckCount = $serverOptions[Server::OPTION_HN_BRANCHER_REACHABILITY_CHECK_COUNT] ?? self::DEFAULT_BRANCHER_REACHABILITY_CHECK_COUNT;
$reachabilityCheckInterval = $serverOptions[Server::OPTION_HN_BRANCHER_REACHABILITY_CHECK_INTERVAL] ?? self::DEFAULT_BRANCHER_REACHABILITY_CHECK_INTERVAL;

$this->log->info(sprintf('Creating an brancher Hypernode based on %s.', $parentApp));
if ($settings) {
Expand All @@ -299,7 +306,12 @@ private function maybeConfigureBrancherServer(Server $server, bool $reuseBranche

try {
$this->log->info('Waiting for brancher Hypernode to become available...');
$this->brancherHypernodeManager->waitForAvailability($brancherApp);
$this->brancherHypernodeManager->waitForAvailability(
$brancherApp,
$timeout,
$reachabilityCheckCount,
$reachabilityCheckInterval
);
$this->log->info('Brancher Hypernode has become available!');
} catch (CreateBrancherHypernodeFailedException | TimeoutException $e) {
if (in_array($brancherApp, $this->brancherHypernodesRegistered)) {
Expand Down
Loading