fix : ajout d'un préfix pour les path des app et correction de l'affichage
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled

This commit is contained in:
2026-04-07 10:30:58 +02:00
parent 777224709d
commit 419d3b24cb
13 changed files with 173 additions and 46 deletions

View File

@@ -12,6 +12,7 @@ use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use App\Repository\ApplicationRepository;
use App\State\ApplicationProvider;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
@@ -24,11 +25,13 @@ use Symfony\Component\Serializer\Attribute\Groups;
new GetCollection(
normalizationContext: ['groups' => ['app:read']],
security: "is_granted('ROLE_ADMIN')",
provider: ApplicationProvider::class,
),
new Get(
uriVariables: ['slug'],
normalizationContext: ['groups' => ['app:read', 'app:detail']],
security: "is_granted('ROLE_ADMIN')",
provider: ApplicationProvider::class,
),
new Post(
security: "is_granted('ROLE_ADMIN')",

View File

@@ -196,6 +196,13 @@ class Environment
public function getMaintenance(): bool
{
return file_exists((string) $this->maintenanceFilePath);
return $this->maintenance ?? false;
}
public function setMaintenance(bool $maintenance): static
{
$this->maintenance = $maintenance;
return $this;
}
}

View File

@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace App\Service;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
final readonly class AppPathResolver
{
public function __construct(
#[Autowire('%env(APPS_BASE_PATH)%')]
private string $basePath,
) {}
public function resolve(string $relativePath): string
{
return rtrim($this->basePath, '/') . '/' . ltrim($relativePath, '/');
}
}

View File

@@ -7,19 +7,33 @@ namespace App\Service;
use App\Entity\Environment;
use Symfony\Component\Process\Process;
final class DeployService
final readonly class DeployService
{
public function __construct(
private AppPathResolver $pathResolver,
) {}
/**
* @return array{success: bool, output: string, exitCode: int}
*/
public function deploy(Environment $environment, string $tag): array
{
$scriptPath = $environment->getDeployScriptPath();
$relativePath = $environment->getDeployScriptPath();
if (null === $scriptPath || !file_exists($scriptPath)) {
if (null === $relativePath) {
return [
'success' => false,
'output' => sprintf('Deploy script not found: %s', $scriptPath ?? 'null'),
'output' => 'Deploy script path is not configured.',
'exitCode' => 1,
];
}
$scriptPath = $this->pathResolver->resolve($relativePath);
if (!file_exists($scriptPath)) {
return [
'success' => false,
'output' => sprintf('Deploy script not found: %s', $scriptPath),
'exitCode' => 1,
];
}

View File

@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace App\State;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\Entity\Application;
use App\Repository\ApplicationRepository;
use App\Service\AppPathResolver;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
final readonly class ApplicationProvider implements ProviderInterface
{
public function __construct(
private ApplicationRepository $applicationRepository,
private AppPathResolver $pathResolver,
) {}
public function provide(Operation $operation, array $uriVariables = [], array $context = []): Application|array
{
if ($operation instanceof GetCollection) {
$apps = $this->applicationRepository->findAll();
foreach ($apps as $app) {
$this->resolveMaintenanceStatus($app);
}
return $apps;
}
$slug = $uriVariables['slug'] ?? '';
$app = $this->applicationRepository->findOneBy(['slug' => $slug]);
if (null === $app) {
throw new NotFoundHttpException(sprintf('Application "%s" not found.', $slug));
}
$this->resolveMaintenanceStatus($app);
return $app;
}
private function resolveMaintenanceStatus(Application $app): void
{
foreach ($app->getEnvironments() as $env) {
$path = $env->getMaintenanceFilePath();
if (null !== $path) {
$env->setMaintenance(file_exists($this->pathResolver->resolve($path)));
}
}
}
}

View File

@@ -7,21 +7,27 @@ namespace App\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use App\Entity\Environment;
use App\Service\AppPathResolver;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
final readonly class MaintenanceToggleProcessor implements ProcessorInterface
{
public function __construct(
private AppPathResolver $pathResolver,
) {}
/**
* @param Environment $data
*/
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): Environment
{
$maintenancePath = $data->getMaintenanceFilePath();
$relativePath = $data->getMaintenanceFilePath();
if (null === $maintenancePath) {
if (null === $relativePath) {
throw new BadRequestHttpException('Maintenance file path is not configured for this environment.');
}
$maintenancePath = $this->pathResolver->resolve($relativePath);
$requestData = $context['request']?->toArray() ?? [];
$enableMaintenance = $requestData['maintenance'] ?? false;