Skip to content

Commit 0d97601

Browse files
committed
Add interface for specifying brancher labels and settings
1 parent c1d105a commit 0d97601

File tree

4 files changed

+58
-7
lines changed

4 files changed

+58
-7
lines changed

src/BrancherServer.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Hypernode\DeployConfiguration;
6+
7+
class BrancherServer extends Server
8+
{
9+
public function getLabels(): array
10+
{
11+
return $this->getOptions()[self::OPTION_HN_BRANCHER_LABELS] ?? [];
12+
}
13+
14+
/**
15+
* @param string[] $labels Labels to be applied to the brancher node
16+
* @return $this
17+
*/
18+
public function setLabels(array $labels): self
19+
{
20+
$this->setOption(self::OPTION_HN_BRANCHER_LABELS, $labels);
21+
return $this;
22+
}
23+
24+
public function getSettings(): array
25+
{
26+
return $this->getOptions()[self::OPTION_HN_BRANCHER_SETTINGS] ?? [];
27+
}
28+
29+
/**
30+
* @param array $settings Settings to be applied to the brancher node
31+
* @return $this
32+
*/
33+
public function setSettings(array $settings): self
34+
{
35+
$this->setOption(self::OPTION_HN_BRANCHER_SETTINGS, $settings);
36+
return $this;
37+
}
38+
}

src/Server.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
class Server
99
{
1010
public const OPTION_HN_BRANCHER = 'hn_brancher';
11+
public const OPTION_HN_BRANCHER_LABELS = 'hn_brancher_labels';
12+
public const OPTION_HN_BRANCHER_SETTINGS = 'hn_brancher_settings';
1113
public const OPTION_HN_PARENT_APP = 'hn_parent_app';
1214

1315
/**
@@ -62,9 +64,6 @@ public function getRoles(): array
6264
return $this->roles;
6365
}
6466

65-
/**
66-
* @return string[]
67-
*/
6867
public function getOptions(): array
6968
{
7069
return $this->options;
@@ -78,6 +77,16 @@ public function getSshOptions(): array
7877
return $this->sshOptions;
7978
}
8079

80+
/**
81+
* @param string $option
82+
* @param mixed $value
83+
* @return void
84+
*/
85+
protected function setOption(string $option, $value)
86+
{
87+
$this->options[$option] = $value;
88+
}
89+
8190
/**
8291
* @param $options
8392
*/

src/Stage.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,18 @@ public function addServer(
7575
* @param array|null $roles Roles for the server to be applied
7676
* @param array $options Extra host options for Deployer
7777
* @see ServerRole
78-
* @return Server
78+
* @return BrancherServer
7979
*/
80-
public function addBrancherServer(string $appName, array $roles = null, array $options = []): Server
80+
public function addBrancherServer(string $appName, array $roles = null, array $options = []): BrancherServer
8181
{
8282
$brancherOptions = [
8383
Server::OPTION_HN_BRANCHER => true,
8484
Server::OPTION_HN_PARENT_APP => $appName,
85+
Server::OPTION_HN_BRANCHER_LABELS => [],
86+
Server::OPTION_HN_BRANCHER_SETTINGS => [],
8587
];
8688
$options = array_merge($brancherOptions, $options);
87-
$server = new Server('', $roles, $options);
89+
$server = new BrancherServer('', $roles, $options);
8890
$this->servers[] = $server;
8991
return $server;
9092
}

templates/deploy.magento2.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
$productionStage->addServer('appname.hypernode.io');
1515

1616
$testStage = $configuration->addStage('test', 'example.com');
17-
$testStage->addBrancherServer('appname');
17+
$testStage->addBrancherServer('appname')
18+
->setLabels(['stage=test', 'ci_ref=' . \getenv('GITHUB_RUN_ID') ?: 'none'])
19+
->setSettings(['cron_enabled' => false, 'supervisor_enabled' => false]);
1820

1921
return $configuration;

0 commit comments

Comments
 (0)