wip: backup existing database

This commit is contained in:
Andras Bacsai 2023-09-05 12:14:31 +02:00
parent f6f4cdde24
commit 1338e68b8c
4 changed files with 73 additions and 35 deletions

View File

@ -22,34 +22,52 @@ class Select extends Component
public Collection|array $swarmDockers = [];
public array $parameters;
public ?string $existingPostgresqlUrl = null;
protected $queryString = [
'server',
];
public function mount()
{
$this->parameters = get_route_parameters();
if (isDev()) {
$this->existingPostgresqlUrl = 'postgres://coolify:password@coolify-db:5432';
}
}
public function set_type(string $type)
// public function addExistingPostgresql()
// {
// try {
// instantCommand("psql {$this->existingPostgresqlUrl} -c 'SELECT 1'");
// $this->emit('success', 'Successfully connected to the database.');
// } catch (\Exception $e) {
// return general_error_handler($e, $this);
// }
// }
public function setType(string $type)
{
$this->type = $type;
if ($type === "existing-postgresql") {
$this->current_step = $type;
return;
}
if (count($this->servers) === 1) {
$server = $this->servers->first();
$this->set_server($server);
$this->setServer($server);
if (count($server->destinations()) === 1) {
$this->set_destination($server->destinations()->first()->uuid);
$this->setDestination($server->destinations()->first()->uuid);
}
}
if (!is_null($this->server)) {
$foundServer = $this->servers->where('id', $this->server)->first();
if ($foundServer) {
return $this->set_server($foundServer);
return $this->setServer($foundServer);
}
}
$this->current_step = 'servers';
}
public function set_server(Server $server)
public function setServer(Server $server)
{
$this->server_id = $server->id;
$this->standaloneDockers = $server->standaloneDockers;
@ -57,7 +75,7 @@ public function set_server(Server $server)
$this->current_step = 'destinations';
}
public function set_destination(string $destination_uuid)
public function setDestination(string $destination_uuid)
{
$this->destination_uuid = $destination_uuid;
redirect()->route('project.resources.new', [

View File

@ -93,7 +93,18 @@ function generate_ssh_command(string $private_key_location, string $server_ip, s
return $ssh_command;
}
function instantCommand(string $command, $throwError = true) {
$process = Process::run($command);
$output = trim($process->output());
$exitCode = $process->exitCode();
if ($exitCode !== 0) {
if (!$throwError) {
return null;
}
throw new \RuntimeException($process->errorOutput(), $exitCode);
}
return $output;
}
function instant_remote_process(array $command, Server $server, $throwError = true, $repeat = 1)
{
$command_string = implode("\n", $command);

View File

@ -26,7 +26,8 @@ class="absolute inset-y-0 left-0 flex items-center pl-2 cursor-pointer hover:tex
wire:model.defer={{ $id }} wire:dirty.class.remove='text-white'
wire:dirty.class="input-warning" wire:loading.attr="disabled" type="{{ $type }}"
@readonly($readonly) @disabled($disabled) id="{{ $id }}" name="{{ $name }}"
placeholder="{{ $attributes->get('placeholder') }}">
placeholder="{{ $attributes->get('placeholder') }}"
aria-placeholder="{{ $attributes->get('placeholder') }}">
</div>
@else

View File

@ -10,8 +10,7 @@
</ul>
<h2>Applications</h2>
<div class="grid justify-start grid-cols-1 gap-2 text-left xl:grid-cols-3">
<div class="box group"
wire:click="set_type('public')">
<div class="box group" wire:click="setType('public')">
<div class="flex flex-col mx-6">
<div class="group-hover:text-white">
Public Repository
@ -21,8 +20,7 @@
</div>
</div>
</div>
<div class="box group"
wire:click="set_type('private-gh-app')">
<div class="box group" wire:click="setType('private-gh-app')">
<div class="flex flex-col mx-6">
<div class="group-hover:text-white">
Private Repository
@ -32,8 +30,7 @@
</div>
</div>
</div>
<div class="box group"
wire:click="set_type('private-deploy-key')">
<div class="box group" wire:click="setType('private-deploy-key')">
<div class="flex flex-col mx-6">
<div class="group-hover:text-white">
Private Repository (with deploy key)
@ -45,8 +42,7 @@
</div>
</div>
<div class="grid justify-start grid-cols-1 gap-2 text-left xl:grid-cols-3">
<div class="box group"
wire:click="set_type('dockerfile')">
<div class="box group" wire:click="setType('dockerfile')">
<div class="flex flex-col mx-6">
<div class="group-hover:text-white">
Based on a Dockerfile
@ -58,18 +54,27 @@
</div>
</div>
<h2 class="py-4">Databases</h2>
<div class="flex flex-col justify-start gap-2 text-left xl:flex-row">
<div class="box group"
wire:click="set_type('postgresql')">
<div class="grid justify-start grid-cols-1 gap-2 text-left xl:grid-cols-3">
<div class="box group" wire:click="setType('postgresql')">
<div class="flex flex-col mx-6">
<div class="group-hover:text-white">
PostgreSQL
New PostgreSQL
</div>
<div class="text-xs group-hover:text-white">
The most loved relational database in the world.
</div>
</div>
</div>
{{-- <div class="box group" wire:click="setType('existing-postgresql')">
<div class="flex flex-col mx-6">
<div class="group-hover:text-white">
Backup Existing PostgreSQL
</div>
<div class="text-xs group-hover:text-white">
Schedule a backup of an existing PostgreSQL database.
</div>
</div>
</div> --}}
</div>
@endif
@if ($current_step === 'servers')
@ -80,8 +85,7 @@
</ul>
<div class="flex flex-col justify-center gap-2 text-left xl:flex-row">
@forelse($servers as $server)
<div class="box group"
wire:click="set_server({{ $server }})">
<div class="box group" wire:click="setServer({{ $server }})">
<div class="flex flex-col mx-6">
<div class="group-hover:text-white">
{{ $server->name }}
@ -92,9 +96,9 @@
</div>
@empty
<div>
<div>No validated & reachable servers found. <a class="text-white underline" href="/servers">
Go to servers page
</a></div>
<div>No validated & reachable servers found. <a class="text-white underline" href="/servers">
Go to servers page
</a></div>
<x-use-magic-bar link="/server/new" />
</div>
@ -109,11 +113,10 @@
</ul>
<div class="flex flex-col justify-center gap-2 text-left xl:flex-row">
@foreach ($standaloneDockers as $standaloneDocker)
<div class="box group"
wire:click="set_destination('{{ $standaloneDocker->uuid }}')">
<div class="box group" wire:click="setDestination('{{ $standaloneDocker->uuid }}')">
<div class="flex flex-col mx-6">
<div class="font-bold group-hover:text-white">
Standalone Docker <span class="text-xs">({{ $standaloneDocker->name }})</span>
Standalone Docker <span class="text-xs">({{ $standaloneDocker->name }})</span>
</div>
<div class="text-xs group-hover:text-white">
network: {{ $standaloneDocker->network }}</div>
@ -121,16 +124,21 @@
</div>
@endforeach
@foreach ($swarmDockers as $swarmDocker)
<div class="box group"
wire:click="set_destination('{{ $swarmDocker->uuid }}')">
<div class="flex flex-col mx-6">
<div class="font-bold group-hover:text-white">
Swarm Docker <span class="text-xs">({{ $swarmDocker->name }})</span>
<div class="box group" wire:click="setDestination('{{ $swarmDocker->uuid }}')">
<div class="flex flex-col mx-6">
<div class="font-bold group-hover:text-white">
Swarm Docker <span class="text-xs">({{ $swarmDocker->name }})</span>
</div>
</div>
</div>
</div>
@endforeach
@endforeach
</div>
@endif
@if ($current_step === 'existing-postgresql')
<form wire:submit.prevent='addExistingPostgresql' class="flex items-end gap-2">
<x-forms.input placeholder="postgres://username:password@database:5432" label="Database URL" id="existingPostgresqlUrl" />
<x-forms.button type="submit">Add Database</x-forms.button>
</form>
@endif
</div>
</div>