* initial commit

This commit is contained in:
David Danyi
2019-10-29 21:45:28 +01:00
commit 2cf81c493e
35 changed files with 3616 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace App\Service;
use App\Runner\SSH;
use Exception;
class Builder
{
const PACKAGE_BUILDER_SCRIPT = "prepare_package.sh";
/**
* @param $host
* @param $path
* @return string Generated filename on remote host
* @throws Exception
*/
public function buildRemotePackage($host, $path): string
{
$runner = new SSH($host);
$out = $runner->execute(sprintf("%s/%s", $path, self::PACKAGE_BUILDER_SCRIPT));
$lines = explode("\n", trim($out));
return array_pop($lines);
}
}

View File

@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace App\Service;
use Interop\Container\ContainerInterface;
class BuilderFactory
{
public function __invoke(ContainerInterface $container): Builder
{
return new Builder();
}
}

View File

@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace App\Service;
use InvalidArgumentException;
use Symfony\Component\Yaml\Yaml;
class ConfigProvider
{
const CONFIG_DIR = "automatique";
private $taskFile = "automatique.task.yaml";
private $envFile = "automatique.env.yaml";
private $loadOrder = [];
public function __construct(?string $taskOverride, ?string $envOverride)
{
if ($taskOverride) {
$this->taskFile = $taskOverride;
}
if ($envOverride) {
$this->envFile = $envOverride;
}
$this->loadOrder[] = ".";
$userCfgDir = sprintf("%s/.config/%s", $_SERVER['HOME'], self::CONFIG_DIR);
if (file_exists($userCfgDir)) {
$this->loadOrder[] = $userCfgDir;
}
$globalCfgDir = sprintf("/etc/%s", self::CONFIG_DIR);
if (file_exists($globalCfgDir)) {
$this->loadOrder[] = $globalCfgDir;
}
}
private function findConfigFile($filename): string
{
foreach ($this->loadOrder as $loadDir) {
$configFile = "${loadDir}/${filename}";
if (file_exists($configFile)) {
return $configFile;
}
}
throw new InvalidArgumentException("Couldn't locate $filename");
}
private function readConfigFile($configFile): ?iterable
{
$configFile = $this->findConfigFile($configFile);
return Yaml::parseFile($configFile);
}
public function getEnvironmentConfig(): ?iterable
{
return $this->readConfigFile($this->envFile);
}
public function getTaskConfig(): ?iterable
{
return $this->readConfigFile($this->taskFile);
}
}

View File

@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace App\Service;
use Interop\Container\ContainerInterface;
use Symfony\Component\Console\Input\ArgvInput;
class ConfigProviderFactory
{
public function __invoke(ContainerInterface $container): ConfigProvider
{
$taskFile = null;
$envFile = null;
$args = new ArgvInput();
if ($args->hasOption("env-file")) {
$envFile = $args->getOption("env-file");
}
if ($args->hasOption("task-file")) {
$taskFile = $args->getOption("task-file");
}
return new ConfigProvider($taskFile, $envFile);
}
}