save
This commit is contained in:
@@ -20,7 +20,7 @@ class CheckProxySettingsInSync
|
||||
$final_output = Str::of($output)->trim()->value;
|
||||
}
|
||||
$docker_compose_yml_base64 = base64_encode($final_output);
|
||||
$server->extra_attributes->last_saved_proxy_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
|
||||
$server->extra_attributes->proxy_last_saved_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
|
||||
$server->save();
|
||||
if (is_null($output) || $reset) {
|
||||
instant_remote_process([
|
||||
|
||||
@@ -31,41 +31,24 @@ class InstallProxy
|
||||
$configuration = Str::of($configuration)->trim()->value;
|
||||
}
|
||||
$docker_compose_yml_base64 = base64_encode($configuration);
|
||||
$server->extra_attributes->last_applied_proxy_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
|
||||
$server->extra_attributes->proxy_last_applied_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
|
||||
$server->save();
|
||||
|
||||
// $env_file_base64 = base64_encode(
|
||||
// $this->getEnvContents()
|
||||
// );
|
||||
$activity = remote_process([
|
||||
"echo 'Creating required Docker networks...'",
|
||||
...$create_networks_command,
|
||||
"echo 'Docker networks created...'",
|
||||
"mkdir -p $proxy_path",
|
||||
"cd $proxy_path",
|
||||
"echo '$docker_compose_yml_base64' | base64 -d > $proxy_path/docker-compose.yml",
|
||||
// "echo '$env_file_base64' | base64 -d > $proxy_path/.env",
|
||||
"echo 'Docker compose file created...'",
|
||||
"echo 'Creating Docker Compose file...'",
|
||||
"echo 'Pulling docker image...'",
|
||||
'docker compose pull -q',
|
||||
"echo 'Stopping proxy...'",
|
||||
"echo 'Stopping old proxy...'",
|
||||
'docker compose down -v --remove-orphans',
|
||||
"echo 'Starting proxy...'",
|
||||
"echo 'Starting new proxy...'",
|
||||
'docker compose up -d --remove-orphans',
|
||||
"echo 'Proxy installed successfully...'"
|
||||
], $server);
|
||||
|
||||
return $activity;
|
||||
}
|
||||
|
||||
// protected function getEnvContents()
|
||||
// {
|
||||
// $data = [
|
||||
// 'LETS_ENCRYPT_EMAIL' => '',
|
||||
// ];
|
||||
|
||||
// return collect($data)
|
||||
// ->map(fn ($v, $k) => "{$k}={$v}")
|
||||
// ->push(PHP_EOL)
|
||||
// ->implode(PHP_EOL);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use Spatie\Activitylog\Models\Activity;
|
||||
|
||||
class ActivityMonitor extends Component
|
||||
{
|
||||
public bool $header = false;
|
||||
public $activityId;
|
||||
public $isPollingActive = false;
|
||||
|
||||
@@ -50,8 +51,4 @@ class ActivityMonitor extends Component
|
||||
]);
|
||||
$this->activity->save();
|
||||
}
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.activity-monitor');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Http\Livewire\Project\Application;
|
||||
|
||||
use App\Jobs\ContainerStatusJob;
|
||||
use App\Jobs\ApplicationContainerStatusJob;
|
||||
use App\Models\Application;
|
||||
use App\Models\ApplicationPreview;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -24,7 +24,7 @@ class Previews extends Component
|
||||
}
|
||||
public function loadStatus($pull_request_id)
|
||||
{
|
||||
dispatch(new ContainerStatusJob(
|
||||
dispatch(new ApplicationContainerStatusJob(
|
||||
application: $this->application,
|
||||
container_name: generate_container_name($this->application->uuid, $pull_request_id),
|
||||
pull_request_id: $pull_request_id
|
||||
|
||||
@@ -30,7 +30,6 @@ class Form extends Component
|
||||
public function installDocker()
|
||||
{
|
||||
$activity = resolve(InstallDocker::class)($this->server);
|
||||
|
||||
$this->emit('newMonitorActivity', $activity->id);
|
||||
}
|
||||
public function validateServer()
|
||||
|
||||
@@ -11,25 +11,21 @@ use Livewire\Component;
|
||||
|
||||
class Proxy extends Component
|
||||
{
|
||||
protected $listeners = ['serverValidated'];
|
||||
public Server $server;
|
||||
|
||||
public ProxyTypes $selectedProxy = ProxyTypes::TRAEFIK_V2;
|
||||
public $proxy_settings = null;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->proxyStatus();
|
||||
}
|
||||
protected $listeners = ['serverValidated', 'saveConfiguration'];
|
||||
public function serverValidated()
|
||||
{
|
||||
$this->server->settings->refresh();
|
||||
$this->server->refresh();
|
||||
}
|
||||
public function installProxy()
|
||||
{
|
||||
if (
|
||||
$this->server->extra_attributes->last_applied_proxy_settings &&
|
||||
$this->server->extra_attributes->last_saved_proxy_settings !== $this->server->extra_attributes->last_applied_proxy_settings
|
||||
$this->server->extra_attributes->proxy_last_applied_settings &&
|
||||
$this->server->extra_attributes->proxy_last_saved_settings !== $this->server->extra_attributes->proxy_last_applied_settings
|
||||
) {
|
||||
$this->saveConfiguration($this->server);
|
||||
}
|
||||
@@ -37,15 +33,9 @@ class Proxy extends Component
|
||||
$this->emit('newMonitorActivity', $activity->id);
|
||||
}
|
||||
|
||||
public function proxyStatus()
|
||||
public function setProxy(string $proxy_type)
|
||||
{
|
||||
$this->server->extra_attributes->proxy_status = get_container_status(server: $this->server, container_id: 'coolify-proxy');
|
||||
$this->server->save();
|
||||
$this->server->refresh();
|
||||
}
|
||||
public function setProxy()
|
||||
{
|
||||
$this->server->extra_attributes->proxy_type = $this->selectedProxy->value;
|
||||
$this->server->extra_attributes->proxy_type = $proxy_type;
|
||||
$this->server->extra_attributes->proxy_status = 'exited';
|
||||
$this->server->save();
|
||||
}
|
||||
@@ -57,17 +47,17 @@ class Proxy extends Component
|
||||
$this->server->extra_attributes->proxy_status = 'exited';
|
||||
$this->server->save();
|
||||
}
|
||||
public function saveConfiguration()
|
||||
public function saveConfiguration(Server $server)
|
||||
{
|
||||
try {
|
||||
$proxy_path = config('coolify.proxy_config_path');
|
||||
$this->proxy_settings = Str::of($this->proxy_settings)->trim()->value;
|
||||
$docker_compose_yml_base64 = base64_encode($this->proxy_settings);
|
||||
$this->server->extra_attributes->last_saved_proxy_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
|
||||
$this->server->save();
|
||||
$server->extra_attributes->proxy_last_saved_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
|
||||
$server->save();
|
||||
instant_remote_process([
|
||||
"echo '$docker_compose_yml_base64' | base64 -d > $proxy_path/docker-compose.yml",
|
||||
], $this->server);
|
||||
], $server);
|
||||
} catch (\Exception $e) {
|
||||
return general_error_handler($e);
|
||||
}
|
||||
|
||||
43
app/Http/Livewire/Server/Proxy/Deploy.php
Normal file
43
app/Http/Livewire/Server/Proxy/Deploy.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Server\Proxy;
|
||||
|
||||
use App\Actions\Proxy\InstallProxy;
|
||||
use App\Models\Server;
|
||||
use Livewire\Component;
|
||||
use Str;
|
||||
|
||||
class Deploy extends Component
|
||||
{
|
||||
public Server $server;
|
||||
public $proxy_settings = null;
|
||||
protected $listeners = ['proxyStatusUpdated', 'serverValidated' => 'proxyStatusUpdated'];
|
||||
public function proxyStatusUpdated()
|
||||
{
|
||||
$this->server->refresh();
|
||||
}
|
||||
public function deploy()
|
||||
{
|
||||
if (
|
||||
$this->server->extra_attributes->proxy_last_applied_settings &&
|
||||
$this->server->extra_attributes->proxy_last_saved_settings !== $this->server->extra_attributes->proxy_last_applied_settings
|
||||
) {
|
||||
$this->saveConfiguration($this->server);
|
||||
}
|
||||
$activity = resolve(InstallProxy::class)($this->server);
|
||||
$this->emit('newMonitorActivity', $activity->id);
|
||||
}
|
||||
public function stop()
|
||||
{
|
||||
instant_remote_process([
|
||||
"docker rm -f coolify-proxy",
|
||||
], $this->server);
|
||||
$this->server->extra_attributes->proxy_status = 'exited';
|
||||
$this->server->save();
|
||||
$this->emit('proxyStatusUpdated');
|
||||
}
|
||||
private function saveConfiguration(Server $server)
|
||||
{
|
||||
$this->emit('saveConfiguration', $server);
|
||||
}
|
||||
}
|
||||
29
app/Http/Livewire/Server/Proxy/Status.php
Normal file
29
app/Http/Livewire/Server/Proxy/Status.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Server\Proxy;
|
||||
|
||||
use App\Jobs\ProxyContainerStatusJob;
|
||||
use App\Models\Server;
|
||||
use Livewire\Component;
|
||||
|
||||
class Status extends Component
|
||||
{
|
||||
public Server $server;
|
||||
protected $listeners = ['proxyStatusUpdated', 'serverValidated' => 'proxyStatusUpdated'];
|
||||
public function proxyStatusUpdated()
|
||||
{
|
||||
ray('Status: ' . $this->server->extra_attributes->proxy_status);
|
||||
$this->server->refresh();
|
||||
}
|
||||
public function proxyStatus()
|
||||
{
|
||||
try {
|
||||
dispatch(new ProxyContainerStatusJob(
|
||||
server: $this->server
|
||||
));
|
||||
$this->emit('proxyStatusUpdated');
|
||||
} catch (\Exception $e) {
|
||||
ray($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ContainerStatusJob implements ShouldQueue, ShouldBeUnique
|
||||
class ApplicationContainerStatusJob implements ShouldQueue, ShouldBeUnique
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
@@ -35,7 +35,6 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeUnique
|
||||
{
|
||||
try {
|
||||
$status = get_container_status(server: $this->application->destination->server, container_id: $this->container_name, throwError: false);
|
||||
ray('Container ' . $this->container_name . ' statuus is ' . $status);
|
||||
if ($this->pull_request_id) {
|
||||
$preview = ApplicationPreview::findPreviewByApplicationAndPullId($this->application->id, $this->pull_request_id);
|
||||
$preview->status = $status;
|
||||
@@ -55,34 +54,4 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeUnique
|
||||
$this->application->save();
|
||||
}
|
||||
}
|
||||
// protected function check_all_servers()
|
||||
// {
|
||||
// $servers = Server::all()->reject(fn (Server $server) => $server->settings->is_build_server);
|
||||
// $applications = Application::all();
|
||||
// $not_found_applications = $applications;
|
||||
// $containers = collect();
|
||||
// foreach ($servers as $server) {
|
||||
// $output = instant_remote_process(['docker ps -a -q --format \'{{json .}}\''], $server);
|
||||
// $containers = $containers->concat(format_docker_command_output_to_json($output));
|
||||
// }
|
||||
// foreach ($containers as $container) {
|
||||
// $found_application = $applications->filter(function ($value, $key) use ($container) {
|
||||
// return $value->uuid == $container['Names'];
|
||||
// })->first();
|
||||
// if ($found_application) {
|
||||
// $not_found_applications = $not_found_applications->filter(function ($value, $key) use ($found_application) {
|
||||
// return $value->uuid != $found_application->uuid;
|
||||
// });
|
||||
// $found_application->status = $container['State'];
|
||||
// $found_application->save();
|
||||
// Log::info('Found application: ' . $found_application->uuid . '. Set status to: ' . $found_application->status);
|
||||
// }
|
||||
// }
|
||||
// foreach ($not_found_applications as $not_found_application) {
|
||||
// $not_found_application->status = 'exited';
|
||||
// $not_found_application->save();
|
||||
// Log::info('Not found application: ' . $not_found_application->uuid . '. Set status to: ' . $not_found_application->status);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -277,7 +277,7 @@ COPY --from=$this->build_image_name /app/{$this->application->publish_directory}
|
||||
'status' => $status,
|
||||
]);
|
||||
}
|
||||
dispatch(new ContainerStatusJob(
|
||||
dispatch(new ApplicationContainerStatusJob(
|
||||
application: $this->application,
|
||||
container_name: $this->container_name,
|
||||
pull_request_id: $this->pull_request_id
|
||||
|
||||
57
app/Jobs/ProxyContainerStatusJob.php
Normal file
57
app/Jobs/ProxyContainerStatusJob.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Enums\ProxyTypes;
|
||||
use App\Models\Application;
|
||||
use App\Models\ApplicationPreview;
|
||||
use App\Models\Server;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Str;
|
||||
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
||||
|
||||
class ProxyContainerStatusJob implements ShouldQueue, ShouldBeUnique
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public Server $server;
|
||||
public $tries = 1;
|
||||
public $timeout = 120;
|
||||
public function middleware(): array
|
||||
{
|
||||
return [new WithoutOverlapping($this->server->id)];
|
||||
}
|
||||
public function __construct(Server $server)
|
||||
{
|
||||
$this->server = $server;
|
||||
}
|
||||
public function uniqueId(): int
|
||||
{
|
||||
return $this->server->id;
|
||||
}
|
||||
public function handle(): void
|
||||
{
|
||||
try {
|
||||
$container = get_container_status(server: $this->server, all_data: true, container_id: 'coolify-proxy', throwError: false);
|
||||
$status = $container['State']['Status'];
|
||||
if ($this->server->extra_attributes->proxy_status !== $status) {
|
||||
$this->server->extra_attributes->proxy_status = $status;
|
||||
if ($this->server->extra_attributes->proxy_status === 'running') {
|
||||
$traefik = $container['Config']['Labels']['org.opencontainers.image.title'];
|
||||
$version = $container['Config']['Labels']['org.opencontainers.image.version'];
|
||||
if (isset($version) && isset($traefik) && $traefik === 'Traefik' && Str::of($version)->startsWith('v2')) {
|
||||
$this->server->extra_attributes->proxy_type = ProxyTypes::TRAEFIK_V2->value;
|
||||
}
|
||||
}
|
||||
$this->server->save();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
ray($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,7 @@ class Server extends BaseModel
|
||||
{
|
||||
return Server::where('team_id', session('currentTeam')->id)->whereRelation('settings', 'is_validated', true)->get();
|
||||
}
|
||||
|
||||
static public function destinations(string|null $server_uuid = null)
|
||||
{
|
||||
if ($server_uuid) {
|
||||
|
||||
Reference in New Issue
Block a user