wip
This commit is contained in:
parent
1f5345dfdb
commit
7fe50a9a1f
103
app/Actions/Proxy/InstallProxy.php
Normal file
103
app/Actions/Proxy/InstallProxy.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Proxy;
|
||||
|
||||
use App\Enums\ActivityTypes;
|
||||
use App\Models\Server;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class InstallProxy
|
||||
{
|
||||
public function __invoke(Server $server)
|
||||
{
|
||||
$docker_compose_yml_base64 = base64_encode(
|
||||
$this->getDockerComposeContents()
|
||||
);
|
||||
|
||||
$env_file_base64 = base64_encode(
|
||||
$this->getEnvContents()
|
||||
);
|
||||
|
||||
$activity = remoteProcess([
|
||||
'mkdir -p proxy',
|
||||
'mkdir -p proxy/letsencrypt',
|
||||
'cd proxy',
|
||||
"echo '$docker_compose_yml_base64' | base64 -d > docker-compose.yml",
|
||||
"echo '$env_file_base64' | base64 -d > .env",
|
||||
'cat .env',
|
||||
], $server, ActivityTypes::INLINE->value);
|
||||
|
||||
return $activity;
|
||||
}
|
||||
|
||||
protected function getDockerComposeContents()
|
||||
{
|
||||
return Yaml::dump($this->getComposeData());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getComposeData(): array
|
||||
{
|
||||
return [
|
||||
"version" => "3.7",
|
||||
"networks" => [
|
||||
"coolify" => [
|
||||
"external" => true,
|
||||
],
|
||||
],
|
||||
"services" => [
|
||||
"traefik" => [
|
||||
"image" => "traefik:v2.9",
|
||||
"restart" => "always",
|
||||
"extra_hosts" => [
|
||||
"host.docker.internal:host-gateway",
|
||||
],
|
||||
"networks" => [
|
||||
"coolify",
|
||||
],
|
||||
"ports" => [
|
||||
"80:80",
|
||||
"443:443",
|
||||
"8080:8080",
|
||||
],
|
||||
"volumes" => [
|
||||
"/var/run/docker.sock:/var/run/docker.sock:ro",
|
||||
"./letsencrypt:/letsencrypt",
|
||||
"./traefik.auth:/auth/traefik.auth",
|
||||
],
|
||||
"command" => [
|
||||
"--api.dashboard=true",
|
||||
"--api.insecure=true",
|
||||
"--entrypoints.http.address=:80",
|
||||
"--entrypoints.https.address=:443",
|
||||
"--providers.docker=true",
|
||||
"--providers.docker.exposedbydefault=false",
|
||||
],
|
||||
"labels" => [
|
||||
"traefik.enable=true",
|
||||
"traefik.http.routers.traefik.entrypoints=http",
|
||||
'traefik.http.routers.traefik.rule=Host(`${TRAEFIK_DASHBOARD_HOST}`)',
|
||||
"traefik.http.routers.traefik.service=api@internal",
|
||||
"traefik.http.services.traefik.loadbalancer.server.port=8080",
|
||||
"traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https",
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getEnvContents()
|
||||
{
|
||||
$data = [
|
||||
'TRAEFIK_DASHBOARD_HOST' => '',
|
||||
'LETS_ENCRYPT_EMAIL' => '',
|
||||
];
|
||||
|
||||
return collect($data)
|
||||
->map(fn($v, $k) => "{$k}={$v}")
|
||||
->push(PHP_EOL)
|
||||
->implode(PHP_EOL);
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Livewire\Server;
|
||||
|
||||
use App\Actions\Proxy\InstallProxy;
|
||||
use App\Enums\ActivityTypes;
|
||||
use App\Models\Server;
|
||||
use Livewire\Component;
|
||||
@ -19,7 +20,7 @@ public function mount(Server $server)
|
||||
|
||||
public function runInstallProxy()
|
||||
{
|
||||
$activity = remoteProcess(['ls -alh'], $this->server, ActivityTypes::INLINE->value);
|
||||
$activity = resolve(InstallProxy::class)($this->server);
|
||||
|
||||
$this->emit('newMonitorActivity', $activity->id);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user