This commit is contained in:
Andras Bacsai 2023-06-15 13:28:16 +02:00
parent 890f0819ad
commit cbfc490d95
12 changed files with 75 additions and 43 deletions

View File

@ -2,21 +2,28 @@
namespace App\Actions\Server; namespace App\Actions\Server;
use App\Enums\ActivityTypes;
use App\Models\Server; use App\Models\Server;
class InstallDocker class InstallDocker
{ {
public function __invoke(Server $server) public function __invoke(Server $server)
{ {
$dockerVersion = '23.0';
$config = base64_encode('{ "live-restore": true }'); $config = base64_encode('{ "live-restore": true }');
$activity = remote_process([ $activity = remote_process([
"echo Installing Docker...", "echo ####### Installing Prerequisites...",
"curl https://releases.rancher.com/install-docker/23.0.sh | sh", "command -v jq >/dev/null || apt-get update",
"echo Configuring Docker...", "command -v jq >/dev/null || apt install -y jq",
"echo '{$config}' | base64 -d > /etc/docker/daemon.json", "echo ####### Installing/updating Docker Engine...",
"echo Restarting Docker...", "curl https://releases.rancher.com/install-docker/{$dockerVersion}.sh | sh",
"systemctl restart docker" "echo ####### Configuring Docker Engine (merging existing configuration with the required)...",
"test -s /etc/docker/daemon.json && cp /etc/docker/daemon.json \"/etc/docker/daemon.json.original-`date +\"%Y%m%d-%H%M%S\"`\" || echo '{$config}' | base64 -d > /etc/docker/daemon.json",
"echo '{$config}' | base64 -d > /etc/docker/daemon.json.coolify",
"cat <<< $(jq . /etc/docker/daemon.json.coolify) > /etc/docker/daemon.json.coolify",
"cat <<< $(jq -s '.[0] * .[1]' /etc/docker/daemon.json /etc/docker/daemon.json.coolify) > /etc/docker/daemon.json",
"echo ####### Restarting Docker Engine...",
"systemctl restart docker",
"echo ####### Done!"
], $server); ], $server);
return $activity; return $activity;

View File

@ -39,16 +39,15 @@ public function validateServer()
if (!$this->uptime) { if (!$this->uptime) {
$this->uptime = 'Server not reachable.'; $this->uptime = 'Server not reachable.';
throw new \Exception('Server not reachable.'); throw new \Exception('Server not reachable.');
} else {
if (!$this->server->settings->is_validated) {
$this->server->settings->is_validated = true;
$this->server->settings->save();
$this->emit('serverValidated');
}
} }
$this->dockerVersion = instant_remote_process(['docker version|head -2|grep -i version'], $this->server, false); $this->dockerVersion = instant_remote_process(['docker version|head -2|grep -i version'], $this->server, false);
if (!$this->dockerVersion) { if (!$this->dockerVersion) {
$this->dockerVersion = 'Not installed.'; $this->dockerVersion = 'Not installed.';
} else {
$this->server->settings->is_docker_installed = true;
$this->server->settings->is_validated = true;
$this->server->settings->save();
$this->emit('serverValidated');
} }
$this->dockerComposeVersion = instant_remote_process(['docker compose version|head -2|grep -i version'], $this->server, false); $this->dockerComposeVersion = instant_remote_process(['docker compose version|head -2|grep -i version'], $this->server, false);
if (!$this->dockerComposeVersion) { if (!$this->dockerComposeVersion) {

View File

@ -35,6 +35,5 @@ public function handle(): void
]); ]);
$remote_process(); $remote_process();
// @TODO: Remove file at $this->activity->getExtraProperty('private_key_location') after process is finished
} }
} }

View File

