diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 476d54437..07e4a2a0f 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -43,6 +43,7 @@ class ProjectController extends Controller { $type = request()->query('type'); $destination_uuid = request()->query('destination'); + $server = requesT()->query('server'); $project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first(); if (!$project) { @@ -59,6 +60,9 @@ class ProjectController extends Controller 'environment_name' => $environment->name, 'database_uuid' => $standalone_postgresql->uuid, ]); + } + if ($server) { + } return view('project.new', [ 'type' => $type diff --git a/app/Http/Livewire/Boarding/Index.php b/app/Http/Livewire/Boarding/Index.php index 539751ceb..8cc1cd50d 100644 --- a/app/Http/Livewire/Boarding/Index.php +++ b/app/Http/Livewire/Boarding/Index.php @@ -6,7 +6,7 @@ use App\Actions\Server\InstallDocker; use App\Models\PrivateKey; use App\Models\Project; use App\Models\Server; -use Illuminate\Database\Eloquent\Collection; +use Illuminate\Support\Collection; use Livewire\Component; class Index extends Component @@ -22,6 +22,8 @@ class Index extends Component public ?string $privateKeyDescription = null; public ?PrivateKey $createdPrivateKey = null; + public ?Collection $servers = null; + public ?int $selectedExistingServer = null; public ?string $remoteServerName = null; public ?string $remoteServerDescription = null; public ?string $remoteServerHost = null; @@ -29,6 +31,8 @@ class Index extends Component public ?string $remoteServerUser = 'root'; public ?Server $createdServer = null; + public Collection|array $projects = []; + public ?int $selectedExistingProject = null; public ?Project $createdProject = null; public function mount() @@ -66,25 +70,62 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== refreshSession(); return redirect()->route('dashboard'); } - public function setServer(string $type) + + public function setServerType(string $type) { if ($type === 'localhost') { $this->createdServer = Server::find(0); if (!$this->createdServer) { return $this->emit('error', 'Localhost server is not found. Something went wrong during installation. Please try to reinstall or contact support.'); } - $this->currentState = 'select-proxy'; + return $this->validateServer(); } elseif ($type === 'remote') { - $this->privateKeys = PrivateKey::ownedByCurrentTeam(['name'])->get(); + $this->privateKeys = PrivateKey::ownedByCurrentTeam(['name'])->where('id', '!=', 0)->get(); + if ($this->privateKeys->count() > 0) { + $this->selectedExistingPrivateKey = $this->privateKeys->first()->id; + } + $this->servers = Server::ownedByCurrentTeam(['name'])->where('id', '!=', 0)->get(); + if ($this->servers->count() > 0) { + $this->selectedExistingServer = $this->servers->first()->id; + $this->currentState = 'select-existing-server'; + return; + } $this->currentState = 'private-key'; } } + public function selectExistingServer() + { + $this->createdServer = Server::find($this->selectedExistingServer); + if (!$this->createdServer) { + $this->emit('error', 'Server is not found.'); + $this->currentState = 'private-key'; + return; + } + $this->selectedExistingPrivateKey = $this->createdServer->privateKey->id; + $this->validateServer(); + $this->getProxyType(); + $this->getProjects(); + } + public function getProxyType() { + $proxyTypeSet = $this->createdServer->proxy->type; + if (!$proxyTypeSet) { + $this->currentState = 'select-proxy'; + return; + } + $this->getProjects(); + } public function selectExistingPrivateKey() { - ray($this->selectedExistingPrivateKey); + $this->currentState = 'create-server'; + } + public function createNewServer() + { + $this->selectedExistingServer = null; + $this->currentState = 'private-key'; } public function setPrivateKey(string $type) { + $this->selectedExistingPrivateKey = null; $this->privateKeyType = $type; if ($type === 'create' && !isDev()) { $this->createNewPrivateKey(); @@ -123,11 +164,12 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== 'private_key_id' => $this->createdPrivateKey->id, 'team_id' => currentTeam()->id ]); + $this->validateServer(); + } + public function validateServer() { try { ['uptime' => $uptime, 'dockerVersion' => $dockerVersion] = validateServer($this->createdServer); if (!$uptime) { - $this->createdServer->delete(); - $this->createdPrivateKey->delete(); throw new \Exception('Server is not reachable.'); } else { $this->createdServer->settings->update([ @@ -135,11 +177,14 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== ]); $this->emit('success', 'Server is reachable.'); } - if ($dockerVersion) { + ray($dockerVersion, $uptime); + if (!$dockerVersion) { $this->emit('error', 'Docker is not installed on the server.'); $this->currentState = 'install-docker'; return; } + $this->getProxyType(); + } catch (\Exception $e) { return general_error_handler(customErrorMessage: "Server is not reachable. Reason: {$e->getMessage()}", that: $this); } @@ -153,13 +198,25 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== public function selectProxy(string|null $proxyType = null) { if (!$proxyType) { - return $this->currentState = 'create-project'; + return $this->getProjects(); } $this->createdServer->proxy->type = $proxyType; $this->createdServer->proxy->status = 'exited'; $this->createdServer->save(); + $this->getProjects(); + } + + public function getProjects() { + $this->projects = Project::ownedByCurrentTeam(['name'])->get(); + if ($this->projects->count() > 0) { + $this->selectedExistingProject = $this->projects->first()->id; + } $this->currentState = 'create-project'; } + public function selectExistingProject() { + $this->createdProject = Project::find($this->selectedExistingProject); + $this->currentState = 'create-resource'; + } public function createNewProject() { $this->createdProject = Project::create([ diff --git a/app/Http/Livewire/Project/New/Select.php b/app/Http/Livewire/Project/New/Select.php index b3109ef8c..e48ebf9cf 100644 --- a/app/Http/Livewire/Project/New/Select.php +++ b/app/Http/Livewire/Project/New/Select.php @@ -5,10 +5,12 @@ namespace App\Http\Livewire\Project\New; use App\Models\Server; use Countable; use Livewire\Component; +use Route; class Select extends Component { public $current_step = 'type'; + public ?int $server = null; public string $type; public string $server_id; public string $destination_uuid; @@ -16,6 +18,9 @@ class Select extends Component public $destinations = []; public array $parameters; + protected $queryString = [ + 'server', + ]; public function mount() { $this->parameters = get_route_parameters(); @@ -31,6 +36,12 @@ class Select extends Component $this->set_destination($server->destinations()->first()->uuid); } } + if (!is_null($this->server )) { + $foundServer = $this->servers->where('id', $this->server)->first(); + if ($foundServer) { + return $this->set_server($foundServer); + } + } $this->current_step = 'servers'; } diff --git a/app/Http/Livewire/Server/PrivateKey.php b/app/Http/Livewire/Server/ShowPrivateKey.php similarity index 96% rename from app/Http/Livewire/Server/PrivateKey.php rename to app/Http/Livewire/Server/ShowPrivateKey.php index 8f433f73d..4f77014cb 100644 --- a/app/Http/Livewire/Server/PrivateKey.php +++ b/app/Http/Livewire/Server/ShowPrivateKey.php @@ -6,7 +6,7 @@ use App\Models\Server; use Livewire\Component; use Masmerise\Toaster\Toaster; -class PrivateKey extends Component +class ShowPrivateKey extends Component { public Server $server; public $privateKeys; diff --git a/resources/views/livewire/boarding/index.blade.php b/resources/views/livewire/boarding/index.blade.php index 06ff5661b..d38aa0190 100644 --- a/resources/views/livewire/boarding/index.blade.php +++ b/resources/views/livewire/boarding/index.blade.php @@ -1,198 +1,279 @@ @php use App\Enums\ProxyTypes; @endphp
- @if ($currentState === 'welcome') -

Welcome to Coolify

-

Let me help you to set the basics.

-
-
Get Started +
+ @if ($currentState === 'welcome') +

Welcome to Coolify

+

Let me help you to set the basics.

+
+
Get Started +
-
- @endif - @if ($currentState === 'select-server') - - - Do you want to deploy your resources on your - or on a ? - - -
Localhost -
-
Remote Server -
-
- -

Servers are the main building blocks, as they will host your applications, databases, - services, called resources. Any CPU intensive process will use the server's CPU where you - are deploying your resources.

-

Localhost is the server where Coolify is running on. It is not recommended to use one server - for everyting.

-

Remote Server is a server reachable through SSH. It can be hosted at home, or from any cloud - provider.

-
-
- @endif - @if ($currentState === 'private-key') - - - Do you have your own SSH Private Key? - - -
Yes -
-
No (create one for me) -
-
- - @foreach ($privateKeys as $privateKey) - - @endforeach - - Select this -
-
- -

SSH Keys are used to connect to a remote server through a secure shell, called SSH.

-

You can use your own ssh private key, or you can let Coolify to create one for you.

-

In both ways, you need to add the public version of your ssh private key to the remote - server's - ~/.ssh/authorized_keys file. -

-
-
- @endif - @if ($currentState === 'create-private-key') - - - Please let me know your key details. - - -
- - - - @if ($privateKeyType === 'create' && !isDev()) - Copy this to your server's ~/.ssh/authorized_keys - file. - + @endif +
+
+ @if ($currentState === 'select-server-type') + + + Do you want to deploy your resources on your + or on a ? + + +
Localhost +
+
Remote Server +
+
+ +

Servers are the main building blocks, as they will host your applications, databases, + services, called resources. Any CPU intensive process will use the server's CPU where you + are deploying your resources.

+

Localhost is the server where Coolify is running on. It is not recommended to use one server + for everyting.

+

Remote Server is a server reachable through SSH. It can be hosted at home, or from any cloud + provider.

+
+
+ @endif +
+
+ @if ($currentState === 'private-key') + + + Do you have your own SSH Private Key? + + +
Yes +
+
No (create one for me) +
+ @if (count($privateKeys) > 0) + + + @foreach ($privateKeys as $privateKey) + + @endforeach + + Use this SSH Key + @endif - Save - -
- -

Private Keys are used to connect to a remote server through a secure shell, called SSH.

-

You can use your own private key, or you can let Coolify to create one for you.

-

In both ways, you need to add the public version of your private key to the remote server's - ~/.ssh/authorized_keys file. -

-
-
- @endif - @if ($currentState === 'create-server') - - - Please let me know your server details. - - -
-
- + + +

SSH Keys are used to connect to a remote server through a secure shell, called SSH.

+

You can use your own ssh private key, or you can let Coolify to create one for you.

+

In both ways, you need to add the public version of your ssh private key to the remote + server's + ~/.ssh/authorized_keys file. +

+
+ + @endif +
+
+ @if ($currentState === 'select-existing-server') + + + There are already servers available for your Team. Do you want to use one of them? + + +
No (create a new one) +
+
+ + + @foreach ($servers as $server) + + @endforeach + + Use this Server + +
+
+ +

Private Keys are used to connect to a remote server through a secure shell, called SSH.

+

You can use your own private key, or you can let Coolify to create one for you.

+

In both ways, you need to add the public version of your private key to the remote server's + ~/.ssh/authorized_keys file. +

+
+
+ @endif +
+
+ @if ($currentState === 'create-private-key') + + + Please let me know your key details. + + +
+ + label="Description" id="privateKeyDescription" /> + + @if ($privateKeyType === 'create' && !isDev()) + Copy this to your server's ~/.ssh/authorized_keys + file. + + @endif + Save + +
+ +

Private Keys are used to connect to a remote server through a secure shell, called SSH.

+

You can use your own private key, or you can let Coolify to create one for you.

+

In both ways, you need to add the public version of your private key to the remote server's + ~/.ssh/authorized_keys file. +

+
+
+ @endif +
+
+ @if ($currentState === 'create-server') + + + Please let me know your server details. + + +
+
+ + +
+
+ + + +
+ Save +
+
+ +

Username should be for now. We are working on to use + non-root users.

+
+
+ @endif +
+
+ @if ($currentState === 'install-docker') + + + + + + + Close + + + + + + Could not find Docker Engine on your server. Do you want me to install it for you? + + +
+ Let's do + it!
+
+ +

This will install the latest Docker Engine on your server, configure a few things to be able + to run optimal.

+
+
+ @endif +
+
+ @if ($currentState === 'select-proxy') + + + If you would like to attach any kind of domain to your resources, you need a proxy. + + + + Decide later + + + Traefik + v2 + + + Nginx + + + Caddy + + + +

This will install the latest Docker Engine on your server, configure a few things to be able + to run optimal.

+
+
+ @endif +
+
+ @if ($currentState === 'create-project') + + + @if (count($projects) > 0) + You already have some projects. Do you want to use one of them or should I create a new one for + you? + @else + I will create an initial project for you. You can change all the details later on. + @endif + + +
Let's create a new one!
+
+ @if (count($projects) > 0) +
+ + @foreach ($projects as $project) + + @endforeach + + Use this Project +
+ @endif
-
- - - -
- Save - -
- -

Username should be for now. We are working on to use - non-root users.

-
-
- @endif - @if ($currentState === 'install-docker') - - - Could not find Docker Engine on your server. Do you want me to install it for you? - - -
- Let's do - it!
-
- -

This will install the latest Docker Engine on your server, configure a few things to be able - to run optimal.

-
-
- @endif - @if ($currentState === 'select-proxy') - - - If you would like to attach any kind of domain to your resources, you need a proxy. - - - - Decide later - - - Traefik - v2 - - - Nginx - - - Caddy - - - -

This will install the latest Docker Engine on your server, configure a few things to be able - to run optimal.

-
-
- @endif - @if ($currentState === 'create-project') - - - I will create an initial project for you. You can change all the details later on. - - -
Let's do it!
-
- -

Projects are bound together several resources into one virtual group. There are no - limitations on the number of projects you could have.

-

Each project should have at least one environment. This helps you to create a production & - staging version of the same application, but grouped separately.

-
-
- @endif - @if ($currentState === 'create-resource') - - - I will redirect you to the new resource page, where you can create your first resource. - - -
Let's do - it!
-
- -

A resource could be an application, a database or a service (like WordPress).

-
-
- @endif + + +

Projects are bound together several resources into one virtual group. There are no + limitations on the number of projects you could have.

+

Each project should have at least one environment. This helps you to create a production & + staging version of the same application, but grouped separately.

+
+ + @endif +
+
+ @if ($currentState === 'create-resource') + + + I will redirect you to the new resource page, where you can create your first resource. + + +
Let's do + it!
+
+ +

A resource could be an application, a database or a service (like WordPress).

+
+
+ @endif +
Skip boarding process Restart boarding process diff --git a/resources/views/livewire/server/private-key.blade.php b/resources/views/livewire/server/show-private-key.blade.php similarity index 100% rename from resources/views/livewire/server/private-key.blade.php rename to resources/views/livewire/server/show-private-key.blade.php diff --git a/resources/views/server/private-key.blade.php b/resources/views/server/private-key.blade.php index 3c42f98f0..d1b22b16c 100644 --- a/resources/views/server/private-key.blade.php +++ b/resources/views/server/private-key.blade.php @@ -1,4 +1,4 @@ - +