mirror of
https://github.com/tiennm99/coolify.git
synced 2026-04-18 03:20:26 +00:00
Refactor: Centralize service application prerequisites
Refactors the Appwrite and Beszel service-specific application settings to use a centralized constant-based approach, following the same pattern as NEEDS_TO_CONNECT_TO_PREDEFINED_NETWORK. Changes: - Added NEEDS_TO_DISABLE_GZIP constant for services requiring gzip disabled - Added NEEDS_TO_DISABLE_STRIPPREFIX constant for services requiring stripprefix disabled - Created applyServiceApplicationPrerequisites() helper function in bootstrap/helpers/services.php - Updated all service creation flows to use the centralized helper: * app/Livewire/Project/Resource/Create.php (web handler) * app/Http/Controllers/Api/ServicesController.php (API handler - BUG FIX) * app/Livewire/Project/New/DockerCompose.php (custom compose handler) * app/Http/Controllers/Api/ApplicationsController.php (API custom compose handler) - Added comprehensive unit tests for the new helper function Benefits: - Single source of truth for service prerequisites - DRY - eliminates code duplication between web and API handlers - Fixes bug where API-created services didn't get prerequisites applied - Easy to extend for future services (just edit the constant) - More maintainable and testable Related commits:3a94f1ea1(Beszel),02b18c86e(Appwrite) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -339,3 +339,55 @@ function parseServiceEnvironmentVariable(string $key): array
|
||||
'has_port' => $hasPort,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply service-specific application prerequisites after service parse.
|
||||
*
|
||||
* This function configures application-level settings that are required for
|
||||
* specific one-click services to work correctly (e.g., disabling gzip for Beszel,
|
||||
* disabling strip prefix for Appwrite services).
|
||||
*
|
||||
* Must be called AFTER $service->parse() since it requires applications to exist.
|
||||
*
|
||||
* @param Service $service The service to apply prerequisites to
|
||||
* @return void
|
||||
*/
|
||||
function applyServiceApplicationPrerequisites(Service $service): void
|
||||
{
|
||||
try {
|
||||
// Extract service name from service name (format: "servicename-uuid")
|
||||
$serviceName = str($service->name)->before('-')->value();
|
||||
|
||||
// Apply gzip disabling if needed
|
||||
if (array_key_exists($serviceName, NEEDS_TO_DISABLE_GZIP)) {
|
||||
$applicationNames = NEEDS_TO_DISABLE_GZIP[$serviceName];
|
||||
foreach ($applicationNames as $applicationName) {
|
||||
$application = $service->applications()->whereName($applicationName)->first();
|
||||
if ($application) {
|
||||
$application->is_gzip_enabled = false;
|
||||
$application->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Apply stripprefix disabling if needed
|
||||
if (array_key_exists($serviceName, NEEDS_TO_DISABLE_STRIPPREFIX)) {
|
||||
$applicationNames = NEEDS_TO_DISABLE_STRIPPREFIX[$serviceName];
|
||||
foreach ($applicationNames as $applicationName) {
|
||||
$application = $service->applications()->whereName($applicationName)->first();
|
||||
if ($application) {
|
||||
$application->is_stripprefix_enabled = false;
|
||||
$application->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// Log error but don't throw - prerequisites are nice-to-have, not critical
|
||||
Log::error('Failed to apply service application prerequisites', [
|
||||
'service_id' => $service->id,
|
||||
'service_name' => $service->name,
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user