@ -3,9 +3,10 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str; use Illuminate\Support\Str;
class LocalPersistentVolume extends BaseModel class LocalPersistentVolume extends Model
{ {
protected $fillable = [ protected $fillable = [
'name', 'name',

View File

@ -7,7 +7,8 @@
class ServerSetting extends Model class ServerSetting extends Model
{ {
protected $fillable = [ protected $fillable = [
'server_id' 'server_id',
'is_docker_installed',
]; ];
public function server() public function server()
{ {

View File

@ -18,7 +18,6 @@ class UserFactory extends Factory
public function definition(): array public function definition(): array
{ {
return [ return [
'uuid' => Str::uuid(),
'email' => fake()->unique()->safeEmail(), 'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(), 'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password

View File

@ -17,6 +17,7 @@ public function up(): void
$table->boolean('is_jump_server')->default(false); $table->boolean('is_jump_server')->default(false);
$table->boolean('is_build_server')->default(false); $table->boolean('is_build_server')->default(false);
$table->boolean('is_validated')->default(false); $table->boolean('is_validated')->default(false);
$table->boolean('is_docker_installed')->default(false);
$table->foreignId('server_id'); $table->foreignId('server_id');
$table->timestamps(); $table->timestamps();
}); });

View File

@ -1,16 +1,21 @@
<x-layout> <x-layout>
<main class="grid min-h-full px-6 place-items-center lg:px-8"> <div class="min-h-screen hero">
<div class="text-center"> <div class="text-center hero-content">
<p class="text-6xl font-semibold text-warning">404</p> <div class="">
<h1 class="mt-4 text-3xl font-bold tracking-tight text-white sm:text-5xl">Page not found</h1> <p class="font-mono text-6xl font-semibold text-warning">404</p>
<p class="mt-6 text-base leading-7 text-neutral-300">Sorry, we couldnt find the page youre looking for.</p> <h1 class="mt-4 font-bold tracking-tight text-white">How did you got here?</h1>
<div class="flex items-center justify-center mt-10 gap-x-6"> <p class="mt-6 text-base leading-7 text-neutral-300">Sorry, we couldnt find the page youre looking for.
<a href="/" </p>
class="rounded-md bg-coollabs px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-coollabs-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 hover:no-underline">Go <div class="flex items-center justify-center mt-10 gap-x-6">
back home</a> <a href="/">
<a href="https://docs.coollabs.io/contact.html" class="text-sm font-semibold text-white">Contact support <x-forms.button isHighlighted>Go back home</x-forms.button>
<span aria-hidden="true">&rarr;</span></a> </a>
<a target="_blank" class="text-xs" href="https://docs.coollabs.io/contact.html">Contact
support
<x-external-link />
</a>
</div>
</div> </div>
</div> </div>
</main> </div>
</x-layout> </x-layout>

View File

@ -1,5 +1,20 @@
@extends('errors::minimal') <x-layout>
<div class="min-h-screen hero">
@section('title', __('Page Expired')) <div class="text-center hero-content">
@section('code', '419') <div class="">
@section('message', __('Page Expired')) <p class="font-mono text-6xl font-semibold text-warning">419</p>
<h1 class="mt-4 font-bold tracking-tight text-white">This page is definitely old</h1>
<p class="mt-6 text-base leading-7 text-neutral-300">Sorry, we couldnt find the page youre looking for.
</p>
<div class="flex items-center justify-center mt-10 gap-x-6">
<a href="/"
class="rounded-md bg-coollabs px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-coollabs-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 hover:no-underline">Go
back home</a>
<a href="https://docs.coollabs.io/contact.html" class="text-sm font-semibold text-white">Contact
support
<span aria-hidden="true">&rarr;</span></a>
</div>
</div>
</div>
</div>
</x-layout>

View File

@ -49,20 +49,30 @@
<h3 class="pt-8 pb-4">Quick Actions</h3> <h3 class="pt-8 pb-4">Quick Actions</h3>
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<x-forms.button wire:click.prevent='validateServer'> <x-forms.button wire:click.prevent='validateServer'>
Check Connection Check Server Details
</x-forms.button>
<x-forms.button wire:click.prevent='installDocker'>
@if ($server->settings->is_docker_installed)
Reconfigure Docker Engine
@else
Install Docker Engine
@endif
</x-forms.button> </x-forms.button>
{{-- <x-forms.button wire:click.prevent='installDocker'>Install Docker</x-forms.button> --}} {{-- <x-forms.button wire:click.prevent='installDocker'>Install Docker</x-forms.button> --}}
</div> </div>
@endif @endif
<div class="container w-full py-4 mx-auto">
<livewire:activity-monitor :header="true" />
</div>
@isset($uptime) @isset($uptime)
<h3 class="py-3">Server Info</h3> <h3 class="pb-3">Server Info</h3>
<div class="text-sm"> <div class="text-sm">
<p>Uptime: {{ $uptime }}</p> <p>Uptime: {{ $uptime }}</p>
@isset($dockerVersion) @isset($dockerVersion)
<p>Docker Engine {{ $dockerVersion }}</p> <p>Docker Engine {{ $dockerVersion }}</p>
@endisset @endisset
@isset($dockerComposeVersion) @isset($dockerComposeVersion)
<p>{{ $dockerComposeVersion }}</p> <p>Compose: {{ $dockerComposeVersion }}</p>
@endisset @endisset
</div> </div>
@endisset @endisset

View File

@ -1,6 +1,6 @@
<div> <div>
@if ($server->settings->is_validated) @if ($server->settings->is_validated)
<div wire:poll.10000ms="proxyStatus"> <div wire:poll.10000ms="proxyStatus" x-init="$wire.proxyStatus">
@if ($server->extra_attributes->proxy_status === 'running') @if ($server->extra_attributes->proxy_status === 'running')
<x-status.running /> <x-status.running />
@elseif ($server->extra_attributes->proxy_status === 'restarting') @elseif ($server->extra_attributes->proxy_status === 'restarting')

View File

@ -1,5 +0,0 @@
#!/bin/bash
curl https://releases.rancher.com/install-docker/23.0.sh | sh
echo "Docker installed successfully"
echo '{ "live-restore": true }' >/etc/docker/daemon.json
systemctl restart docker