* initial commit
This commit is contained in:
27
src/App/Service/Builder.php
Normal file
27
src/App/Service/Builder.php
Normal 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);
|
||||
}
|
||||
}
|
||||
15
src/App/Service/BuilderFactory.php
Normal file
15
src/App/Service/BuilderFactory.php
Normal 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();
|
||||
}
|
||||
}
|
||||
65
src/App/Service/ConfigProvider.php
Normal file
65
src/App/Service/ConfigProvider.php
Normal 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);
|
||||
}
|
||||
}
|
||||
25
src/App/Service/ConfigProviderFactory.php
Normal file
25
src/App/Service/ConfigProviderFactory.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user