Compare commits
2 Commits
ee1b9bafc7
...
0091f0fd08
| Author | SHA1 | Date | |
|---|---|---|---|
| 0091f0fd08 | |||
| daaa846902 |
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* DeploymentService.php 2026-03-23 thomas
|
* DeploymentService.php 2026-03-27 thomas
|
||||||
*
|
*
|
||||||
* Copyright (c) 2026 Thomas Schneider <thomas@inter-mundos.de>
|
* Copyright (c) 2026 Thomas Schneider <thomas@inter-mundos.de>
|
||||||
* Alle Rechte vorbehalten.
|
* Alle Rechte vorbehalten.
|
||||||
@@ -41,7 +41,7 @@ abstract class DeploymentService implements DeploymentInterface
|
|||||||
->setName($project->name)
|
->setName($project->name)
|
||||||
->setWorkingDir($project->projectDir)
|
->setWorkingDir($project->projectDir)
|
||||||
->setComposeFiles([$this->filesDir . '/compose.yaml', $this->filesDir . '/compose.prod.yaml'])
|
->setComposeFiles([$this->filesDir . '/compose.yaml', $this->filesDir . '/compose.prod.yaml'])
|
||||||
->daemonize(true)
|
->wait(true)
|
||||||
->up(['--build']);
|
->up(['--build']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
namespace App\Service\Docker;
|
namespace App\Service\Docker;
|
||||||
|
|
||||||
|
use App\Service\Docker\Logger\LoggerService;
|
||||||
use App\Service\Process\CleanProcess;
|
use App\Service\Process\CleanProcess;
|
||||||
use Dotenv\Dotenv;
|
use Dotenv\Dotenv;
|
||||||
use Exception;
|
use Exception;
|
||||||
@@ -24,6 +25,8 @@ class DockerCompose
|
|||||||
|
|
||||||
protected bool $daemonize = false;
|
protected bool $daemonize = false;
|
||||||
|
|
||||||
|
protected bool $wait = false;
|
||||||
|
|
||||||
protected string $dockerHost = '';
|
protected string $dockerHost = '';
|
||||||
|
|
||||||
protected string $workingDir = '';
|
protected string $workingDir = '';
|
||||||
@@ -41,10 +44,14 @@ class DockerCompose
|
|||||||
*/
|
*/
|
||||||
public function up(array $optionalArgs = []): void
|
public function up(array $optionalArgs = []): void
|
||||||
{
|
{
|
||||||
|
$log = new LoggerService($this->workingDir);
|
||||||
|
$log->clearLog();
|
||||||
|
$log->log('Starting Docker Compose up command at ' . date('Y-m-d H:i:s') . ' with optional arguments: ' . implode(', ', $this->getExtraOptions($optionalArgs)));
|
||||||
|
|
||||||
$process = $this->process('up', $optionalArgs);
|
$process = $this->process('up', $optionalArgs);
|
||||||
$process->run(function ($type, $buffer): void
|
$process->run(function ($type, $buffer) use ($log): void
|
||||||
{
|
{
|
||||||
echo $buffer;
|
$log->log($buffer);
|
||||||
});
|
});
|
||||||
|
|
||||||
// if(!$process->isSuccessful())
|
// if(!$process->isSuccessful())
|
||||||
@@ -161,6 +168,24 @@ class DockerCompose
|
|||||||
$extraOptions[] = '-d';
|
$extraOptions[] = '-d';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->wait)
|
||||||
|
{
|
||||||
|
if(($key = array_search('-d', $extraOptions, true)) !== false)
|
||||||
|
{
|
||||||
|
unset($extraOptions[$key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(($key = array_search('--detach', $extraOptions, true)) !== false)
|
||||||
|
{
|
||||||
|
unset($extraOptions[$key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!in_array('--wait', $extraOptions, true))
|
||||||
|
{
|
||||||
|
$extraOptions[] = '--wait';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $extraOptions;
|
return $extraOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,6 +273,22 @@ class DockerCompose
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the wait state for the current instance.
|
||||||
|
*
|
||||||
|
* This method allows enabling or disabling the wait behavior by updating
|
||||||
|
* the internal wait property. It returns the instance to allow method chaining.
|
||||||
|
*
|
||||||
|
* @param bool $wait The value to set for the wait property.
|
||||||
|
* @return self The current instance with the updated wait state.
|
||||||
|
*/
|
||||||
|
public function wait(bool $wait): self
|
||||||
|
{
|
||||||
|
$this->wait = $wait;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets and merges Docker Compose files.
|
* Sets and merges Docker Compose files.
|
||||||
*
|
*
|
||||||
|
|||||||
39
src/Service/Docker/Logger/LoggerService.php
Normal file
39
src/Service/Docker/Logger/LoggerService.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* LoggerService.php 2026-03-27 thomas
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Thomas Schneider <thomas@inter-mundos.de>
|
||||||
|
* Alle Rechte vorbehalten.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Service\Docker\Logger;
|
||||||
|
|
||||||
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
|
|
||||||
|
class LoggerService
|
||||||
|
{
|
||||||
|
const string LOG_FILE = 'docker.log';
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
protected string $logDir,
|
||||||
|
){}
|
||||||
|
|
||||||
|
|
||||||
|
public function log(string $message): void
|
||||||
|
{
|
||||||
|
new Filesystem()->appendToFile($this->logDir . DIRECTORY_SEPARATOR . self::LOG_FILE, $message . PHP_EOL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function clearLog(): void
|
||||||
|
{
|
||||||
|
new Filesystem()->remove($this->logDir . DIRECTORY_SEPARATOR . self::LOG_FILE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getLog(): string
|
||||||
|
{
|
||||||
|
return new Filesystem()->readFile($this->logDir . DIRECTORY_SEPARATOR . self::LOG_FILE);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -110,7 +110,7 @@ class GitService
|
|||||||
public function fetchRepo(string $dir, array $options = []): void
|
public function fetchRepo(string $dir, array $options = []): void
|
||||||
{
|
{
|
||||||
Process::fromShellCommandline(
|
Process::fromShellCommandline(
|
||||||
command: 'git --all --tags',
|
command: 'git fetch --all --tags',
|
||||||
cwd: $this->workingDir . DIRECTORY_SEPARATOR . $dir,
|
cwd: $this->workingDir . DIRECTORY_SEPARATOR . $dir,
|
||||||
)->mustRun();
|
)->mustRun();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user