Compare commits
3 Commits
ee1b9bafc7
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 62b50152dc | |||
| 0091f0fd08 | |||
| daaa846902 |
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* DeploymentService.php 2026-03-23 thomas
|
||||
* DeploymentService.php 2026-03-27 thomas
|
||||
*
|
||||
* Copyright (c) 2026 Thomas Schneider <thomas@inter-mundos.de>
|
||||
* Alle Rechte vorbehalten.
|
||||
@@ -41,7 +41,7 @@ abstract class DeploymentService implements DeploymentInterface
|
||||
->setName($project->name)
|
||||
->setWorkingDir($project->projectDir)
|
||||
->setComposeFiles([$this->filesDir . '/compose.yaml', $this->filesDir . '/compose.prod.yaml'])
|
||||
->daemonize(true)
|
||||
->wait(true)
|
||||
->up(['--build']);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
namespace App\Service\Docker;
|
||||
|
||||
use App\Service\Docker\Logger\LoggerService;
|
||||
use App\Service\Process\CleanProcess;
|
||||
use Dotenv\Dotenv;
|
||||
use Exception;
|
||||
@@ -24,6 +25,8 @@ class DockerCompose
|
||||
|
||||
protected bool $daemonize = false;
|
||||
|
||||
protected bool $wait = false;
|
||||
|
||||
protected string $dockerHost = '';
|
||||
|
||||
protected string $workingDir = '';
|
||||
@@ -41,10 +44,14 @@ class DockerCompose
|
||||
*/
|
||||
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->run(function ($type, $buffer): void
|
||||
$process->run(function ($type, $buffer) use ($log): void
|
||||
{
|
||||
echo $buffer;
|
||||
$log->log($buffer);
|
||||
});
|
||||
|
||||
// if(!$process->isSuccessful())
|
||||
@@ -161,6 +168,24 @@ class DockerCompose
|
||||
$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;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
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
|
||||
{
|
||||
Process::fromShellCommandline(
|
||||
command: 'git --all --tags',
|
||||
command: 'git fetch --all --tags',
|
||||
cwd: $this->workingDir . DIRECTORY_SEPARATOR . $dir,
|
||||
)->mustRun();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* CleanProcess.php 2026-03-27 thomas
|
||||
* CleanProcess.php 2026-04-9 thomas
|
||||
*
|
||||
* Copyright (c) 2026 Thomas Schneider <thomas@inter-mundos.de>
|
||||
* Alle Rechte vorbehalten.
|
||||
@@ -27,8 +27,9 @@ class CleanProcess extends Process
|
||||
private function parseEnvVars(string $keySelector, array &$env): void
|
||||
{
|
||||
$preservedKeys = [];
|
||||
$envVars = getenv($keySelector) ?: ($_SERVER[$keySelector] ?? $_ENV[$keySelector] ?? false);
|
||||
|
||||
if(empty(getenv($keySelector)))
|
||||
if(empty($envVars))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -39,7 +40,7 @@ class CleanProcess extends Process
|
||||
$preservedKeys += ['SSH_AUTH_SOCK'];
|
||||
}
|
||||
|
||||
$vars = array_fill_keys(explode(',', getenv($keySelector)), false);
|
||||
$vars = array_fill_keys(explode(',', $envVars), false);
|
||||
|
||||
$env = [...array_diff_key($vars, array_flip($preservedKeys)), ...$env];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user