lasthourcloud/bootstrap/helpers/proxy.php

86 lines
3.6 KiB
PHP
Raw Normal View History

2023-05-24 12:26:50 +00:00
<?php
use App\Models\Server;
use Symfony\Component\Yaml\Yaml;
if (!function_exists('getProxyConfiguration')) {
function getProxyConfiguration(Server $server)
{
$proxy_path = config('coolify.proxy_config_path');
2023-05-25 10:00:09 +00:00
if (config('app.env') === 'local') {
$proxy_path = $proxy_path . '/testing-host-1/';
}
2023-05-24 12:26:50 +00:00
$networks = collect($server->standaloneDockers)->map(function ($docker) {
return $docker['network'];
})->unique();
if ($networks->count() === 0) {
$networks = collect(['coolify']);
}
$array_of_networks = collect([]);
$networks->map(function ($network) use ($array_of_networks) {
$array_of_networks[$network] = [
"external" => true,
];
});
$config = [
"version" => "3.8",
"networks" => $array_of_networks->toArray(),
"services" => [
"traefik" => [
"container_name" => "coolify-proxy",
"image" => "traefik:v2.10",
"restart" => "always",
"extra_hosts" => [
"host.docker.internal:host-gateway",
],
"networks" => $networks->toArray(),
"ports" => [
"80:80",
"443:443",
"8080:8080",
],
2023-06-08 08:29:44 +00:00
"healthcheck" => [
"test" => "wget -qO- http://localhost:80/ping || exit 1",
"interval" => "4s",
"timeout" => "2s",
"retries" => 5,
],
2023-05-24 12:26:50 +00:00
"volumes" => [
"/var/run/docker.sock:/var/run/docker.sock:ro",
"{$proxy_path}:/traefik",
],
"command" => [
2023-06-08 08:29:44 +00:00
"--ping=true",
"--ping.entrypoint=http",
2023-05-24 12:26:50 +00:00
"--api.dashboard=true",
"--api.insecure=true",
"--entrypoints.http.address=:80",
"--entrypoints.https.address=:443",
"--providers.docker=true",
"--providers.docker.exposedbydefault=false",
2023-05-24 20:39:24 +00:00
"--providers.file.directory=/traefik/dynamic/",
2023-05-24 12:26:50 +00:00
"--providers.file.watch=true",
"--certificatesresolvers.letsencrypt.acme.httpchallenge=true",
"--certificatesresolvers.letsencrypt.acme.storage=/traefik/acme.json",
"--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=http",
],
"labels" => [
"traefik.enable=true",
"traefik.http.routers.traefik.entrypoints=http",
"traefik.http.routers.traefik.middlewares=traefik-basic-auth@file",
"traefik.http.routers.traefik.service=api@internal",
"traefik.http.services.traefik.loadbalancer.server.port=8080",
2023-05-25 19:28:10 +00:00
// Global Middlewares
2023-05-24 12:26:50 +00:00
"traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https",
"traefik.http.middlewares.gzip.compress=true",
],
],
],
];
if (config('app.env') === 'local') {
$config['services']['traefik']['command'][] = "--log.level=debug";
}
return Yaml::dump($config, 4, 2);
}
}