php-spark/plugins/com.noccy.docker/sparkplug.php

59 lines
1.8 KiB
PHP
Raw Normal View History

2021-12-08 23:58:28 +00:00
<?php // "name":"Docker plugin for SparkPlug", "author":"Noccy"
namespace SparkPlug\Com\Noccy\Docker;
use Spark\Commands\Command;
use SparkPlug;
use SparkPlug\Com\Noccy\Docker\DockerCompose\Stack;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class DockerPlug extends SparkPlug
{
private array $compose = [];
private Stack $composeStack;
public function load()
{
$config = read_config("docker.json");
$docker = $config['docker']??[];
$hasCompose = array_key_exists('compose', $docker);
$hasBuild = array_key_exists('build', $docker);
if ($hasCompose) {
$this->compose = $docker['compose'];
}
if ($hasCompose || $hasBuild) {
register_command(new Commands\DockerUpCommand);
register_command(new Commands\DockerDownCommand);
register_command(new Commands\DockerStatusCommand);
register_command(new Commands\DockerDbExportCommand);
2021-12-08 23:58:28 +00:00
}
if ($hasBuild) {
register_command(new Commands\DockerBuildCommand);
register_command(new Commands\DockerExecCommand);
2021-12-08 23:58:28 +00:00
}
register_command(new Commands\Stack\StatusCommand);
register_command(new Commands\Stack\RegisterCommand);
register_command(new Commands\Stack\UnregisterCommand);
2021-12-08 23:58:28 +00:00
}
public function getComposeStack(): ?Stack
{
$base = $this->getProjectDirectory();
if (empty($this->composeStack)) {
$composeFile = $base . "/" . ($this->compose['file']??'docker-compose.yml');
$this->composeStack = new Stack($composeFile);
}
return $this->composeStack;
}
}
//if (file_exists(get_environment()->getConfigDirectory()."/maker.json")) {
register_plugin("com.noccy.docker", new DockerPlug());
//}