wip: swarm

This commit is contained in:
Andras Bacsai 2023-11-28 18:42:09 +01:00
parent b4874c7df3
commit c41ffd6bfb
2 changed files with 36 additions and 16 deletions

View File

@ -13,9 +13,7 @@ class StartProxy
public function handle(Server $server, bool $async = true): string|Activity
{
try {
if ($server->isSwarm()) {
throw new \Exception("Server is part of swarm, not implemented yet.");
}
$proxyType = $server->proxyType();
$commands = collect([]);
$proxy_path = get_proxy_path();
@ -27,6 +25,15 @@ public function handle(Server $server, bool $async = true): string|Activity
$docker_compose_yml_base64 = base64_encode($configuration);
$server->proxy->last_applied_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
$server->save();
if ($server->isSwarm()) {
$commands = $commands->merge([
"mkdir -p $proxy_path && cd $proxy_path",
"echo 'Creating required Docker Compose file.'",
"echo 'Starting coolify-proxy.'",
// "docker stack deploy -c docker-compose.yaml coolify-proxy",
"echo 'Proxy started successfully.'"
]);
} else {
$commands = $commands->merge([
"mkdir -p $proxy_path && cd $proxy_path",
"echo 'Creating required Docker Compose file.'",
@ -39,6 +46,8 @@ public function handle(Server $server, bool $async = true): string|Activity
"echo 'Proxy started successfully.'"
]);
$commands = $commands->merge(connectProxyToNetworks($server));
}
if ($async) {
$activity = remote_process($commands, $server);
return $activity;

View File

@ -102,7 +102,6 @@ function generate_default_proxy_configuration(Server $server)
"--entrypoints.https.address=:443",
"--entrypoints.http.http.encodequerysemicolons=true",
"--entrypoints.https.http.encodequerysemicolons=true",
"--providers.docker=true",
"--providers.docker.exposedbydefault=false",
"--providers.file.directory=/traefik/dynamic/",
"--providers.file.watch=true",
@ -128,6 +127,18 @@ function generate_default_proxy_configuration(Server $server)
$config['services']['traefik']['command'][] = "--accesslog.filepath=/traefik/access.log";
$config['services']['traefik']['command'][] = "--accesslog.bufferingsize=100";
}
if ($server->isSwarm()) {
$config['services']['traefik']['command'][] = "--providers.docker.swarmMode=true";
$config['services']['traefik']['deploy'] = [
"placement" => [
"constraints" => [
"node.role==manager",
],
],
];
} else {
$config['services']['traefik']['command'][] = "--providers.docker=true";
}
$config = Yaml::dump($config, 4, 2);
SaveConfiguration::run($server, $config);
return $config;