feat(Production): Complete production deployment infrastructure

- Add comprehensive health check system with multiple endpoints
- Add Prometheus metrics endpoint
- Add production logging configurations (5 strategies)
- Add complete deployment documentation suite:
  * QUICKSTART.md - 30-minute deployment guide
  * DEPLOYMENT_CHECKLIST.md - Printable verification checklist
  * DEPLOYMENT_WORKFLOW.md - Complete deployment lifecycle
  * PRODUCTION_DEPLOYMENT.md - Comprehensive technical reference
  * production-logging.md - Logging configuration guide
  * ANSIBLE_DEPLOYMENT.md - Infrastructure as Code automation
  * README.md - Navigation hub
  * DEPLOYMENT_SUMMARY.md - Executive summary
- Add deployment scripts and automation
- Add DEPLOYMENT_PLAN.md - Concrete plan for immediate deployment
- Update README with production-ready features

All production infrastructure is now complete and ready for deployment.
This commit is contained in:
2025-10-25 19:18:37 +02:00
parent caa85db796
commit fc3d7e6357
83016 changed files with 378904 additions and 20919 deletions

View File

@@ -0,0 +1,98 @@
<?php
declare(strict_types=1);
namespace App\Framework\Health\Checks;
use App\Framework\Core\ValueObjects\Duration;
use App\Framework\Health\HealthCheckCategory;
use App\Framework\Health\HealthCheckInterface;
use App\Framework\Health\HealthCheckResult;
use App\Framework\Queue\Queue;
final readonly class QueueHealthCheck implements HealthCheckInterface
{
public function __construct(
private Queue $queue
) {
}
public function check(): HealthCheckResult
{
$startTime = microtime(true);
try {
// Get queue statistics
$stats = $this->queue->getStats();
$responseTime = Duration::fromSeconds(microtime(true) - $startTime);
$queueSize = $stats['total_size'] ?? 0;
$failedJobs = $stats['failed_jobs'] ?? 0;
// Determine health based on queue metrics
$healthy = true;
$warnings = [];
// Warning if queue is getting large
if ($queueSize > 1000) {
$warnings[] = "Queue size is high ({$queueSize} jobs)";
$healthy = false;
}
// Warning if there are many failed jobs
if ($failedJobs > 100) {
$warnings[] = "High number of failed jobs ({$failedJobs})";
$healthy = false;
}
$data = [
'queue_size' => $queueSize,
'failed_jobs' => $failedJobs,
'response_time_ms' => $responseTime->toMilliseconds(),
];
if (!empty($warnings)) {
return HealthCheckResult::warning(
'Queue System',
implode(', ', $warnings),
$data,
$responseTime->toMilliseconds()
);
}
return HealthCheckResult::healthy(
'Queue System',
$data,
$responseTime->toMilliseconds()
);
} catch (\Throwable $e) {
$responseTime = Duration::fromSeconds(microtime(true) - $startTime);
return HealthCheckResult::unhealthy(
'Queue System',
'Queue system failed: ' . $e->getMessage(),
[
'error_type' => get_class($e),
],
$responseTime->toMilliseconds(),
$e
);
}
}
public function getName(): string
{
return 'Queue System';
}
public function getCategory(): HealthCheckCategory
{
return HealthCheckCategory::INFRASTRUCTURE;
}
public function getTimeout(): int
{
return 3000; // 3 seconds
}
}

View File

@@ -0,0 +1,101 @@
<?php
declare(strict_types=1);
namespace App\Framework\Health\Checks;
use App\Framework\Core\ValueObjects\Duration;
use App\Framework\Deployment\Ssl\SslCertificateManager;
use App\Framework\Health\HealthCheckCategory;
use App\Framework\Health\HealthCheckInterface;
use App\Framework\Health\HealthCheckResult;
final readonly class SslHealthCheck implements HealthCheckInterface
{
public function __construct(
private SslCertificateManager $sslManager
) {
}
public function check(): HealthCheckResult
{
$startTime = microtime(true);
try {
$status = $this->sslManager->getCertificateStatus();
$responseTime = Duration::fromSeconds(microtime(true) - $startTime);
$data = [
'valid' => $status->isValid(),
'days_until_expiry' => $status->getDaysUntilExpiry(),
'issuer' => $status->getIssuer(),
'subject' => $status->getSubject(),
'response_time_ms' => $responseTime->toMilliseconds(),
];
// Certificate expired or expiring soon
if (!$status->isValid()) {
return HealthCheckResult::unhealthy(
'SSL Certificate',
'Certificate is invalid or expired',
$data,
$responseTime->toMilliseconds()
);
}
// Warning if expiring within 7 days
if ($status->getDaysUntilExpiry() <= 7) {
return HealthCheckResult::warning(
'SSL Certificate',
"Certificate expiring in {$status->getDaysUntilExpiry()} days",
$data,
$responseTime->toMilliseconds()
);
}
// Warning if expiring within 30 days
if ($status->getDaysUntilExpiry() <= 30) {
return HealthCheckResult::warning(
'SSL Certificate',
"Certificate expiring in {$status->getDaysUntilExpiry()} days (renewal recommended)",
$data,
$responseTime->toMilliseconds()
);
}
return HealthCheckResult::healthy(
'SSL Certificate',
$data,
$responseTime->toMilliseconds()
);
} catch (\Throwable $e) {
$responseTime = Duration::fromSeconds(microtime(true) - $startTime);
return HealthCheckResult::unhealthy(
'SSL Certificate',
'SSL check failed: ' . $e->getMessage(),
[
'error_type' => get_class($e),
],
$responseTime->toMilliseconds(),
$e
);
}
}
public function getName(): string
{
return 'SSL Certificate';
}
public function getCategory(): HealthCheckCategory
{
return HealthCheckCategory::SECURITY;
}
public function getTimeout(): int
{
return 5000; // 5 seconds
}
}

