Skip to content

Commit

Permalink
Merge pull request #31 from ByteInternet/brancher_labels_and_settings
Browse files Browse the repository at this point in the history
  • Loading branch information
tdgroot authored Nov 23, 2022
2 parents c1d105a + de45e75 commit 400b3b3
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 12 deletions.
38 changes: 38 additions & 0 deletions src/BrancherServer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Hypernode\DeployConfiguration;

class BrancherServer extends Server
{
public function getLabels(): array
{
return $this->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;
}
}
21 changes: 13 additions & 8 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -20,10 +22,7 @@ class Server
*/
private $roles;

/**
* @var string[]
*/
private $options = [];
private array $options;

/**
* @var string[]
Expand All @@ -32,7 +31,6 @@ class Server

/**
* @param string[] $roles
* @param string[] $options
*/
public function __construct(string $hostname, array $roles = null, array $options = [])
{
Expand Down Expand Up @@ -62,9 +60,6 @@ public function getRoles(): array
return $this->roles;
}

/**
* @return string[]
*/
public function getOptions(): array
{
return $this->options;
Expand All @@ -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
*/
Expand Down
8 changes: 5 additions & 3 deletions src/Stage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion templates/deploy.magento2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 400b3b3

Please sign in to comment.