An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
feat: deploy private repo with ssh key
Andras Bacsai2f4d7c0e430f
diff --git a/app/Http/Livewire/Project/New/GithubPrivateRepositoryDeployKey.php b/app/Http/Livewire/Project/New/GithubPrivateRepositoryDeployKey.phpindex cf8f56642a..0397b822fb 100644--- a/app/Http/Livewire/Project/New/GithubPrivateRepositoryDeployKey.php+++ b/app/Http/Livewire/Project/New/GithubPrivateRepositoryDeployKey.php@@ -11,6 +11,7 @@ use App\Models\StandaloneDocker;use App\Models\SwarmDocker;use Livewire\Component;use Spatie\Url\Url;+use Illuminate\Support\Str;class GithubPrivateRepositoryDeployKey extends Component{@@ -29,7 +30,7 @@ class GithubPrivateRepositoryDeployKey extends Componentpublic string $repository_url;public string $branch;protected $rules = [- 'repository_url' => 'required|url',+ 'repository_url' => 'required','branch' => 'required|string','port' => 'required|numeric','is_static' => 'required|boolean',@@ -43,8 +44,8 @@ class GithubPrivateRepositoryDeployKey extends Component'publish_directory' => 'Publish directory',];private object $repository_url_parsed;- private GithubApp|GitlabApp|null $git_source = null;- private string $git_host;+ private GithubApp|GitlabApp|string $git_source = 'other';+ private ?string $git_host = null;private string $git_repository;public function mount()@@ -92,21 +93,38 @@ class GithubPrivateRepositoryDeployKey extends Component$project = Project::where('uuid', $this->parameters['project_uuid'])->first();$environment = $project->load(['environments'])->environments->where('name', $this->parameters['environment_name'])->first();- $application_init = [- 'name' => generate_random_name(),- 'git_repository' => $this->git_repository,- 'git_branch' => $this->branch,- 'git_full_url' => "git@$this->git_host:$this->git_repository.git",- 'build_pack' => 'nixpacks',- 'ports_exposes' => $this->port,- 'publish_directory' => $this->publish_directory,- 'environment_id' => $environment->id,- 'destination_id' => $destination->id,- 'destination_type' => $destination_class,- 'private_key_id' => $this->private_key_id,- 'source_id' => $this->git_source->id,- 'source_type' => $this->git_source->getMorphClass()- ];+ if ($this->git_source === 'other') {+ $application_init = [+ 'name' => generate_random_name(),+ 'git_repository' => $this->git_repository,+ 'git_branch' => $this->branch,+ 'git_full_url' => $this->git_repository,+ 'build_pack' => 'nixpacks',+ 'ports_exposes' => $this->port,+ 'publish_directory' => $this->publish_directory,+ 'environment_id' => $environment->id,+ 'destination_id' => $destination->id,+ 'destination_type' => $destination_class,+ 'private_key_id' => $this->private_key_id,+ ];+ } else {+ $application_init = [+ 'name' => generate_random_name(),+ 'git_repository' => $this->git_repository,+ 'git_branch' => $this->branch,+ 'git_full_url' => "git@$this->git_host:$this->git_repository.git",+ 'build_pack' => 'nixpacks',+ 'ports_exposes' => $this->port,+ 'publish_directory' => $this->publish_directory,+ 'environment_id' => $environment->id,+ 'destination_id' => $destination->id,+ 'destination_type' => $destination_class,+ 'private_key_id' => $this->private_key_id,+ 'source_id' => $this->git_source->id,+ 'source_type' => $this->git_source->getMorphClass()+ ];+ }+$application = Application::create($application_init);$application->settings->is_static = $this->is_static;$application->settings->save();@@ -128,16 +146,18 @@ class GithubPrivateRepositoryDeployKey extends Componentprivate function get_git_source(){- $this->repository_url_parsed = Url::fromString($this->repository_url);- $this->git_host = $this->repository_url_parsed->getHost();- $this->git_repository = $this->repository_url_parsed->getSegment(1) . '/' . $this->repository_url_parsed->getSegment(2);+ if (Str::of($this->repository_url)->startsWith('http')) {+ $this->repository_url_parsed = Url::fromString($this->repository_url);+ $this->git_host = $this->repository_url_parsed->getHost();+ $this->git_repository = $this->repository_url_parsed->getSegment(1) . '/' . $this->repository_url_parsed->getSegment(2);+ } else {+ $this->git_repository = $this->repository_url;+ }if ($this->git_host == 'github.com') {$this->git_source = GithubApp::where('name', 'Public GitHub')->first();- } elseif ($this->git_host == 'gitlab.com') {- $this->git_source = GitlabApp::where('name', 'Public GitLab')->first();- } elseif ($this->git_host == 'bitbucket.org') {- // Not supported yet+ return;}+ $this->git_source = 'other';}}diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.phpindex 9988c97283..fc0387357c 100644--- a/app/Jobs/ApplicationDeploymentJob.php+++ b/app/Jobs/ApplicationDeploymentJob.php@@ -165,12 +165,12 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted]);}- // $this->execute_remote_command(- // [- // "docker rm -f {$this->deployment_uuid} >/dev/null 2>&1",- // "hidden" => true,- // ]- // );+ $this->execute_remote_command(+ [+ "docker rm -f {$this->deployment_uuid} >/dev/null 2>&1",+ "hidden" => true,+ ]+ );}}private function deploy_docker_compose()@@ -428,7 +428,6 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted$pr_branch_name = "pr-{$this->pull_request_id}-coolify";}-if ($this->application->deploymentType() === 'source') {$source_html_url = data_get($this->application, 'source.html_url');$url = parse_url(filter_var($source_html_url, FILTER_SANITIZE_URL));diff --git a/app/Models/Application.php b/app/Models/Application.phpindex 3d23a57091..3f5eb54d59 100644--- a/app/Models/Application.php+++ b/app/Models/Application.php@@ -243,9 +243,7 @@ class Application extends BaseModelif ($this->dockerfile) {return false;}- if (is_null($this->source)) {- return false;- }+return true;}public function isHealthcheckDisabled(): booldiff --git a/resources/views/livewire/project/new/select.blade.php b/resources/views/livewire/project/new/select.blade.phpindex 8e4b9d54c4..3bda859b3c 100644--- a/resources/views/livewire/project/new/select.blade.php+++ b/resources/views/livewire/project/new/select.blade.php@@ -23,7 +23,7 @@<div class="box group" wire:click="setType('private-gh-app')"><div class="flex flex-col mx-6"><div class="font-bold text-white group-hover:text-white">- Private Repository+ Private Repository (with GitHub App)</div><div class="text-xs group-hover:text-white">You can deploy public & private repositories through your GitHub Apps.