diff --git a/ci/test/magento/deploy_brancher.php b/ci/test/magento/deploy_brancher.php index 4399a7d..5d9d3bd 100644 --- a/ci/test/magento/deploy_brancher.php +++ b/ci/test/magento/deploy_brancher.php @@ -19,6 +19,7 @@ $productionStage = $configuration->addStage('test', 'banaan.store'); $productionStage->addBrancherServer('hndeployintegr8') + ->setBrancherTimeout(3000) ->setLabels(['gitref='. (\getenv('GITHUB_SHA') ?: 'unknown')]); return $configuration; diff --git a/composer.json b/composer.json index 87c18cb..48bb58f 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/composer.lock b/composer.lock index 63e817f..17c2d5d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ac062b2d98f523024b86eb9b650ed881", + "content-hash": "060108911b9a3452b54a2d0704c7c549", "packages": [ { "name": "carbonphp/carbon-doctrine-types", @@ -917,16 +917,16 @@ }, { "name": "hypernode/deploy-configuration", - "version": "3.5.0", + "version": "3.6.0", "source": { "type": "git", "url": "https://github.com/ByteInternet/hypernode-deploy-configuration.git", - "reference": "c42b0e35237888b2a0afa2ed66a3e6ae49cdf3c9" + "reference": "7abbb530e95add7d64dd4312e12643f6fe7aeb0c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ByteInternet/hypernode-deploy-configuration/zipball/c42b0e35237888b2a0afa2ed66a3e6ae49cdf3c9", - "reference": "c42b0e35237888b2a0afa2ed66a3e6ae49cdf3c9", + "url": "https://api.github.com/repos/ByteInternet/hypernode-deploy-configuration/zipball/7abbb530e95add7d64dd4312e12643f6fe7aeb0c", + "reference": "7abbb530e95add7d64dd4312e12643f6fe7aeb0c", "shasum": "" }, "require": { @@ -954,9 +954,9 @@ "description": "Hypernode deploy configuration files", "support": { "issues": "https://github.com/ByteInternet/hypernode-deploy-configuration/issues", - "source": "https://github.com/ByteInternet/hypernode-deploy-configuration/tree/3.5.0" + "source": "https://github.com/ByteInternet/hypernode-deploy-configuration/tree/3.6.0" }, - "time": "2025-12-15T11:56:28+00:00" + "time": "2025-12-24T09:41:44+00:00" }, { "name": "justinrainbow/json-schema", @@ -7722,7 +7722,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -7732,6 +7732,6 @@ "ext-zlib": "*", "composer-runtime-api": "^2" }, - "platform-dev": [], - "plugin-api-version": "2.6.0" + "platform-dev": {}, + "plugin-api-version": "2.9.0" } diff --git a/src/Brancher/BrancherHypernodeManager.php b/src/Brancher/BrancherHypernodeManager.php index cb82ef2..9f96175 100644 --- a/src/Brancher/BrancherHypernodeManager.php +++ b/src/Brancher/BrancherHypernodeManager.php @@ -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; @@ -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; @@ -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) ); diff --git a/src/DeployRunner.php b/src/DeployRunner.php index 3688ae8..4bb2b15 100644 --- a/src/DeployRunner.php +++ b/src/DeployRunner.php @@ -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; @@ -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) { @@ -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)) {