mirror of
https://github.com/tiennm99/coolify.git
synced 2026-04-17 17:21:04 +00:00
feat(proxy): enhance proxy configuration regeneration by extracting custom commands
- Added a new function to extract custom proxy commands from existing Traefik configurations before regenerating the proxy configuration. - Updated the proxy configuration generation logic to include these custom commands, ensuring they are preserved during regeneration. - Introduced unit tests to validate the extraction of custom commands and handle various scenarios, including invalid YAML and different proxy types.
This commit is contained in:
@@ -108,7 +108,63 @@ function connectProxyToNetworks(Server $server)
|
||||
|
||||
return $commands->flatten();
|
||||
}
|
||||
function generate_default_proxy_configuration(Server $server)
|
||||
function extractCustomProxyCommands(Server $server, string $existing_config): array
|
||||
{
|
||||
$custom_commands = [];
|
||||
$proxy_type = $server->proxyType();
|
||||
|
||||
if ($proxy_type !== ProxyTypes::TRAEFIK->value || empty($existing_config)) {
|
||||
return $custom_commands;
|
||||
}
|
||||
|
||||
try {
|
||||
$yaml = Yaml::parse($existing_config);
|
||||
$existing_commands = data_get($yaml, 'services.traefik.command', []);
|
||||
|
||||
if (empty($existing_commands)) {
|
||||
return $custom_commands;
|
||||
}
|
||||
|
||||
// Define default commands that Coolify generates
|
||||
$default_command_prefixes = [
|
||||
'--ping=',
|
||||
'--api.',
|
||||
'--entrypoints.http.address=',
|
||||
'--entrypoints.https.address=',
|
||||
'--entrypoints.http.http.encodequerysemicolons=',
|
||||
'--entryPoints.http.http2.maxConcurrentStreams=',
|
||||
'--entrypoints.https.http.encodequerysemicolons=',
|
||||
'--entryPoints.https.http2.maxConcurrentStreams=',
|
||||
'--entrypoints.https.http3',
|
||||
'--providers.file.',
|
||||
'--certificatesresolvers.',
|
||||
'--providers.docker',
|
||||
'--providers.swarm',
|
||||
'--log.level=',
|
||||
'--accesslog.',
|
||||
];
|
||||
|
||||
// Extract commands that don't match default prefixes (these are custom)
|
||||
foreach ($existing_commands as $command) {
|
||||
$is_default = false;
|
||||
foreach ($default_command_prefixes as $prefix) {
|
||||
if (str_starts_with($command, $prefix)) {
|
||||
$is_default = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! $is_default) {
|
||||
$custom_commands[] = $command;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// If we can't parse the config, return empty array
|
||||
// Silently fail to avoid breaking the proxy regeneration
|
||||
}
|
||||
|
||||
return $custom_commands;
|
||||
}
|
||||
function generateDefaultProxyConfiguration(Server $server, array $custom_commands = [])
|
||||
{
|
||||
$proxy_path = $server->proxyPath();
|
||||
$proxy_type = $server->proxyType();
|
||||
@@ -228,6 +284,13 @@ function generate_default_proxy_configuration(Server $server)
|
||||
$config['services']['traefik']['command'][] = '--providers.docker=true';
|
||||
$config['services']['traefik']['command'][] = '--providers.docker.exposedbydefault=false';
|
||||
}
|
||||
|
||||
// Append custom commands (e.g., trustedIPs for Cloudflare)
|
||||
if (! empty($custom_commands)) {
|
||||
foreach ($custom_commands as $custom_command) {
|
||||
$config['services']['traefik']['command'][] = $custom_command;
|
||||
}
|
||||
}
|
||||
} elseif ($proxy_type === 'CADDY') {
|
||||
$config = [
|
||||
'networks' => $array_of_networks->toArray(),
|
||||
|
||||
Reference in New Issue
Block a user