From 54441ddfdec51c5705338f924e50e97a63bc2f04 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 28 Mar 2023 12:09:34 +0200 Subject: [PATCH] Add GitHub, GitLab, DeployKeys --- app/Models/Application.php | 4 ++ app/Models/GitDeployKey.php | 7 +++ app/Models/GithubApp.php | 11 +++++ app/Models/GitlabApp.php | 7 +++ app/Models/Kubernetes.php | 6 +-- ...03_27_081716_create_applications_table.php | 1 + ...85020_create_standalone_dockers_table.php} | 0 ..._27_085022_create_swarm_dockers_table.php} | 0 ...3_03_28_062150_create_kubernetes_table.php | 2 + ..._03_28_083723_create_github_apps_table.php | 46 +++++++++++++++++ ..._03_28_083726_create_gitlab_apps_table.php | 49 +++++++++++++++++++ ...28_100003_create_git_deploy_keys_table.php | 31 ++++++++++++ database/seeders/ApplicationSeeder.php | 6 +++ database/seeders/DatabaseSeeder.php | 35 +++++++------ database/seeders/GitDeployKeySeeder.php | 17 +++++++ database/seeders/GithubAppSeeder.php | 43 ++++++++++++++++ database/seeders/GitlabAppSeeder.php | 43 ++++++++++++++++ database/seeders/PrivateKeySeeder.php | 39 +++++++++++++++ database/seeders/ServerSeeder.php | 2 +- resources/views/home.blade.php | 1 + 20 files changed, 326 insertions(+), 24 deletions(-) create mode 100644 app/Models/GitDeployKey.php create mode 100644 app/Models/GithubApp.php create mode 100644 app/Models/GitlabApp.php rename database/migrations/{2023_03_27_085022_create_standalone_dockers_table.php => 2023_03_27_085020_create_standalone_dockers_table.php} (100%) rename database/migrations/{2023_03_27_085023_create_swarm_dockers_table.php => 2023_03_27_085022_create_swarm_dockers_table.php} (100%) create mode 100644 database/migrations/2023_03_28_083723_create_github_apps_table.php create mode 100644 database/migrations/2023_03_28_083726_create_gitlab_apps_table.php create mode 100644 database/migrations/2023_03_28_100003_create_git_deploy_keys_table.php create mode 100644 database/seeders/GitDeployKeySeeder.php create mode 100644 database/seeders/GithubAppSeeder.php create mode 100644 database/seeders/GitlabAppSeeder.php diff --git a/app/Models/Application.php b/app/Models/Application.php index 875a6c790..8f8c4391b 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -12,4 +12,8 @@ public function destination() { return $this->morphTo(); } + public function source() + { + return $this->morphTo(); + } } diff --git a/app/Models/GitDeployKey.php b/app/Models/GitDeployKey.php new file mode 100644 index 000000000..f487f37c5 --- /dev/null +++ b/app/Models/GitDeployKey.php @@ -0,0 +1,7 @@ +morphMany(Application::class, 'source'); + } +} diff --git a/app/Models/GitlabApp.php b/app/Models/GitlabApp.php new file mode 100644 index 000000000..65024b3f7 --- /dev/null +++ b/app/Models/GitlabApp.php @@ -0,0 +1,7 @@ +string('name'); $table->morphs('destination'); + $table->morphs('source'); $table->foreignId('environment_id'); $table->timestamps(); diff --git a/database/migrations/2023_03_27_085022_create_standalone_dockers_table.php b/database/migrations/2023_03_27_085020_create_standalone_dockers_table.php similarity index 100% rename from database/migrations/2023_03_27_085022_create_standalone_dockers_table.php rename to database/migrations/2023_03_27_085020_create_standalone_dockers_table.php diff --git a/database/migrations/2023_03_27_085023_create_swarm_dockers_table.php b/database/migrations/2023_03_27_085022_create_swarm_dockers_table.php similarity index 100% rename from database/migrations/2023_03_27_085023_create_swarm_dockers_table.php rename to database/migrations/2023_03_27_085022_create_swarm_dockers_table.php diff --git a/database/migrations/2023_03_28_062150_create_kubernetes_table.php b/database/migrations/2023_03_28_062150_create_kubernetes_table.php index 42ef4770a..365380e1f 100644 --- a/database/migrations/2023_03_28_062150_create_kubernetes_table.php +++ b/database/migrations/2023_03_28_062150_create_kubernetes_table.php @@ -13,6 +13,8 @@ public function up(): void { Schema::create('kubernetes', function (Blueprint $table) { $table->id(); + $table->string('uuid')->unique(); + $table->timestamps(); }); } diff --git a/database/migrations/2023_03_28_083723_create_github_apps_table.php b/database/migrations/2023_03_28_083723_create_github_apps_table.php new file mode 100644 index 000000000..049c8f366 --- /dev/null +++ b/database/migrations/2023_03_28_083723_create_github_apps_table.php @@ -0,0 +1,46 @@ +id(); + $table->string('uuid')->unique(); + $table->string('name'); + + $table->string('organization')->nullable(); + $table->string('api_url'); + $table->string('html_url'); + $table->integer('custom_port')->default(22); + $table->string('custom_user')->default('git'); + $table->boolean('is_system_wide')->default(false); + $table->boolean('is_public')->default(false); + + $table->integer('app_id')->nullable(); + $table->integer('installation_id')->nullable(); + $table->string('client_id')->nullable(); + $table->longText('client_secret')->nullable(); + $table->longText('webhook_secret')->nullable(); + + $table->foreignId('private_key_id')->nullable(); + $table->foreignId('team_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('github_apps'); + } +}; diff --git a/database/migrations/2023_03_28_083726_create_gitlab_apps_table.php b/database/migrations/2023_03_28_083726_create_gitlab_apps_table.php new file mode 100644 index 000000000..24db88d86 --- /dev/null +++ b/database/migrations/2023_03_28_083726_create_gitlab_apps_table.php @@ -0,0 +1,49 @@ +id(); + $table->string('uuid')->unique(); + $table->string('name'); + + $table->string('organization')->nullable(); + $table->string('api_url'); + $table->string('html_url'); + $table->integer('custom_port')->default(22); + $table->string('custom_user')->default('git'); + $table->boolean('is_system_wide')->default(false); + $table->boolean('is_public')->default(false); + + $table->integer('app_id')->nullable(); + $table->string('app_secret')->nullable(); + $table->integer('oauth_id')->nullable(); + $table->string('group_name')->nullable(); + $table->longText('public_key')->nullable(); + $table->longText('webhook_token')->nullable(); + $table->integer('deploy_key_id')->nullable(); + + $table->foreignId('private_key_id')->nullable(); + $table->foreignId('team_id'); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('gitlab_apps'); + } +}; diff --git a/database/migrations/2023_03_28_100003_create_git_deploy_keys_table.php b/database/migrations/2023_03_28_100003_create_git_deploy_keys_table.php new file mode 100644 index 000000000..0f22aa97e --- /dev/null +++ b/database/migrations/2023_03_28_100003_create_git_deploy_keys_table.php @@ -0,0 +1,31 @@ +id(); + $table->string('uuid')->unique(); + $table->string('url'); + + $table->foreignId('private_key_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('git_deploy_keys'); + } +}; diff --git a/database/seeders/ApplicationSeeder.php b/database/seeders/ApplicationSeeder.php index ded229b65..6436edeef 100644 --- a/database/seeders/ApplicationSeeder.php +++ b/database/seeders/ApplicationSeeder.php @@ -4,6 +4,7 @@ use App\Models\Application; use App\Models\Environment; +use App\Models\GithubApp; use App\Models\StandaloneDocker; use App\Models\SwarmDocker; use Illuminate\Database\Seeder; @@ -19,12 +20,15 @@ public function run(): void $standalone_docker_1 = StandaloneDocker::find(1); $swarm_docker_1 = SwarmDocker::find(1); + $github_public_source = GithubApp::find(1); Application::create([ 'id' => 1, 'name' => 'My first application', 'environment_id' => $environment_1->id, 'destination_id' => $standalone_docker_1->id, 'destination_type' => StandaloneDocker::class, + 'source_id' => $github_public_source->id, + 'source_type' => GithubApp::class, ]); Application::create([ 'id' => 2, @@ -32,6 +36,8 @@ public function run(): void '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, ]); } } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 674153fd0..c2bf8ac21 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -2,29 +2,28 @@ namespace Database\Seeders; -use App\Models\StandaloneDocker; use Illuminate\Database\Seeder; class DatabaseSeeder extends Seeder { public function run(): void { - if (env('APP_ENV') === 'local') { - $this->call([ - UserSeeder::class, - TeamSeeder::class, - PrivateKeySeeder::class, - ServerSeeder::class, - ProjectSeeder::class, - ProjectSettingSeeder::class, - EnvironmentSeeder::class, - StandaloneDockerSeeder::class, - SwarmDockerSeeder::class, - KubernetesSeeder::class, - ApplicationSeeder::class, - DBSeeder::class, - ServiceSeeder::class, - ]); - } + $this->call([ + UserSeeder::class, + TeamSeeder::class, + PrivateKeySeeder::class, + ServerSeeder::class, + ProjectSeeder::class, + ProjectSettingSeeder::class, + EnvironmentSeeder::class, + StandaloneDockerSeeder::class, + SwarmDockerSeeder::class, + KubernetesSeeder::class, + GithubAppSeeder::class, + GitlabAppSeeder::class, + ApplicationSeeder::class, + DBSeeder::class, + ServiceSeeder::class, + ]); } } diff --git a/database/seeders/GitDeployKeySeeder.php b/database/seeders/GitDeployKeySeeder.php new file mode 100644 index 000000000..ecbcb5653 --- /dev/null +++ b/database/seeders/GitDeployKeySeeder.php @@ -0,0 +1,17 @@ + 1, + 'name' => 'Public GitHub', + 'api_url' => 'https://api.github.com', + 'html_url' => 'https://github.com', + 'is_public' => true, + 'team_id' => $root_team->id, + ]); + GithubApp::create([ + 'id' => 2, + 'name' => 'coolify-laravel-development-private-github', + 'api_url' => 'https://api.github.com', + 'html_url' => 'https://github.com', + 'is_public' => false, + 'app_id' => 292941, + 'installation_id' => 34157139, + 'client_id' => 'Iv1.220e564d2b0abd8c', + 'client_secret' => '96b1b31f36ce0a34386d11798ff35b9b6d8aba3a', + 'webhook_secret' => '326a47b49054f03288f800d81247ec9414d0abf3', + 'private_key_id' => $private_key_2->id, + 'team_id' => $root_team->id, + ]); + } +} diff --git a/database/seeders/GitlabAppSeeder.php b/database/seeders/GitlabAppSeeder.php new file mode 100644 index 000000000..92da014a7 --- /dev/null +++ b/database/seeders/GitlabAppSeeder.php @@ -0,0 +1,43 @@ + 1, + 'name' => 'Public GitLab', + 'api_url' => 'https://gitlab.com/api/v4', + 'html_url' => 'https://gitlab.com', + 'is_public' => true, + 'team_id' => $root_team->id, + ]); + GitlabApp::create([ + 'id' => 2, + 'name' => 'coolify-laravel-development-private-gitlab', + 'api_url' => 'https://gitlab.com/api/v4', + 'html_url' => 'https://gitlab.com', + 'app_id' => 1234, + 'app_secret' => '1234', + 'oauth_id' => 1234, + 'deploy_key_id' => '1234', + 'public_key' => 'dfjasiourj', + 'webhook_token' => '4u3928u4y392', + 'private_key_id' => $private_key_3->id, + 'team_id' => $root_team->id, + ]); + } +} diff --git a/database/seeders/PrivateKeySeeder.php b/database/seeders/PrivateKeySeeder.php index 554d949e7..b54a07f6b 100644 --- a/database/seeders/PrivateKeySeeder.php +++ b/database/seeders/PrivateKeySeeder.php @@ -15,6 +15,7 @@ class PrivateKeySeeder extends Seeder public function run(): void { PrivateKey::create([ + "id" => 1, "name" => "Testing-host", "description" => "This is a test docker container", "private_key" => "-----BEGIN OPENSSH PRIVATE KEY----- @@ -26,5 +27,43 @@ public function run(): void -----END OPENSSH PRIVATE KEY----- " ]); + PrivateKey::create([ + "id" => 2, + "name" => "development-github-app", + "description" => "This is the key for using the development GitHub app", + "private_key" => "-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAstJo/SfYh3tquc2BA29a1X3pdPpXazRgtKsb5fHOwQs1rE04 +VyJYW6QCToSH4WS1oKt6iI4ma4uivn8rnkZFdw3mpcLp2ofcoeV3YPKX6pN/RiJC +if+g8gCaFywOxy2pjXOLPZeFJSXFqc4UOymbhESUyDnMfk4/RvnubMiv3jINo4Ow +4Tv7tRzAdMlMrx3hEhi142oQuyl1kc4WQOM9cAV0bd+62ga3EYSnsWTnC9AaFtWk +eGC5w/7knHJ5QZ9tKApkG3/29vJXY7WwCRUROEHqkvQhRDP0uqRPBdR48iG87Dwq +ePa6TodkFaVfyHS/OUZzRiTn6MOSyQQFg0QIIwIDAQABAoIBAQCsmGebSJU2lwl4 +0oAeZ6E9hG0LagFsSL66QpkHxO9w5bflWRbzCwRLVy6eyE46XzDrJfd7y/ALR1hK +E4ZvGpY7heBDx7BdK1rprAggO6YjVD+42qJsfZ3DVo9jpDOTTWBkVcxkI1Xwd9ej +wHNIcy1WabdM1nSoyC9M+ziEKOOOShXc5Q6e+zEzSBbwjc1fvvXZOH4VXZZ1DllE +xGu0jFS23TLnXATxh8SdfYgnvfZgB5n72P9m/lj3FmkuJq57DLZhBwN3Zd4wom03 +K7/J4K2Ssnjdv/HjVgrRgpMv7oMxfclN/Aiq878Ue4Mav6LjnLENyHbyR0WxQjY6 +lZ7UMEeJAoGBAOCGepk3rCMFa3a6GagN6lYzAkLxB5y0PsefiDo6w+PeEj1tUvSd +aQkiP7uvUC7a5GNp9yE8W79/O1jJXYJq15kMBpUshzfgdzyzDDCj+qvm6nbTWtP9 +rP30h81R+NGdOStgs0OVZSjMWnIoii3Rv3UV4+iQXZd67+wd/kbTWtWVAoGBAMvj +xv4wjt7OwtK/6oAhcNd2V9EUQp6PPpMkUyPicWdsLsoNOcuTpWvEc0AomdIGGjgI +AIor1ggCxjEhbCDaZucOFUghciUup+PjyQyQT+3bjvCWuUmi0Vt51G7RE0jjZjQt +2+W9V4yDcJ5R5ow6veYvT0ZOjVTScDYowTBulgjXAoGBALFxVl7UotQiqmVwempY +ZQSu13C0MIHl6V+2cuEiJEJn9R5a0h7EcIhpatkXmlUNZUY0Lr0ziIb1NJ/ctGwn +qDAqUuF+CXddjJ6KGm4uiiNlIZO7QaMcbqVdph3cVLrEeLQRfltBLGtr5WcnJt1D +UP5lyHK59V2MKSUAJz8uNjFpAoGAL5fR4Y/wKa5V5+AImzQzJPho81MpYd3KG4rF +JYE8O4oTOfLwZMboPEm1JWrUzSPDhwTHK3mkEmajYOCOXvTcRF8TNK0p+ef0JMwN +KDOflMRFj39/bOLmv9Wmct+3ArKiLtftlqkmAJTF+w7fJCiqH0s31A+OChi9PMcy +oV2PBC0CgYAXOm08kFOQA+bPBdLAte8Ga89frh6asH/Z8ucfsz9/zMMG/hhq5nF3 +7TItY9Pblc2Fp805J13G96zWLX4YGyLwXXkYs+Ae7QoqjonTw7/mUDARY1Zxs9m/ +a1C8EDKapCw5hAhizEFOUQKOygL8Ipn+tmEUkORYdZ8Q8cWFCv9nIw== +-----END RSA PRIVATE KEY-----" + ]); + PrivateKey::create([ + "id" => 3, + "name" => "development-gitlab-app", + "description" => "This is the key for using the development Gitlab app", + "private_key" => "asdf" + ]); } } diff --git a/database/seeders/ServerSeeder.php b/database/seeders/ServerSeeder.php index 2d14bd199..28f4e42fa 100644 --- a/database/seeders/ServerSeeder.php +++ b/database/seeders/ServerSeeder.php @@ -18,7 +18,7 @@ public function run(): void { $root_team = Team::find(1); $private_key_1 = PrivateKey::find(1); - $server_1 = Server::create([ + Server::create([ 'id' => 1, 'name' => "testing-host", 'description' => "This is a test docker container", diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 78f3675fd..031c6a8ce 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -15,6 +15,7 @@

{{ $application->name }}

Application: {{ $application }}

Destination Class: {{ $application->destination->getMorphClass() }}

+

Source Class: {{ $application->source->getMorphClass() }}

@empty
  • No application found
  • @endforelse