View File

@@ -0,0 +1,94 @@
<?php
declare(strict_types=1);
namespace App\Framework\Health\Checks;
use App\Framework\Core\ValueObjects\Duration;
use App\Framework\Health\HealthCheckCategory;
use App\Framework\Health\HealthCheckInterface;
use App\Framework\Health\HealthCheckResult;
use App\Framework\Vault\Vault;
use App\Framework\Vault\ValueObjects\SecretKey;
final readonly class VaultHealthCheck implements HealthCheckInterface
{
public function __construct(
private Vault $vault
) {
}
public function check(): HealthCheckResult
{
$startTime = microtime(true);
$testKey = SecretKey::from('_health_check_test_' . time());
try {
// Test Vault connectivity and encryption/decryption
// Create test secret
$testValue = 'health_check_' . bin2hex(random_bytes(8));
// Store test secret
$this->vault->set($testKey, $testValue);
// Retrieve test secret
$retrievedValue = $this->vault->get($testKey);
// Delete test secret
$this->vault->delete($testKey);
$responseTime = Duration::fromSeconds(microtime(true) - $startTime);
// Verify value matches
if ($retrievedValue->reveal() === $testValue) {
return HealthCheckResult::healthy(
'Vault',
[
'operations' => ['set', 'get', 'delete'],
'encryption' => 'working',
'response_time_ms' => $responseTime->toMilliseconds(),
],
$responseTime->toMilliseconds()
);
}
return HealthCheckResult::warning(
'Vault',
'Encryption/decryption mismatch',
[
'expected_length' => strlen($testValue),
'actual_length' => strlen($retrievedValue->reveal()),
],
$responseTime->toMilliseconds()
);
} catch (\Throwable $e) {
$responseTime = Duration::fromSeconds(microtime(true) - $startTime);
return HealthCheckResult::unhealthy(
'Vault',
'Vault system failed: ' . $e->getMessage(),
[
'error_type' => get_class($e),
],
$responseTime->toMilliseconds(),
$e
);
}
}
public function getName(): string
{
return 'Vault Secrets Management';
}
public function getCategory(): HealthCheckCategory
{
return HealthCheckCategory::SECURITY;
}
public function getTimeout(): int
{
return 5000; // 5 seconds
}
}

View File

@@ -4,19 +4,15 @@ declare(strict_types=1);
namespace App\Framework\Health;
use App\Framework\Cache\Cache;
use App\Framework\Database\DatabaseManager;
use App\Framework\DI\Container;
use App\Framework\DI\Initializer;
use App\Framework\Health\Checks\CacheHealthCheck;
use App\Framework\Health\Checks\DatabaseHealthCheck;
use App\Framework\Health\Checks\DiskSpaceHealthCheck;
use App\Framework\Health\Checks\SystemHealthCheck;
use App\Framework\Discovery\UnifiedDiscoveryService;
final readonly class HealthCheckManagerInitializer
{
public function __construct(
private DatabaseManager $databaseManager,
private Cache $cache
private UnifiedDiscoveryService $discoveryService,
private Container $container
) {
}
@@ -25,22 +21,25 @@ final readonly class HealthCheckManagerInitializer
{
$manager = new HealthCheckManager();
// Register all health checks
$manager->registerHealthCheck(
new DatabaseHealthCheck($this->databaseManager)
// Automatically discover all classes implementing HealthCheckInterface
$healthCheckClasses = $this->discoveryService->findImplementations(
HealthCheckInterface::class
);
$manager->registerHealthCheck(
new CacheHealthCheck($this->cache)
);
// Register each health check via dependency injection
foreach ($healthCheckClasses as $className) {
try {
// Use container to instantiate (handles dependencies automatically)
$healthCheck = $this->container->get($className);
$manager->registerHealthCheck(
new DiskSpaceHealthCheck()
);
$manager->registerHealthCheck(
new SystemHealthCheck()
);
if ($healthCheck instanceof HealthCheckInterface) {
$manager->registerHealthCheck($healthCheck);
}
} catch (\Throwable $e) {
// Log error but continue with other health checks
error_log("Failed to register health check {$className}: " . $e->getMessage());
}
}
return $manager;
}