wip
This commit is contained in:
parent
9f0ca1cc2e
commit
3bdea4c931
@ -20,7 +20,7 @@ class CheckProxySettingsInSync
|
|||||||
$final_output = Str::of($output)->trim()->value;
|
$final_output = Str::of($output)->trim()->value;
|
||||||
}
|
}
|
||||||
$docker_compose_yml_base64 = base64_encode($final_output);
|
$docker_compose_yml_base64 = base64_encode($final_output);
|
||||||
$server->extra_attributes->proxy_last_saved_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
|
$server->proxy->last_saved_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
|
||||||
$server->save();
|
$server->save();
|
||||||
if (is_null($output) || $reset) {
|
if (is_null($output) || $reset) {
|
||||||
instant_remote_process([
|
instant_remote_process([
|
||||||
|
@ -12,9 +12,9 @@ class InstallProxy
|
|||||||
{
|
{
|
||||||
public function __invoke(Server $server): Activity
|
public function __invoke(Server $server): Activity
|
||||||
{
|
{
|
||||||
if (is_null(data_get($server, 'extra_attributes.proxy_type'))) {
|
if (is_null(data_get($server, 'proxy.type'))) {
|
||||||
$server->extra_attributes->proxy_type = ProxyTypes::TRAEFIK_V2->value;
|
$server->proxy->type = ProxyTypes::TRAEFIK_V2->value;
|
||||||
$server->extra_attributes->proxy_status = ProxyStatus::EXITED->value;
|
$server->proxy->status = ProxyStatus::EXITED->value;
|
||||||
$server->save();
|
$server->save();
|
||||||
}
|
}
|
||||||
$proxy_path = config('coolify.proxy_config_path');
|
$proxy_path = config('coolify.proxy_config_path');
|
||||||
@ -38,7 +38,7 @@ class InstallProxy
|
|||||||
$configuration = Str::of($configuration)->trim()->value;
|
$configuration = Str::of($configuration)->trim()->value;
|
||||||
}
|
}
|
||||||
$docker_compose_yml_base64 = base64_encode($configuration);
|
$docker_compose_yml_base64 = base64_encode($configuration);
|
||||||
$server->extra_attributes->proxy_last_applied_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
|
$server->proxy->last_applied_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
|
||||||
$server->save();
|
$server->save();
|
||||||
$activity = remote_process([
|
$activity = remote_process([
|
||||||
"echo 'Creating required Docker networks...'",
|
"echo 'Creating required Docker networks...'",
|
||||||
|
@ -9,8 +9,8 @@ use Spatie\LaravelData\Data;
|
|||||||
class ServerMetadata extends Data
|
class ServerMetadata extends Data
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public ?ProxyTypes $proxy_type,
|
public ?ProxyTypes $type,
|
||||||
public ?ProxyStatus $proxy_status
|
public ?ProxyStatus $status
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,14 +23,14 @@ class Proxy extends Component
|
|||||||
}
|
}
|
||||||
public function switchProxy()
|
public function switchProxy()
|
||||||
{
|
{
|
||||||
$this->server->extra_attributes->proxy_type = null;
|
$this->server->proxy->type = null;
|
||||||
$this->server->save();
|
$this->server->save();
|
||||||
}
|
}
|
||||||
public function installProxy()
|
public function installProxy()
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
$this->server->extra_attributes->proxy_last_applied_settings &&
|
$this->server->proxy->last_applied_settings &&
|
||||||
$this->server->extra_attributes->proxy_last_saved_settings !== $this->server->extra_attributes->proxy_last_applied_settings
|
$this->server->proxy->last_saved_settings !== $this->server->proxy->last_applied_settings
|
||||||
) {
|
) {
|
||||||
$this->saveConfiguration($this->server);
|
$this->saveConfiguration($this->server);
|
||||||
}
|
}
|
||||||
@ -40,8 +40,8 @@ class Proxy extends Component
|
|||||||
|
|
||||||
public function setProxy(string $proxy_type)
|
public function setProxy(string $proxy_type)
|
||||||
{
|
{
|
||||||
$this->server->extra_attributes->proxy_type = $proxy_type;
|
$this->server->proxy->type = $proxy_type;
|
||||||
$this->server->extra_attributes->proxy_status = 'exited';
|
$this->server->proxy->status = 'exited';
|
||||||
$this->server->save();
|
$this->server->save();
|
||||||
}
|
}
|
||||||
public function stopProxy()
|
public function stopProxy()
|
||||||
@ -49,7 +49,7 @@ class Proxy extends Component
|
|||||||
instant_remote_process([
|
instant_remote_process([
|
||||||
"docker rm -f coolify-proxy",
|
"docker rm -f coolify-proxy",
|
||||||
], $this->server);
|
], $this->server);
|
||||||
$this->server->extra_attributes->proxy_status = 'exited';
|
$this->server->proxy->status = 'exited';
|
||||||
$this->server->save();
|
$this->server->save();
|
||||||
}
|
}
|
||||||
public function saveConfiguration(Server $server)
|
public function saveConfiguration(Server $server)
|
||||||
@ -58,7 +58,7 @@ class Proxy extends Component
|
|||||||
$proxy_path = config('coolify.proxy_config_path');
|
$proxy_path = config('coolify.proxy_config_path');
|
||||||
$this->proxy_settings = Str::of($this->proxy_settings)->trim()->value;
|
$this->proxy_settings = Str::of($this->proxy_settings)->trim()->value;
|
||||||
$docker_compose_yml_base64 = base64_encode($this->proxy_settings);
|
$docker_compose_yml_base64 = base64_encode($this->proxy_settings);
|
||||||
$server->extra_attributes->proxy_last_saved_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
|
$server->proxy->last_saved_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
|
||||||
$server->save();
|
$server->save();
|
||||||
instant_remote_process([
|
instant_remote_process([
|
||||||
"echo '$docker_compose_yml_base64' | base64 -d > $proxy_path/docker-compose.yml",
|
"echo '$docker_compose_yml_base64' | base64 -d > $proxy_path/docker-compose.yml",
|
||||||
|
@ -19,8 +19,8 @@ class Deploy extends Component
|
|||||||
public function deploy()
|
public function deploy()
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
$this->server->extra_attributes->proxy_last_applied_settings &&
|
$this->server->proxy->last_applied_settings &&
|
||||||
$this->server->extra_attributes->proxy_last_saved_settings !== $this->server->extra_attributes->proxy_last_applied_settings
|
$this->server->proxy->last_saved_settings !== $this->server->proxy->last_applied_settings
|
||||||
) {
|
) {
|
||||||
$this->saveConfiguration($this->server);
|
$this->saveConfiguration($this->server);
|
||||||
}
|
}
|
||||||
@ -32,7 +32,7 @@ class Deploy extends Component
|
|||||||
instant_remote_process([
|
instant_remote_process([
|
||||||
"docker rm -f coolify-proxy",
|
"docker rm -f coolify-proxy",
|
||||||
], $this->server);
|
], $this->server);
|
||||||
$this->server->extra_attributes->proxy_status = 'exited';
|
$this->server->proxy->status = 'exited';
|
||||||
$this->server->save();
|
$this->server->save();
|
||||||
$this->emit('proxyStatusUpdated');
|
$this->emit('proxyStatusUpdated');
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ class InstanceProxyCheckJob implements ShouldQueue
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$container_name = 'coolify-proxy';
|
$container_name = 'coolify-proxy';
|
||||||
$servers = Server::whereRelation('settings', 'is_reachable', true)->where('extra_attributes->proxy_type', ProxyTypes::TRAEFIK_V2)->get();
|
$servers = Server::whereRelation('settings', 'is_reachable', true)->where('proxy->type', ProxyTypes::TRAEFIK_V2)->get();
|
||||||
|
|
||||||
foreach ($servers as $server) {
|
foreach ($servers as $server) {
|
||||||
$status = get_container_status(server: $server, container_id: $container_name);
|
$status = get_container_status(server: $server, container_id: $container_name);
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
namespace App\Jobs;
|
namespace App\Jobs;
|
||||||
|
|
||||||
use App\Enums\ProxyTypes;
|
use App\Enums\ProxyTypes;
|
||||||
use App\Models\Application;
|
|
||||||
use App\Models\ApplicationPreview;
|
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||||
@ -12,8 +10,8 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
|||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Str;
|
|
||||||
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class ProxyContainerStatusJob implements ShouldQueue, ShouldBeUnique
|
class ProxyContainerStatusJob implements ShouldQueue, ShouldBeUnique
|
||||||
{
|
{
|
||||||
@ -39,13 +37,13 @@ class ProxyContainerStatusJob implements ShouldQueue, ShouldBeUnique
|
|||||||
try {
|
try {
|
||||||
$container = get_container_status(server: $this->server, all_data: true, container_id: 'coolify-proxy', throwError: true);
|
$container = get_container_status(server: $this->server, all_data: true, container_id: 'coolify-proxy', throwError: true);
|
||||||
$status = $container['State']['Status'];
|
$status = $container['State']['Status'];
|
||||||
if ($this->server->extra_attributes->proxy_status !== $status) {
|
if ($this->server->proxy->status !== $status) {
|
||||||
$this->server->extra_attributes->proxy_status = $status;
|
$this->server->proxy->status = $status;
|
||||||
if ($this->server->extra_attributes->proxy_status === 'running') {
|
if ($this->server->proxy->status === 'running') {
|
||||||
$traefik = $container['Config']['Labels']['org.opencontainers.image.title'];
|
$traefik = $container['Config']['Labels']['org.opencontainers.image.title'];
|
||||||
$version = $container['Config']['Labels']['org.opencontainers.image.version'];
|
$version = $container['Config']['Labels']['org.opencontainers.image.version'];
|
||||||
if (isset($version) && isset($traefik) && $traefik === 'Traefik' && Str::of($version)->startsWith('v2')) {
|
if (isset($version) && isset($traefik) && $traefik === 'Traefik' && Str::of($version)->startsWith('v2')) {
|
||||||
$this->server->extra_attributes->proxy_type = ProxyTypes::TRAEFIK_V2->value;
|
$this->server->proxy->type = ProxyTypes::TRAEFIK_V2->value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->server->save();
|
$this->server->save();
|
||||||
|
@ -4,9 +4,17 @@ namespace App\Models;
|
|||||||
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;
|
use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;
|
||||||
|
use Spatie\SchemalessAttributes\SchemalessAttributesTrait;
|
||||||
|
|
||||||
class Server extends BaseModel
|
class Server extends BaseModel
|
||||||
{
|
{
|
||||||
|
use SchemalessAttributesTrait;
|
||||||
|
protected $schemalessAttributes = [
|
||||||
|
'proxy',
|
||||||
|
];
|
||||||
|
public $casts = [
|
||||||
|
'proxy' => SchemalessAttributes::class,
|
||||||
|
];
|
||||||
protected static function booted()
|
protected static function booted()
|
||||||
{
|
{
|
||||||
static::created(function ($server) {
|
static::created(function ($server) {
|
||||||
@ -25,16 +33,14 @@ class Server extends BaseModel
|
|||||||
'port',
|
'port',
|
||||||
'team_id',
|
'team_id',
|
||||||
'private_key_id',
|
'private_key_id',
|
||||||
'extra_attributes',
|
'proxy',
|
||||||
];
|
];
|
||||||
|
|
||||||
public $casts = [
|
|
||||||
'extra_attributes' => SchemalessAttributes::class,
|
|
||||||
];
|
|
||||||
|
|
||||||
public function scopeWithExtraAttributes(): Builder
|
|
||||||
|
public function scopeWithProxy(): Builder
|
||||||
{
|
{
|
||||||
return $this->extra_attributes->modelScope();
|
return $this->proxy->modelScope();
|
||||||
}
|
}
|
||||||
public function isEmpty()
|
public function isEmpty()
|
||||||
{
|
{
|
||||||
|
@ -21,7 +21,7 @@ return new class extends Migration
|
|||||||
$table->string('user')->default('root');
|
$table->string('user')->default('root');
|
||||||
$table->foreignId('team_id');
|
$table->foreignId('team_id');
|
||||||
$table->foreignId('private_key_id');
|
$table->foreignId('private_key_id');
|
||||||
$table->schemalessAttributes('extra_attributes');
|
$table->schemalessAttributes('proxy');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -77,9 +77,9 @@ class ProductionSeeder extends Seeder
|
|||||||
'team_id' => 0,
|
'team_id' => 0,
|
||||||
'private_key_id' => 0
|
'private_key_id' => 0
|
||||||
];
|
];
|
||||||
$server_details['extra_attributes'] = ServerMetadata::from([
|
$server_details['proxy'] = ServerMetadata::from([
|
||||||
'proxy_type' => ProxyTypes::TRAEFIK_V2->value,
|
'type' => ProxyTypes::TRAEFIK_V2->value,
|
||||||
'proxy_status' => ProxyStatus::EXITED->value
|
'status' => ProxyStatus::EXITED->value
|
||||||
]);
|
]);
|
||||||
$server = Server::create($server_details);
|
$server = Server::create($server_details);
|
||||||
$server->settings->is_reachable = true;
|
$server->settings->is_reachable = true;
|
||||||
|
@ -28,9 +28,9 @@ class ServerSeeder extends Seeder
|
|||||||
'ip' => "coolify-testing-host",
|
'ip' => "coolify-testing-host",
|
||||||
'team_id' => $root_team->id,
|
'team_id' => $root_team->id,
|
||||||
'private_key_id' => $private_key_1->id,
|
'private_key_id' => $private_key_1->id,
|
||||||
'extra_attributes' => ServerMetadata::from([
|
'proxy' => ServerMetadata::from([
|
||||||
'proxy_type' => ProxyTypes::TRAEFIK_V2->value,
|
'type' => ProxyTypes::TRAEFIK_V2->value,
|
||||||
'proxy_status' => ProxyStatus::EXITED->value
|
'status' => ProxyStatus::EXITED->value
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
Server::create([
|
Server::create([
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<x-naked-modal show="stopProxy" action="stopProxy" title="Stop Proxy"
|
<x-naked-modal show="stopProxy" action="stopProxy" title="Stop Proxy"
|
||||||
message='This proxy will be stopped. It is not reversible. <br>All resources will be unavailable. <br>Please think again.' />
|
message='This proxy will be stopped. It is not reversible. <br>All resources will be unavailable. <br>Please think again.' />
|
||||||
@if ($server->settings->is_reachable)
|
@if ($server->settings->is_reachable)
|
||||||
@if ($server->extra_attributes->proxy_type)
|
@if ($server->proxy->type)
|
||||||
<div x-init="$wire.checkProxySettingsInSync">
|
<div x-init="$wire.checkProxySettingsInSync">
|
||||||
<div wire:loading wire:target="checkProxySettingsInSync">
|
<div wire:loading wire:target="checkProxySettingsInSync">
|
||||||
<x-loading />
|
<x-loading />
|
||||||
@ -13,15 +13,15 @@
|
|||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<h2>Proxy</h2>
|
<h2>Proxy</h2>
|
||||||
<x-forms.button type="submit">Save</x-forms.button>
|
<x-forms.button type="submit">Save</x-forms.button>
|
||||||
@if ($server->extra_attributes->proxy_status === 'exited')
|
@if ($server->proxy->status === 'exited')
|
||||||
<x-forms.button wire:click.prevent="switchProxy">Switch Proxy</x-forms.button>
|
<x-forms.button wire:click.prevent="switchProxy">Switch Proxy</x-forms.button>
|
||||||
@endif
|
@endif
|
||||||
<livewire:server.proxy.status :server="$server" />
|
<livewire:server.proxy.status :server="$server" />
|
||||||
</div>
|
</div>
|
||||||
<div class="pt-3 pb-4 ">Traefik v2</div>
|
<div class="pt-3 pb-4 ">Traefik v2</div>
|
||||||
@if (
|
@if (
|
||||||
$server->extra_attributes->proxy_last_applied_settings &&
|
$server->proxy->last_applied_settings &&
|
||||||
$server->extra_attributes->proxy_last_saved_settings !== $server->extra_attributes->proxy_last_applied_settings)
|
$server->proxy->last_saved_settings !== $server->proxy->last_applied_settings)
|
||||||
<div class="text-red-500 ">Configuration out of sync. Restart to get the new configs.
|
<div class="text-red-500 ">Configuration out of sync. Restart to get the new configs.
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<div>
|
<div>
|
||||||
@if ($server->settings->is_reachable)
|
@if ($server->settings->is_reachable)
|
||||||
@if ($server->extra_attributes->proxy_status === 'running')
|
@if ($server->proxy->status === 'running')
|
||||||
<div class="flex gap-4">
|
<div class="flex gap-4">
|
||||||
<div class="group">
|
<div class="group">
|
||||||
<label tabindex="0" class="flex items-center gap-2 cursor-pointer hover:text-white"> Links
|
<label tabindex="0" class="flex items-center gap-2 cursor-pointer hover:text-white"> Links
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
<div>
|
<div>
|
||||||
@if ($server->settings->is_reachable)
|
@if ($server->settings->is_reachable)
|
||||||
<div wire:poll.10000ms="proxyStatus" x-init="$wire.proxyStatus">
|
<div wire:poll.10000ms="proxyStatus" x-init="$wire.proxyStatus">
|
||||||
@if ($server->extra_attributes->proxy_status === 'running')
|
@if ($server->proxy->status === 'running')
|
||||||
<x-status.running />
|
<x-status.running />
|
||||||
@elseif ($server->extra_attributes->proxy_status === 'restarting')
|
@elseif ($server->proxy->status === 'restarting')
|
||||||
<x-status.restarting />
|
<x-status.restarting />
|
||||||
@else
|
@else
|
||||||
<x-status.stopped />
|
<x-status.stopped />
|
||||||
|
@ -71,7 +71,7 @@ Route::middleware(['auth'])->group(function () {
|
|||||||
'server' => Server::ownedByCurrentTeam(['name', 'description', 'ip', 'port', 'user'])->whereUuid(request()->server_uuid)->firstOrFail(),
|
'server' => Server::ownedByCurrentTeam(['name', 'description', 'ip', 'port', 'user'])->whereUuid(request()->server_uuid)->firstOrFail(),
|
||||||
]))->name('server.show');
|
]))->name('server.show');
|
||||||
Route::get('/server/{server_uuid}/proxy', fn () => view('server.proxy', [
|
Route::get('/server/{server_uuid}/proxy', fn () => view('server.proxy', [
|
||||||
'server' => Server::ownedByCurrentTeam(['name', 'extra_attributes'])->whereUuid(request()->server_uuid)->firstOrFail(),
|
'server' => Server::ownedByCurrentTeam(['name', 'proxy'])->whereUuid(request()->server_uuid)->firstOrFail(),
|
||||||
]))->name('server.proxy');
|
]))->name('server.proxy');
|
||||||
Route::get('/server/{server_uuid}/private-key', fn () => view('server.private-key', [
|
Route::get('/server/{server_uuid}/private-key', fn () => view('server.private-key', [
|
||||||
'server' => Server::ownedByCurrentTeam()->whereUuid(request()->server_uuid)->firstOrFail(),
|
'server' => Server::ownedByCurrentTeam()->whereUuid(request()->server_uuid)->firstOrFail(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user