diff --git a/app/Models/Application.php b/app/Models/Application.php index c0fa88067..a139bc6a8 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -7,6 +7,15 @@ class Application extends BaseModel { + protected static function booted() + { + static::created(function ($application) { + ApplicationSetting::create([ + 'application_id' => $application->id, + ]); + }); + } + public function environment() { return $this->belongsTo(Environment::class); diff --git a/app/Models/ApplicationSetting.php b/app/Models/ApplicationSetting.php index d5f9b6f4e..9acad2ae9 100644 --- a/app/Models/ApplicationSetting.php +++ b/app/Models/ApplicationSetting.php @@ -6,4 +6,8 @@ class ApplicationSetting extends Model { + public function application() + { + return $this->belongsTo(Application::class); + } } diff --git a/app/Models/GithubApp.php b/app/Models/GithubApp.php index 4d461fdc4..fd7dd0775 100644 --- a/app/Models/GithubApp.php +++ b/app/Models/GithubApp.php @@ -8,4 +8,8 @@ public function applications() { return $this->morphMany(Application::class, 'source'); } + public function privateKey() + { + return $this->belongsTo(PrivateKey::class); + } } diff --git a/app/Models/GitlabApp.php b/app/Models/GitlabApp.php index 65024b3f7..ad5f658e2 100644 --- a/app/Models/GitlabApp.php +++ b/app/Models/GitlabApp.php @@ -4,4 +4,8 @@ class GitlabApp extends BaseModel { + public function privateKey() + { + return $this->belongsTo(PrivateKey::class); + } } diff --git a/app/Models/Project.php b/app/Models/Project.php index 1efe88548..1b0a71049 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -4,6 +4,14 @@ class Project extends BaseModel { + protected static function booted() + { + static::created(function ($project) { + ProjectSetting::create([ + 'project_id' => $project->id, + ]); + }); + } public function environments() { return $this->hasMany(Environment::class); } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 3487238e9..984d714cd 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -21,9 +21,11 @@ public function register(): void */ public function boot(): void { - // @TODO: Should remove builder container here - // Queue::after(function (JobProcessed $event) { - // dd($event->job->resolveName()); - // }); + Queue::after(function (JobProcessed $event) { + // @TODO: Remove `coolify-builder` container after the remoteProcess job is finishged and remoteProcess->type == `deployment`. + if ($event->job->resolveName() === 'App\Jobs\ExecuteRemoteProcess') { + + } + }); } } diff --git a/config/coolify.php b/config/coolify.php new file mode 100644 index 000000000..4c6af61d4 --- /dev/null +++ b/config/coolify.php @@ -0,0 +1,5 @@ + '4.0.0-rc.1', +]; diff --git a/database/migrations/2023_03_27_081716_create_applications_table.php b/database/migrations/2023_03_27_081716_create_applications_table.php index 57515e4fc..701a70c17 100644 --- a/database/migrations/2023_03_27_081716_create_applications_table.php +++ b/database/migrations/2023_03_27_081716_create_applications_table.php @@ -58,7 +58,6 @@ public function up(): void $table->morphs('source'); $table->foreignId('environment_id'); - $table->timestamps(); }); } diff --git a/database/seeders/ApplicationSeeder.php b/database/seeders/ApplicationSeeder.php index 91b954834..ccfa74045 100644 --- a/database/seeders/ApplicationSeeder.php +++ b/database/seeders/ApplicationSeeder.php @@ -22,6 +22,7 @@ public function run(): void $swarm_docker_1 = SwarmDocker::find(1); $github_public_source = GithubApp::find(1); + $github_private_source = GithubApp::find(2); Application::create([ 'id' => 1, 'name' => 'My first application', @@ -36,14 +37,19 @@ public function run(): void 'source_id' => $github_public_source->id, 'source_type' => GithubApp::class, ]); - // Application::create([ - // 'id' => 2, - // 'name' => 'My second application (Swarm)', - // 'environment_id' => $environment_1->id, - // 'destination_id' => $swarm_docker_1->id, - // 'destination_type' => SwarmDocker::class, - // 'source_id' => $github_public_source->id, - // 'source_type' => GithubApp::class, - // ]); + Application::create([ + 'id' => 2, + 'name' => 'My second application', + 'git_repository' => 'coollabsio/nodejs-example', + 'git_branch' => 'main', + 'build_pack' => 'nixpacks', + 'ports_exposes' => '3000', + 'ports_mappings' => '3001:3000', + 'environment_id' => $environment_1->id, + 'destination_id' => $standalone_docker_1->id, + 'destination_type' => StandaloneDocker::class, + 'source_id' => $github_private_source->id, + 'source_type' => GithubApp::class, + ]); } } diff --git a/database/seeders/ApplicationSettingsSeeder.php b/database/seeders/ApplicationSettingsSeeder.php index 760306b07..fceb32954 100644 --- a/database/seeders/ApplicationSettingsSeeder.php +++ b/database/seeders/ApplicationSettingsSeeder.php @@ -17,10 +17,10 @@ class ApplicationSettingsSeeder extends Seeder */ public function run(): void { - $application_1 = Application::find(1); - ApplicationSetting::create([ - 'id' => 1, - 'application_id' => $application_1->id, - ]); + // $application_1 = Application::find(1); + // ApplicationSetting::create([ + // 'id' => 1, + // 'application_id' => $application_1->id, + // ]); } } diff --git a/database/seeders/ProjectSettingSeeder.php b/database/seeders/ProjectSettingSeeder.php index 050982bee..8a2eddcc1 100644 --- a/database/seeders/ProjectSettingSeeder.php +++ b/database/seeders/ProjectSettingSeeder.php @@ -3,7 +3,6 @@ namespace Database\Seeders; use App\Models\Project; -use App\Models\ProjectSetting; use Illuminate\Database\Seeder; class ProjectSettingSeeder extends Seeder @@ -11,10 +10,7 @@ class ProjectSettingSeeder extends Seeder public function run(): void { $first_project = Project::find(1); - ProjectSetting::create([ - 'id' => 1, - 'wildcard_domain' => 'testing-host.localhost', - 'project_id' => $first_project->id, - ]); + $first_project->settings->wildcard_domain = 'wildcard.example.com'; + $first_project->settings->save(); } }