Add root team + localhost (coolify host) in prod seeder
This commit is contained in:
parent
06e00ffccb
commit
ff5ff7f310
@ -6,6 +6,7 @@ use App\Models\Team;
|
|||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Laravel\Fortify\Contracts\CreatesNewUsers;
|
use Laravel\Fortify\Contracts\CreatesNewUsers;
|
||||||
@ -33,23 +34,38 @@ class CreateNewUser implements CreatesNewUsers
|
|||||||
'password' => $this->passwordRules(),
|
'password' => $this->passwordRules(),
|
||||||
])->validate();
|
])->validate();
|
||||||
|
|
||||||
$team = Team::create([
|
if (User::count() == 0) {
|
||||||
'name' => explode(' ', $input['name'], 2)[0] . "'s Team",
|
// If this is the first user, make them the root user
|
||||||
'personal_team' => true,
|
// Team is already created in the database/seeders/ProductionSeeder.php
|
||||||
]);
|
$team = Team::find(0);
|
||||||
|
$user = User::create([
|
||||||
$user = User::create([
|
'id' => 0,
|
||||||
'name' => $input['name'],
|
'name' => $input['name'],
|
||||||
'email' => $input['email'],
|
'email' => $input['email'],
|
||||||
'password' => Hash::make($input['password']),
|
'password' => Hash::make($input['password']),
|
||||||
'is_root_user' => User::count() == 0 ? true : false,
|
'is_root_user' => true,
|
||||||
]);
|
]);
|
||||||
|
} else {
|
||||||
|
$team = Team::create([
|
||||||
|
'name' => explode(' ', $input['name'], 2)[0] . "'s Team",
|
||||||
|
'personal_team' => true,
|
||||||
|
]);
|
||||||
|
$user = User::create([
|
||||||
|
'name' => $input['name'],
|
||||||
|
'email' => $input['email'],
|
||||||
|
'password' => Hash::make($input['password']),
|
||||||
|
'is_root_user' => false,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add user to team
|
||||||
DB::table('team_user')->insert([
|
DB::table('team_user')->insert([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'team_id' => $team->id,
|
'team_id' => $team->id,
|
||||||
'role' => 'admin',
|
'role' => 'admin',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Set session variable
|
||||||
session(['currentTeam' => $user->currentTeam = $team]);
|
session(['currentTeam' => $user->currentTeam = $team]);
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,11 @@ class HomeController extends Controller
|
|||||||
public function show()
|
public function show()
|
||||||
{
|
{
|
||||||
$projects = session('currentTeam')->load(['projects'])->projects;
|
$projects = session('currentTeam')->load(['projects'])->projects;
|
||||||
return view('home', ['projects' => $projects]);
|
$servers = session('currentTeam')->load(['servers'])->servers;
|
||||||
|
|
||||||
|
return view('home', [
|
||||||
|
'servers' => $servers,
|
||||||
|
'projects' => $projects
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ class Team extends BaseModel
|
|||||||
'personal_team' => 'boolean',
|
'personal_team' => 'boolean',
|
||||||
];
|
];
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
|
'id',
|
||||||
'name',
|
'name',
|
||||||
'personal_team'
|
'personal_team'
|
||||||
];
|
];
|
||||||
|
@ -19,6 +19,7 @@ class User extends Authenticatable
|
|||||||
* @var array<int, string>
|
* @var array<int, string>
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
|
'id',
|
||||||
'name',
|
'name',
|
||||||
'email',
|
'email',
|
||||||
'password',
|
'password',
|
||||||
|
@ -15,7 +15,7 @@ class GithubAppSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
$root_team = Team::find(1);
|
$root_team = Team::find(0);
|
||||||
$private_key_1 = PrivateKey::find(1);
|
$private_key_1 = PrivateKey::find(1);
|
||||||
$private_key_2 = PrivateKey::find(2);
|
$private_key_2 = PrivateKey::find(2);
|
||||||
GithubApp::create([
|
GithubApp::create([
|
||||||
|
@ -15,7 +15,7 @@ class GitlabAppSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
$root_team = Team::find(1);
|
$root_team = Team::find(0);
|
||||||
$private_key_3 = PrivateKey::find(3);
|
$private_key_3 = PrivateKey::find(3);
|
||||||
GitlabApp::create([
|
GitlabApp::create([
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
|
@ -4,6 +4,7 @@ namespace Database\Seeders;
|
|||||||
|
|
||||||
use App\Models\PrivateKey;
|
use App\Models\PrivateKey;
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
|
use App\Models\Server;
|
||||||
use App\Models\Team;
|
use App\Models\Team;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
@ -12,6 +13,7 @@ class ProductionSeeder extends Seeder
|
|||||||
{
|
{
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
|
// Save SSH Keys for the Coolify Host
|
||||||
$coolify_key_name = "id.root@host.docker.internal";
|
$coolify_key_name = "id.root@host.docker.internal";
|
||||||
$coolify_key = Storage::disk('local')->get("ssh-keys/{$coolify_key_name}");
|
$coolify_key = Storage::disk('local')->get("ssh-keys/{$coolify_key_name}");
|
||||||
$coolify_key_in_database = PrivateKey::where('name', 'Coolify Host');
|
$coolify_key_in_database = PrivateKey::where('name', 'Coolify Host');
|
||||||
@ -21,10 +23,32 @@ class ProductionSeeder extends Seeder
|
|||||||
}
|
}
|
||||||
if ($coolify_key && !$coolify_key_in_database->exists()) {
|
if ($coolify_key && !$coolify_key_in_database->exists()) {
|
||||||
PrivateKey::create([
|
PrivateKey::create([
|
||||||
'name' => 'Coolify Host',
|
'id' => 0,
|
||||||
'description' => 'The private key for the Coolify host machine.',
|
'name' => 'localhost\'s key',
|
||||||
|
'description' => 'The private key for the Coolify host machine (localhost).',
|
||||||
'private_key' => $coolify_key,
|
'private_key' => $coolify_key,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add first Team if it doesn't exist
|
||||||
|
if (Team::find(0) == null) {
|
||||||
|
Team::create([
|
||||||
|
'id' => 0,
|
||||||
|
'name' => "Root's Team",
|
||||||
|
'personal_team' => true,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
// Add Coolify host (localhost) as Server if it doesn't exist
|
||||||
|
if (Server::find(0) == null) {
|
||||||
|
Server::create([
|
||||||
|
'id' => 0,
|
||||||
|
'name' => "localhost",
|
||||||
|
'description' => "This is the local machine",
|
||||||
|
'user' => 'root',
|
||||||
|
'ip' => "host.docker.internal",
|
||||||
|
'team_id' => 0,
|
||||||
|
'private_key_id' => 0,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ class ProjectSeeder extends Seeder
|
|||||||
{
|
{
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
$root_team = Team::find(1);
|
$root_team = Team::find(0);
|
||||||
Project::create([
|
Project::create([
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
'name' => "My first project",
|
'name' => "My first project",
|
||||||
|
@ -14,10 +14,10 @@ class ServerSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
$root_team = Team::find(1);
|
$root_team = Team::find(0);
|
||||||
$private_key_1 = PrivateKey::find(1);
|
$private_key_1 = PrivateKey::find(1);
|
||||||
Server::create([
|
Server::create([
|
||||||
'id' => 1,
|
'id' => 0,
|
||||||
'name' => "localhost",
|
'name' => "localhost",
|
||||||
'description' => "This is the local machine",
|
'description' => "This is the local machine",
|
||||||
'user' => 'root',
|
'user' => 'root',
|
||||||
@ -26,7 +26,7 @@ class ServerSeeder extends Seeder
|
|||||||
'private_key_id' => $private_key_1->id,
|
'private_key_id' => $private_key_1->id,
|
||||||
]);
|
]);
|
||||||
Server::create([
|
Server::create([
|
||||||
'id' => 2,
|
'id' => 1,
|
||||||
'name' => "testing-local-docker-container",
|
'name' => "testing-local-docker-container",
|
||||||
'description' => "This is a test docker container",
|
'description' => "This is a test docker container",
|
||||||
'ip' => "coolify-testing-host",
|
'ip' => "coolify-testing-host",
|
||||||
@ -34,7 +34,7 @@ class ServerSeeder extends Seeder
|
|||||||
'private_key_id' => $private_key_1->id,
|
'private_key_id' => $private_key_1->id,
|
||||||
]);
|
]);
|
||||||
Server::create([
|
Server::create([
|
||||||
'id' => 3,
|
'id' => 2,
|
||||||
'name' => "testing-local-docker-container-2",
|
'name' => "testing-local-docker-container-2",
|
||||||
'description' => "This is a test docker container",
|
'description' => "This is a test docker container",
|
||||||
'ip' => "coolify-testing-host-2",
|
'ip' => "coolify-testing-host-2",
|
||||||
|
@ -15,11 +15,11 @@ class StandaloneDockerSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
$server_1 = Server::find(1);
|
$server_0 = Server::find(0);
|
||||||
StandaloneDocker::create([
|
StandaloneDocker::create([
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
'network' => 'coolify',
|
'network' => 'coolify',
|
||||||
'server_id' => $server_1->id,
|
'server_id' => $server_0->id,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,10 @@ class SwarmDockerSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
$server_2 = Server::find(2);
|
$server_1 = Server::find(1);
|
||||||
SwarmDocker::create([
|
SwarmDocker::create([
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
'server_id' => $server_2->id,
|
'server_id' => $server_1->id,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ class TeamSeeder extends Seeder
|
|||||||
$normal_user = User::find(2);
|
$normal_user = User::find(2);
|
||||||
|
|
||||||
$root_user_personal_team = Team::create([
|
$root_user_personal_team = Team::create([
|
||||||
|
'id' => 0,
|
||||||
'name' => "Root Team",
|
'name' => "Root Team",
|
||||||
'personal_team' => true,
|
'personal_team' => true,
|
||||||
]);
|
]);
|
||||||
@ -27,7 +28,7 @@ class TeamSeeder extends Seeder
|
|||||||
'personal_team' => true,
|
'personal_team' => true,
|
||||||
]);
|
]);
|
||||||
DB::table('team_user')->insert([
|
DB::table('team_user')->insert([
|
||||||
'team_id' => $root_user_personal_team->id,
|
'team_id' => $root_user_personal_team->id,
|
||||||
'user_id' => $root_user->id,
|
'user_id' => $root_user->id,
|
||||||
'role' => 'admin',
|
'role' => 'admin',
|
||||||
]);
|
]);
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<x-layout>
|
<x-layout>
|
||||||
<form action="/register" method="POST">
|
<form action="/register" method="POST">
|
||||||
@csrf
|
@csrf
|
||||||
<input type="text" name="name" placeholder="name" @env('local') value="Andras Bacsai" @endenv />
|
<input type="text" name="name" placeholder="name" @env('local') value="Root" @endenv />
|
||||||
<input type="text" name="email" placeholder="email" @env('local') value="andras@bacsai.com" @endenv />
|
<input type="text" name="email" placeholder="email" @env('local') value="test@example.com" @endenv />
|
||||||
<input type="password" name="password" placeholder="Password" @env('local') value="password" @endenv />
|
<input type="password" name="password" placeholder="Password" @env('local') value="password" @endenv />
|
||||||
<input type="password" name="password_confirmation" placeholder="Password"
|
<input type="password" name="password_confirmation" placeholder="Password"
|
||||||
@env('local') value="password" @endenv />
|
@env('local') value="password" @endenv />
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
<x-layout>
|
<x-layout>
|
||||||
|
<h1>Servers</h1>
|
||||||
|
@forelse ($servers as $server)
|
||||||
|
<a href="{{ route('project.environments', [$server->uuid]) }}">{{ data_get($server, 'name') }}</a>
|
||||||
|
@empty
|
||||||
|
<p>No projects found.</p>
|
||||||
|
@endforelse
|
||||||
<h1>Projects</h1>
|
<h1>Projects</h1>
|
||||||
@forelse ($projects as $project)
|
@forelse ($projects as $project)
|
||||||
<a href="{{ route('project.environments', [$project->uuid]) }}">{{ data_get($project, 'name') }}</a>
|
<a href="{{ route('project.environments', [$project->uuid]) }}">{{ data_get($project, 'name') }}</a>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user