55 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?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 DockerUpCommand);
 | 
						|
            register_command(new DockerDownCommand);
 | 
						|
            register_command(new DockerStatusCommand);
 | 
						|
        }
 | 
						|
        if ($hasBuild) {
 | 
						|
            register_command(new DockerBuildCommand);
 | 
						|
            register_command(new DockerExecCommand);
 | 
						|
        }
 | 
						|
        register_command(new DockerDbExportCommand);
 | 
						|
    }
 | 
						|
 | 
						|
    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());
 | 
						|
//}
 |