Skip to content

Commit b39ca51

Browse files
committed
wip: boarding
1 parent 2414ddd commit b39ca51

File tree

71 files changed

+694
-137
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+694
-137
lines changed

.ssh/known_hosts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
|1|TRkudHmvsBVekjyAfpo3EWrkQSs=|XdMLpIt2l32hhdSyWnDwMMlVBSI= ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIK/Ln1b72Lc5JtHRDiZd4lYyW7F5aVuJH42HdHXuYudT

app/Actions/Server/UpdateCoolify.php

-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ public function __invoke(bool $force)
1717
$settings = InstanceSettings::get();
1818
ray('Running InstanceAutoUpdateJob');
1919
$localhost_name = 'localhost';
20-
if (is_dev()) {
21-
$localhost_name = 'testing-local-docker-container';
22-
}
2320
$this->server = Server::where('name', $localhost_name)->firstOrFail();
2421
$this->latest_version = get_latest_version_of_coolify();
2522
$this->current_version = config('version');

app/Http/Controllers/ApplicationController.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ApplicationController extends Controller
1212

1313
public function configuration()
1414
{
15-
$project = auth()->user()->currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
15+
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
1616
if (!$project) {
1717
return redirect()->route('dashboard');
1818
}
@@ -29,7 +29,7 @@ public function configuration()
2929

3030
public function deployments()
3131
{
32-
$project = auth()->user()->currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
32+
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
3333
if (!$project) {
3434
return redirect()->route('dashboard');
3535
}
@@ -49,7 +49,7 @@ public function deployment()
4949
{
5050
$deploymentUuid = request()->route('deployment_uuid');
5151

52-
$project = auth()->user()->currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
52+
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
5353
if (!$project) {
5454
return redirect()->route('dashboard');
5555
}

app/Http/Controllers/Controller.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,24 @@ public function dashboard()
5858
$resources += $project->applications->count();
5959
$resources += $project->postgresqls->count();
6060
}
61-
6261
return view('dashboard', [
6362
'servers' => $servers->count(),
6463
'projects' => $projects->count(),
6564
'resources' => $resources,
6665
's3s' => $s3s,
6766
]);
6867
}
68+
public function boarding() {
69+
if (currentTeam()->boarding || is_dev()) {
70+
return view('boarding');
71+
} else {
72+
return redirect()->route('dashboard');
73+
}
74+
}
6975

7076
public function settings()
7177
{
72-
if (is_instance_admin()) {
78+
if (isInstanceAdmin()) {
7379
$settings = InstanceSettings::get();
7480
$database = StandalonePostgresql::whereName('coolify-db')->first();
7581
if ($database) {
@@ -89,7 +95,7 @@ public function team()
8995
{
9096
$invitations = [];
9197
if (auth()->user()->isAdminFromSession()) {
92-
$invitations = TeamInvitation::whereTeamId(auth()->user()->currentTeam()->id)->get();
98+
$invitations = TeamInvitation::whereTeamId(currentTeam()->id)->get();
9399
}
94100
return view('team.show', [
95101
'invitations' => $invitations,
@@ -116,7 +122,7 @@ public function members()
116122
{
117123
$invitations = [];
118124
if (auth()->user()->isAdminFromSession()) {
119-
$invitations = TeamInvitation::whereTeamId(auth()->user()->currentTeam()->id)->get();
125+
$invitations = TeamInvitation::whereTeamId(currentTeam()->id)->get();
120126
}
121127
return view('team.members', [
122128
'invitations' => $invitations,

app/Http/Controllers/DatabaseController.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class DatabaseController extends Controller
1111

1212
public function configuration()
1313
{
14-
$project = auth()->user()->currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
14+
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
1515
if (!$project) {
1616
return redirect()->route('dashboard');
1717
}
@@ -29,7 +29,7 @@ public function configuration()
2929
public function executions()
3030
{
3131
$backup_uuid = request()->route('backup_uuid');
32-
$project = auth()->user()->currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
32+
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
3333
if (!$project) {
3434
return redirect()->route('dashboard');
3535
}
@@ -50,13 +50,13 @@ public function executions()
5050
'database' => $database,
5151
'backup' => $backup,
5252
'executions' => $executions,
53-
's3s' => auth()->user()->currentTeam()->s3s,
53+
's3s' => currentTeam()->s3s,
5454
]);
5555
}
5656

5757
public function backups()
5858
{
59-
$project = auth()->user()->currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
59+
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
6060
if (!$project) {
6161
return redirect()->route('dashboard');
6262
}
@@ -70,7 +70,7 @@ public function backups()
7070
}
7171
return view('project.database.backups.all', [
7272
'database' => $database,
73-
's3s' => auth()->user()->currentTeam()->s3s,
73+
's3s' => currentTeam()->s3s,
7474
]);
7575
}
7676
}

app/Http/Controllers/MagicController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function newProject()
4141
{
4242
$project = Project::firstOrCreate(
4343
['name' => request()->query('name') ?? generate_random_name()],
44-
['team_id' => auth()->user()->currentTeam()->id]
44+
['team_id' => currentTeam()->id]
4545
);
4646
return response()->json([
4747
'project_uuid' => $project->uuid
@@ -68,7 +68,7 @@ public function newTeam()
6868
],
6969
);
7070
auth()->user()->teams()->attach($team, ['role' => 'admin']);
71-
session(['currentTeam' => $team]);
71+
refreshSession();
7272
return redirect(request()->header('Referer'));
7373
}
7474
}

app/Http/Controllers/ProjectController.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function all()
1818
public function edit()
1919
{
2020
$projectUuid = request()->route('project_uuid');
21-
$teamId = auth()->user()->currentTeam()->id;
21+
$teamId = currentTeam()->id;
2222
$project = Project::where('team_id', $teamId)->where('uuid', $projectUuid)->first();
2323
if (!$project) {
2424
return redirect()->route('dashboard');
@@ -29,7 +29,7 @@ public function edit()
2929
public function show()
3030
{
3131
$projectUuid = request()->route('project_uuid');
32-
$teamId = auth()->user()->currentTeam()->id;
32+
$teamId = currentTeam()->id;
3333

3434
$project = Project::where('team_id', $teamId)->where('uuid', $projectUuid)->first();
3535
if (!$project) {
@@ -44,7 +44,7 @@ public function new()
4444
$type = request()->query('type');
4545
$destination_uuid = request()->query('destination');
4646

47-
$project = auth()->user()->currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
47+
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
4848
if (!$project) {
4949
return redirect()->route('dashboard');
5050
}
@@ -67,7 +67,7 @@ public function new()
6767

6868
public function resources()
6969
{
70-
$project = auth()->user()->currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
70+
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
7171
if (!$project) {
7272
return redirect()->route('dashboard');
7373
}

app/Http/Controllers/ServerController.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ class ServerController extends Controller
1212

1313
public function new_server()
1414
{
15-
if (!is_cloud() || is_instance_admin()) {
15+
if (!is_cloud() || isInstanceAdmin()) {
1616
return view('server.create', [
1717
'limit_reached' => false,
1818
'private_keys' => PrivateKey::ownedByCurrentTeam()->get(),
1919
]);
2020
}
21-
$servers = auth()->user()->currentTeam()->servers->count();
22-
$subscription = auth()->user()->currentTeam()?->subscription->type();
21+
$servers = currentTeam()->servers->count();
22+
$subscription = currentTeam()?->subscription->type();
2323
$your_limit = config('constants.limits.server')[strtolower($subscription)];
2424
$limit_reached = $servers >= $your_limit;
2525

app/Http/Kernel.php

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Kernel extends HttpKernel
3939
\Illuminate\Routing\Middleware\SubstituteBindings::class,
4040
\App\Http\Middleware\CheckForcePasswordReset::class,
4141
\App\Http\Middleware\SubscriptionValid::class,
42+
\App\Http\Middleware\IsBoardingFlow::class,
4243

4344
],
4445

app/Http/Livewire/Boarding.php

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<?php
2+
3+
namespace App\Http\Livewire;
4+
5+
use App\Models\PrivateKey;
6+
use App\Models\Project;
7+
use App\Models\Server;
8+
use Livewire\Component;
9+
10+
class Boarding extends Component
11+
{
12+
13+
public string $currentState = 'create-private-key';
14+
// public ?string $serverType = null;
15+
16+
public ?string $privateKeyType = null;
17+
public ?string $privateKey = null;
18+
public ?string $privateKeyName = null;
19+
public ?string $privateKeyDescription = null;
20+
public ?PrivateKey $createdPrivateKey = null;
21+
22+
public ?string $remoteServerName = null;
23+
public ?string $remoteServerDescription = null;
24+
public ?string $remoteServerHost = null;
25+
public ?int $remoteServerPort = 22;
26+
public ?string $remoteServerUser = 'root';
27+
public ?Server $createdServer = null;
28+
29+
public function mount()
30+
{
31+
$this->privateKeyName = generate_random_name();
32+
$this->remoteServerName = generate_random_name();
33+
if (is_dev()) {
34+
$this->privateKey = '-----BEGIN OPENSSH PRIVATE KEY-----
35+
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
36+
QyNTUxOQAAACBbhpqHhqv6aI67Mj9abM3DVbmcfYhZAhC7ca4d9UCevAAAAJi/QySHv0Mk
37+
hwAAAAtzc2gtZWQyNTUxOQAAACBbhpqHhqv6aI67Mj9abM3DVbmcfYhZAhC7ca4d9UCevA
38+
AAAECBQw4jg1WRT2IGHMncCiZhURCts2s24HoDS0thHnnRKVuGmoeGq/pojrsyP1pszcNV
39+
uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA==
40+
-----END OPENSSH PRIVATE KEY-----';
41+
$this->privateKeyDescription = 'Created by Coolify';
42+
$this->remoteServerDescription = 'Created by Coolify';
43+
$this->remoteServerHost = 'coolify-testing-host';
44+
}
45+
}
46+
public function restartBoarding()
47+
{
48+
if ($this->createdServer) {
49+
$this->createdServer->delete();
50+
}
51+
if ($this->createdPrivateKey) {
52+
$this->createdPrivateKey->delete();
53+
}
54+
return redirect()->route('boarding');
55+
}
56+
public function skipBoarding()
57+
{
58+
currentTeam()->update([
59+
'show_boarding' => false
60+
]);
61+
refreshSession();
62+
return redirect()->route('dashboard');
63+
}
64+
public function setServer(string $type)
65+
{
66+
if ($type === 'localhost') {
67+
$this->currentState = 'create-project';
68+
} elseif ($type === 'remote') {
69+
$this->currentState = 'private-key';
70+
}
71+
}
72+
public function setPrivateKey(string $type)
73+
{
74+
$this->privateKeyType = $type;
75+
$this->currentState = 'create-private-key';
76+
}
77+
public function savePrivateKey()
78+
{
79+
$this->validate([
80+
'privateKeyName' => 'required',
81+
'privateKey' => 'required',
82+
]);
83+
$this->currentState = 'create-server';
84+
}
85+
public function saveServer()
86+
{
87+
$this->validate([
88+
'remoteServerName' => 'required',
89+
'remoteServerHost' => 'required',
90+
'remoteServerPort' => 'required',
91+
'remoteServerUser' => 'required',
92+
]);
93+
if ($this->privateKeyType === 'create') {
94+
$this->createNewPrivateKey();
95+
}
96+
$this->privateKey = formatPrivateKey($this->privateKey);
97+
$this->createdPrivateKey = PrivateKey::create([
98+
'name' => $this->privateKeyName,
99+
'description' => $this->privateKeyDescription,
100+
'private_key' => $this->privateKey,
101+
'team_id' => currentTeam()->id
102+
]);
103+
$this->createdServer = Server::create([
104+
'name' => $this->remoteServerName,
105+
'ip' => $this->remoteServerHost,
106+
'port' => $this->remoteServerPort,
107+
'user' => $this->remoteServerUser,
108+
'description' => $this->remoteServerDescription,
109+
'private_key_id' => $this->createdPrivateKey->id,
110+
'team_id' => currentTeam()->id
111+
]);
112+
try {
113+
['uptime' => $uptime, 'dockerVersion' => $dockerVersion] = validateServer($this->createdServer);
114+
if (!$uptime) {
115+
$this->createdServer->delete();
116+
$this->createdPrivateKey->delete();
117+
throw new \Exception('Server is not reachable.');
118+
} else {
119+
$this->createdServer->settings->update([
120+
'is_reachable' => true,
121+
]);
122+
$this->emit('success', 'Server is reachable.');
123+
}
124+
if ($dockerVersion) {
125+
$this->emit('error', 'Docker is not installed on the server.');
126+
$this->currentState = 'install-docker';
127+
return;
128+
}
129+
ray($uptime, $dockerVersion);
130+
} catch (\Exception $e) {
131+
return general_error_handler(customErrorMessage: "Server is not reachable. Reason: {$e->getMessage()}", that: $this);
132+
}
133+
}
134+
private function createNewPrivateKey()
135+
{
136+
$this->privateKeyName = generate_random_name();
137+
$this->privateKeyDescription = 'Created by Coolify';
138+
$this->privateKey = generateSSHKey();
139+
}
140+
public function createNewProject()
141+
{
142+
Project::create([
143+
'name' => generate_random_name(),
144+
'team_id' => currentTeam()->id
145+
]);
146+
}
147+
}

app/Http/Livewire/Destination/New/StandaloneDocker.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function submit()
6767
'name' => $this->name,
6868
'network' => $this->network,
6969
'server_id' => $this->server_id,
70-
'team_id' => auth()->user()->currentTeam()->id
70+
'team_id' => currentTeam()->id
7171
]);
7272
}
7373
$this->createNetworkAndAttachToProxy();

app/Http/Livewire/Notifications/DiscordSettings.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ public function submit()
4141

4242
public function saveModel()
4343
{
44-
ray($this->model);
4544
$this->model->save();
4645
if (is_a($this->model, Team::class)) {
47-
session(['currentTeam' => $this->model]);
46+
refreshSession();
4847
}
4948
$this->emit('success', 'Settings saved.');
5049
}

0 commit comments

Comments
 (0)