Added default ports

This commit is contained in:
Eldad Fux
2020-07-31 15:50:39 +03:00
parent e5d26d74eb
commit 40b7a1de7f
4 changed files with 27 additions and 6 deletions
+2 -2
View File
@@ -129,12 +129,12 @@ $cli
->setParam('vars', $input)
;
if(!file_put_contents($path.'/docker-compose.yml.xx', $templateForCompose->render(false))) {
if(!file_put_contents($path.'/docker-compose.yml', $templateForCompose->render(false))) {
Console::error('Failed to save Docker Compose file');
exit(1);
}
if(!file_put_contents($path.'/.env.xx', $templateForEnv->render(false))) {
if(!file_put_contents($path.'/.env', $templateForEnv->render(false))) {
Console::error('Failed to save environment variables file');
exit(1);
}
+22 -2
View File
@@ -17,7 +17,19 @@ class Service
public function __construct(array $service)
{
$this->service = $service;
$this->service['environment'] = isset($this->service['environment']) ? new Env(implode("\n", $this->service['environment'])) : new Env('');
$ports = (isset($this->service['ports']) && is_array($this->service['ports'])) ? $this->service['ports'] : [];
$this->service['ports'] = [];
array_walk($ports, function(&$value, &$key) {
$split = explode(':', $value);
$this->service['ports'][
(isset($split[0])) ? $split[0] : ''
] = (isset($split[1])) ? $split[1] : '';
});
$this->service['environment'] = (isset($this->service['environment']) && is_array($this->service['environment'])) ? $this->service['environment'] : [];
$this->service['environment'] = new Env(implode("\n", $this->service['environment']));
}
/**
@@ -46,10 +58,18 @@ class Service
}
/**
* @return string
* @return Env
*/
public function getEnvironment(): Env
{
return $this->service['environment'];
}
/**
* @return array
*/
public function getPorts(): array
{
return $this->service['ports'];
}
}
+2 -2
View File
@@ -15,8 +15,8 @@ services:
- --accesslog=true
restart: unless-stopped
ports:
- 80:80
- 443:443
- 2080:80
- 2443:443
- 8080:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock
+1
View File
@@ -41,6 +41,7 @@ class ComposeTest extends TestCase
$this->assertEquals('appwrite', $this->object->getService('appwrite')->getContainerName());
$this->assertEquals('', $this->object->getService('appwrite')->getImageVersion());
$this->assertEquals('2.2', $this->object->getService('traefik')->getImageVersion());
$this->assertEquals(['2080' => '80', '2443' => '443', '8080' => '8080'], $this->object->getService('traefik')->getPorts());
}
public function testNetworks()