Logger-Service in GitDeployment integriert: Logging für Git-Deployments hinzugefügt
Changelog: added
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* GitDeployment.php 2026-03-27 thomas
|
||||
* GitDeployment.php 2026-04-7 thomas
|
||||
*
|
||||
* Copyright (c) 2026 Thomas Schneider <thomas@inter-mundos.de>
|
||||
* Alle Rechte vorbehalten.
|
||||
@@ -10,6 +10,7 @@ namespace App\Service\Git;
|
||||
|
||||
use App\Entity\Project;
|
||||
use App\Service\Deployment\DeploymentService;
|
||||
use App\Service\Git\Logger\LoggerService;
|
||||
use App\Service\ProjectConfigDirService;
|
||||
use App\Traits\LoggerTrait;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
|
||||
@@ -21,9 +22,12 @@ class GitDeployment extends DeploymentService
|
||||
|
||||
const string GIT_DIR = 'repo.git';
|
||||
|
||||
protected LoggerService $log;
|
||||
|
||||
|
||||
public function __construct(
|
||||
protected GitService $git, private readonly ProjectConfigDirService $projectConfigDirService,
|
||||
protected GitService $git,
|
||||
private readonly ProjectConfigDirService $projectConfigDirService,
|
||||
){}
|
||||
|
||||
|
||||
@@ -36,6 +40,7 @@ class GitDeployment extends DeploymentService
|
||||
public function init(Project $project): void
|
||||
{
|
||||
$this->git->setWorkingDir($project->projectDir);
|
||||
$this->log = new LoggerService($project->projectDir);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,8 +60,13 @@ class GitDeployment extends DeploymentService
|
||||
*/
|
||||
public function handle(Project $project, string $version = '', string $step = ''): void
|
||||
{
|
||||
$this->log->clearLog();
|
||||
$this->log->log('Starting Git deployment at ' . date('Y-m-d H:i:s') . '...');
|
||||
|
||||
$this->fetch($project);
|
||||
$this->deploy($project, $version);
|
||||
|
||||
$this->log->log('Finished Git deployment at ' . date('Y-m-d H:i:s') . '.');
|
||||
}
|
||||
|
||||
|
||||
@@ -93,6 +103,7 @@ class GitDeployment extends DeploymentService
|
||||
if($this->git->isCloned(self::GIT_DIR))
|
||||
{
|
||||
$this->projectConfigDirService->setDeploymentStep($project->projectDir, 'fetch.git.clone');
|
||||
$this->log->log('Project already cloned. Fetching repo...');
|
||||
|
||||
$this->git->fetchRepo(
|
||||
dir: self::GIT_DIR,
|
||||
@@ -102,6 +113,7 @@ class GitDeployment extends DeploymentService
|
||||
else
|
||||
{
|
||||
$this->projectConfigDirService->setDeploymentStep($project->projectDir, 'fetch.git.fetch');
|
||||
$this->log->log('Fresh Project. Cloning repo...');
|
||||
|
||||
$this->git->cloneRepo(
|
||||
repoUrl: $project->deployment['repository_url'],
|
||||
@@ -139,6 +151,8 @@ class GitDeployment extends DeploymentService
|
||||
$version = $this->git->getRepoDefaultBranch(self::GIT_DIR);
|
||||
}
|
||||
|
||||
$this->log->log('Fetching Version: ' . $version . ' ...');
|
||||
|
||||
if(!$version || $version === 'latest')
|
||||
{
|
||||
# check out latest release
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/*
|
||||
* LoggerService.php 2026-04-7 thomas
|
||||
*
|
||||
* Copyright (c) 2026 Thomas Schneider <thomas@inter-mundos.de>
|
||||
* Alle Rechte vorbehalten.
|
||||
*/
|
||||
|
||||
namespace App\Service\Git\Logger;
|
||||
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
class LoggerService
|
||||
{
|
||||
const string LOG_FILE = 'git.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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user