Skip to content

Commit af858ac

Browse files
authored
Merge pull request #24 from ByteInternet/ephemeral_servers
Add ephemeral Hypernode server support
2 parents a15e8b5 + bbb6222 commit af858ac

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/Server.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
*/
88
class Server
99
{
10+
public const OPTION_HN_EPHEMERAL = 'hn_ephemeral';
11+
public const OPTION_HN_PARENT_APP = 'hn_parent_app';
12+
1013
/**
1114
* @var string
1215
*/
@@ -46,6 +49,11 @@ public function getHostname(): string
4649
return $this->hostname;
4750
}
4851

52+
public function setHostname(string $hostname): void
53+
{
54+
$this->hostname = $hostname;
55+
}
56+
4957
/**
5058
* @return string[]
5159
*/

src/Stage.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ public function getUsername(): string
4848
}
4949

5050
/**
51-
* @param string $hostname
52-
* @param array $roles
53-
* @param array $options Extra host options
54-
* @param array $sshOptions
51+
* @param string $hostname Hostname of the server
52+
* @param array|null $roles Roles for the server to be applied
53+
* @param array $options Extra host options
54+
* @param array $sshOptions
55+
* @see ServerRole
5556
* @return Server
5657
*/
5758
public function addServer(
@@ -66,6 +67,28 @@ public function addServer(
6667
return $server;
6768
}
6869

70+
/**
71+
* Create a temporary (ephemeral) Hypernode instance based on given Hypernode.
72+
* The hostname will be defined during the deployment.
73+
*
74+
* @param string $appName Name of the Hypernode to base the ephemeral server on
75+
* @param array|null $roles Roles for the server to be applied
76+
* @param array $options Extra host options for Deployer
77+
* @see ServerRole
78+
* @return Server
79+
*/
80+
public function addEphemeralServer(string $appName, array $roles = null, array $options = []): Server
81+
{
82+
$ephemeralOptions = [
83+
Server::OPTION_HN_EPHEMERAL => true,
84+
Server::OPTION_HN_PARENT_APP => $appName,
85+
];
86+
$options = array_merge($ephemeralOptions, $options);
87+
$server = new Server('', $roles, $options);
88+
$this->servers[] = $server;
89+
return $server;
90+
}
91+
6992
/**
7093
* @return Server[]
7194
*/

0 commit comments

Comments
 (0)