From de45e75c23760ca6d55a6fe9dfe3be16e110226e Mon Sep 17 00:00:00 2001 From: Timon de Groot Date: Tue, 22 Nov 2022 13:18:48 +0100 Subject: [PATCH] Add interface for specifying brancher labels and settings --- src/BrancherServer.php | 38 +++++++++++++++++++++++++++++++++++ src/Server.php | 21 +++++++++++-------- src/Stage.php | 8 +++++--- templates/deploy.magento2.php | 4 +++- 4 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 src/BrancherServer.php diff --git a/src/BrancherServer.php b/src/BrancherServer.php new file mode 100644 index 0000000..87171a8 --- /dev/null +++ b/src/BrancherServer.php @@ -0,0 +1,38 @@ +getOptions()[self::OPTION_HN_BRANCHER_LABELS] ?? []; + } + + /** + * @param string[] $labels Labels to be applied to the brancher node + * @return $this + */ + public function setLabels(array $labels): self + { + $this->setOption(self::OPTION_HN_BRANCHER_LABELS, $labels); + return $this; + } + + public function getSettings(): array + { + return $this->getOptions()[self::OPTION_HN_BRANCHER_SETTINGS] ?? []; + } + + /** + * @param array $settings Settings to be applied to the brancher node + * @return $this + */ + public function setSettings(array $settings): self + { + $this->setOption(self::OPTION_HN_BRANCHER_SETTINGS, $settings); + return $this; + } +} diff --git a/src/Server.php b/src/Server.php index 69c4547..c7329bc 100644 --- a/src/Server.php +++ b/src/Server.php @@ -8,6 +8,8 @@ class Server { public const OPTION_HN_BRANCHER = 'hn_brancher'; + public const OPTION_HN_BRANCHER_LABELS = 'hn_brancher_labels'; + public const OPTION_HN_BRANCHER_SETTINGS = 'hn_brancher_settings'; public const OPTION_HN_PARENT_APP = 'hn_parent_app'; /** @@ -20,10 +22,7 @@ class Server */ private $roles; - /** - * @var string[] - */ - private $options = []; + private array $options; /** * @var string[] @@ -32,7 +31,6 @@ class Server /** * @param string[] $roles - * @param string[] $options */ public function __construct(string $hostname, array $roles = null, array $options = []) { @@ -62,9 +60,6 @@ public function getRoles(): array return $this->roles; } - /** - * @return string[] - */ public function getOptions(): array { return $this->options; @@ -78,6 +73,16 @@ public function getSshOptions(): array return $this->sshOptions; } + /** + * @param string $option + * @param mixed $value + * @return void + */ + protected function setOption(string $option, $value) + { + $this->options[$option] = $value; + } + /** * @param $options */ diff --git a/src/Stage.php b/src/Stage.php index 81f46cc..79bf1d3 100644 --- a/src/Stage.php +++ b/src/Stage.php @@ -75,16 +75,18 @@ public function addServer( * @param array|null $roles Roles for the server to be applied * @param array $options Extra host options for Deployer * @see ServerRole - * @return Server + * @return BrancherServer */ - public function addBrancherServer(string $appName, array $roles = null, array $options = []): Server + public function addBrancherServer(string $appName, array $roles = null, array $options = []): BrancherServer { $brancherOptions = [ Server::OPTION_HN_BRANCHER => true, Server::OPTION_HN_PARENT_APP => $appName, + Server::OPTION_HN_BRANCHER_LABELS => [], + Server::OPTION_HN_BRANCHER_SETTINGS => [], ]; $options = array_merge($brancherOptions, $options); - $server = new Server('', $roles, $options); + $server = new BrancherServer('', $roles, $options); $this->servers[] = $server; return $server; } diff --git a/templates/deploy.magento2.php b/templates/deploy.magento2.php index 887733e..0d02dca 100644 --- a/templates/deploy.magento2.php +++ b/templates/deploy.magento2.php @@ -14,6 +14,8 @@ $productionStage->addServer('appname.hypernode.io'); $testStage = $configuration->addStage('test', 'example.com'); -$testStage->addBrancherServer('appname'); +$testStage->addBrancherServer('appname') + ->setLabels(['stage=test', 'ci_ref=' . \getenv('GITHUB_RUN_ID') ?: 'none']) + ->setSettings(['cron_enabled' => false, 'supervisor_enabled' => false]); return $configuration;