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
fix: compose generator
Andras Bacsai019cdd2b3a2e
diff --git a/app/Http/Controllers/Webhook/Bitbucket.php b/app/Http/Controllers/Webhook/Bitbucket.phpindex b9035b755b..f666d55cc0 100644--- a/app/Http/Controllers/Webhook/Bitbucket.php+++ b/app/Http/Controllers/Webhook/Bitbucket.php@@ -39,7 +39,7 @@ class Bitbucket extends Controller$x_bitbucket_token = data_get($headers, 'x-hub-signature.0', '');$x_bitbucket_event = data_get($headers, 'x-event-key.0', '');$handled_events = collect(['repo:push', 'pullrequest:created', 'pullrequest:rejected', 'pullrequest:fulfilled']);- if (! $handled_events->contains($x_bitbucket_event)) {+ if (!$handled_events->contains($x_bitbucket_event)) {return response(['status' => 'failed','message' => 'Nothing to do. Event not handled.',@@ -49,13 +49,13 @@ class Bitbucket extends Controller$branch = data_get($payload, 'push.changes.0.new.name');$full_name = data_get($payload, 'repository.full_name');$commit = data_get($payload, 'push.changes.0.new.target.hash');- if (! $branch) {+ if (!$branch) {return response(['status' => 'failed','message' => 'Nothing to do. No branch found in the request.',]);}- ray('Manual webhook bitbucket push event with branch: '.$branch);+ ray('Manual webhook bitbucket push event with branch: ' . $branch);}if ($x_bitbucket_event === 'pullrequest:created' || $x_bitbucket_event === 'pullrequest:rejected' || $x_bitbucket_event === 'pullrequest:fulfilled') {$branch = data_get($payload, 'pullrequest.destination.branch.name');@@ -79,7 +79,7 @@ class Bitbucket extends Controller[$algo, $hash] = explode('=', $x_bitbucket_token, 2);$payloadHash = hash_hmac($algo, $payload, $webhook_secret);- if (! hash_equals($hash, $payloadHash) && ! isDev()) {+ if (!hash_equals($hash, $payloadHash) && !isDev()) {$return_payloads->push(['application' => $application->name,'status' => 'failed',@@ -90,19 +90,19 @@ class Bitbucket extends Controllercontinue;}$isFunctional = $application->destination->server->isFunctional();- if (! $isFunctional) {+ if (!$isFunctional) {$return_payloads->push(['application' => $application->name,'status' => 'failed','message' => 'Server is not functional.',]);- ray('Server is not functional: '.$application->destination->server->name);+ ray('Server is not functional: ' . $application->destination->server->name);continue;}if ($x_bitbucket_event === 'repo:push') {if ($application->isDeployable()) {- ray('Deploying '.$application->name.' with branch '.$branch);+ ray('Deploying ' . $application->name . ' with branch ' . $branch);$deployment_uuid = new Cuid2(7);queue_application_deployment(application: $application,@@ -126,16 +126,27 @@ class Bitbucket extends Controller}if ($x_bitbucket_event === 'pullrequest:created') {if ($application->isPRDeployable()) {- ray('Deploying preview for '.$application->name.' with branch '.$branch.' and base branch '.$base_branch.' and pull request id '.$pull_request_id);+ ray('Deploying preview for ' . $application->name . ' with branch ' . $branch . ' and base branch ' . $base_branch . ' and pull request id ' . $pull_request_id);$deployment_uuid = new Cuid2(7);$found = ApplicationPreview::where('application_id', $application->id)->where('pull_request_id', $pull_request_id)->first();- if (! $found) {- ApplicationPreview::create([- 'git_type' => 'bitbucket',- 'application_id' => $application->id,- 'pull_request_id' => $pull_request_id,- 'pull_request_html_url' => $pull_request_html_url,- ]);+ if (!$found) {+ if ($application->build_pack === 'dockercompose') {+ $pr_app = ApplicationPreview::create([+ 'git_type' => 'bitbucket',+ 'application_id' => $application->id,+ 'pull_request_id' => $pull_request_id,+ 'pull_request_html_url' => $pull_request_html_url,+ 'docker_compose_domains' => $application->docker_compose_domains,+ ]);+ $pr_app->generate_preview_fqdn_compose();+ } else {+ ApplicationPreview::create([+ 'git_type' => 'bitbucket',+ 'application_id' => $application->id,+ 'pull_request_id' => $pull_request_id,+ 'pull_request_html_url' => $pull_request_html_url,+ ]);+ }}queue_application_deployment(application: $application,diff --git a/app/Http/Controllers/Webhook/Gitea.php b/app/Http/Controllers/Webhook/Gitea.phpindex 3884819498..e6d91efd6d 100644--- a/app/Http/Controllers/Webhook/Gitea.php+++ b/app/Http/Controllers/Webhook/Gitea.php@@ -165,12 +165,24 @@ class Gitea extends Controller$deployment_uuid = new Cuid2(7);$found = ApplicationPreview::where('application_id', $application->id)->where('pull_request_id', $pull_request_id)->first();if (! $found) {- ApplicationPreview::create([- 'git_type' => 'gitea',- 'application_id' => $application->id,- 'pull_request_id' => $pull_request_id,- 'pull_request_html_url' => $pull_request_html_url,- ]);+ if ($application->build_pack === 'dockercompose') {+ $pr_app = ApplicationPreview::create([+ 'git_type' => 'gitea',+ 'application_id' => $application->id,+ 'pull_request_id' => $pull_request_id,+ 'pull_request_html_url' => $pull_request_html_url,+ 'docker_compose_domains' => $application->docker_compose_domains,+ ]);+ $pr_app->generate_preview_fqdn_compose();+ } else {+ ApplicationPreview::create([+ 'git_type' => 'gitea',+ 'application_id' => $application->id,+ 'pull_request_id' => $pull_request_id,+ 'pull_request_html_url' => $pull_request_html_url,+ ]);+ }+}queue_application_deployment(application: $application,diff --git a/app/Http/Controllers/Webhook/Github.php b/app/Http/Controllers/Webhook/Github.phpindex 4034381939..87c7e283ae 100644--- a/app/Http/Controllers/Webhook/Github.php+++ b/app/Http/Controllers/Webhook/Github.php@@ -73,7 +73,7 @@ class Github extends Controller$removed_files = data_get($payload, 'commits.*.removed');$modified_files = data_get($payload, 'commits.*.modified');$changed_files = collect($added_files)->concat($removed_files)->concat($modified_files)->unique()->flatten();- ray('Manual Webhook GitHub Push Event with branch: '.$branch);+ ray('Manual Webhook GitHub Push Event with branch: ' . $branch);}if ($x_github_event === 'pull_request') {$action = data_get($payload, 'action');@@ -82,9 +82,9 @@ class Github extends Controller$pull_request_html_url = data_get($payload, 'pull_request.html_url');$branch = data_get($payload, 'pull_request.head.ref');$base_branch = data_get($payload, 'pull_request.base.ref');- ray('Webhook GitHub Pull Request Event with branch: '.$branch.' and base branch: '.$base_branch.' and pull request id: '.$pull_request_id);+ ray('Webhook GitHub Pull Request Event with branch: ' . $branch . ' and base branch: ' . $base_branch . ' and pull request id: ' . $pull_request_id);}- if (! $branch) {+ if (!$branch) {return response('Nothing to do. No branch found in the request.');}$applications = Application::where('git_repository', 'like', "%$full_name%");@@ -103,7 +103,7 @@ class Github extends Controllerforeach ($applications as $application) {$webhook_secret = data_get($application, 'manual_webhook_secret_github');$hmac = hash_hmac('sha256', $request->getContent(), $webhook_secret);- if (! hash_equals($x_hub_signature_256, $hmac) && ! isDev()) {+ if (!hash_equals($x_hub_signature_256, $hmac) && !isDev()) {ray('Invalid signature');$return_payloads->push(['application' => $application->name,@@ -114,7 +114,7 @@ class Github extends Controllercontinue;}$isFunctional = $application->destination->server->isFunctional();- if (! $isFunctional) {+ if (!$isFunctional) {$return_payloads->push(['application' => $application->name,'status' => 'failed',@@ -127,7 +127,7 @@ class Github extends Controllerif ($application->isDeployable()) {$is_watch_path_triggered = $application->isWatchPathsTriggered($changed_files);if ($is_watch_path_triggered || is_null($application->watch_paths)) {- ray('Deploying '.$application->name.' with branch '.$branch);+ ray('Deploying ' . $application->name . ' with branch ' . $branch);$deployment_uuid = new Cuid2(7);queue_application_deployment(application: $application,@@ -169,13 +169,24 @@ class Github extends Controllerif ($application->isPRDeployable()) {$deployment_uuid = new Cuid2(7);$found = ApplicationPreview::where('application_id', $application->id)->where('pull_request_id', $pull_request_id)->first();- if (! $found) {- ApplicationPreview::create([- 'git_type' => 'github',- 'application_id' => $application->id,- 'pull_request_id' => $pull_request_id,- 'pull_request_html_url' => $pull_request_html_url,- ]);+ if (!$found) {+ if ($application->build_pack === 'dockercompose') {+ $pr_app = ApplicationPreview::create([+ 'git_type' => 'github',+ 'application_id' => $application->id,+ 'pull_request_id' => $pull_request_id,+ 'pull_request_html_url' => $pull_request_html_url,+ 'docker_compose_domains' => $application->docker_compose_domains,+ ]);+ $pr_app->generate_preview_fqdn_compose();+ } else {+ ApplicationPreview::create([+ 'git_type' => 'github',+ 'application_id' => $application->id,+ 'pull_request_id' => $pull_request_id,+ 'pull_request_html_url' => $pull_request_html_url,+ ]);+ }}queue_application_deployment(application: $application,@@ -279,7 +290,7 @@ class Github extends Controller$webhook_secret = data_get($github_app, 'webhook_secret');$hmac = hash_hmac('sha256', $request->getContent(), $webhook_secret);if (config('app.env') !== 'local') {- if (! hash_equals($x_hub_signature_256, $hmac)) {+ if (!hash_equals($x_hub_signature_256, $hmac)) {return response('Invalid signature.');}}@@ -302,7 +313,7 @@ class Github extends Controller$removed_files = data_get($payload, 'commits.*.removed');$modified_files = data_get($payload, 'commits.*.modified');$changed_files = collect($added_files)->concat($removed_files)->concat($modified_files)->unique()->flatten();- ray('Webhook GitHub Push Event: '.$id.' with branch: '.$branch);+ ray('Webhook GitHub Push Event: ' . $id . ' with branch: ' . $branch);}if ($x_github_event === 'pull_request') {$action = data_get($payload, 'action');@@ -311,9 +322,9 @@ class Github extends Controller$pull_request_html_url = data_get($payload, 'pull_request.html_url');$branch = data_get($payload, 'pull_request.head.ref');$base_branch = data_get($payload, 'pull_request.base.ref');- ray('Webhook GitHub Pull Request Event: '.$id.' with branch: '.$branch.' and base branch: '.$base_branch.' and pull request id: '.$pull_request_id);+ ray('Webhook GitHub Pull Request Event: ' . $id . ' with branch: ' . $branch . ' and base branch: ' . $base_branch . ' and pull request id: ' . $pull_request_id);}- if (! $id || ! $branch) {+ if (!$id || !$branch) {return response('Nothing to do. No id or branch found.');}$applications = Application::where('repository_project_id', $id)->whereRelation('source', 'is_public', false);@@ -332,7 +343,7 @@ class Github extends Controllerforeach ($applications as $application) {$isFunctional = $application->destination->server->isFunctional();- if (! $isFunctional) {+ if (!$isFunctional) {$return_payloads->push(['status' => 'failed','message' => 'Server is not functional.',@@ -346,7 +357,7 @@ class Github extends Controllerif ($application->isDeployable()) {$is_watch_path_triggered = $application->isWatchPathsTriggered($changed_files);if ($is_watch_path_triggered || is_null($application->watch_paths)) {- ray('Deploying '.$application->name.' with branch '.$branch);+ ray('Deploying ' . $application->name . ' with branch ' . $branch);$deployment_uuid = new Cuid2(7);queue_application_deployment(application: $application,@@ -388,7 +399,7 @@ class Github extends Controllerif ($application->isPRDeployable()) {$deployment_uuid = new Cuid2(7);$found = ApplicationPreview::where('application_id', $application->id)->where('pull_request_id', $pull_request_id)->first();- if (! $found) {+ if (!$found) {ApplicationPreview::create(['git_type' => 'github','application_id' => $application->id,diff --git a/app/Http/Controllers/Webhook/Gitlab.php b/app/Http/Controllers/Webhook/Gitlab.phpindex a3d7712eb4..7ae376f1f7 100644--- a/app/Http/Controllers/Webhook/Gitlab.php+++ b/app/Http/Controllers/Webhook/Gitlab.php@@ -40,7 +40,7 @@ class Gitlab extends Controller$x_gitlab_token = data_get($headers, 'x-gitlab-token.0');$x_gitlab_event = data_get($payload, 'object_kind');$allowed_events = ['push', 'merge_request'];- if (! in_array($x_gitlab_event, $allowed_events)) {+ if (!in_array($x_gitlab_event, $allowed_events)) {$return_payloads->push(['status' => 'failed','message' => 'Event not allowed. Only push and merge_request events are allowed.',@@ -55,7 +55,7 @@ class Gitlab extends Controllerif (Str::isMatch('/refs\/heads\/*/', $branch)) {$branch = Str::after($branch, 'refs/heads/');}- if (! $branch) {+ if (!$branch) {$return_payloads->push(['status' => 'failed','message' => 'Nothing to do. No branch found in the request.',@@ -67,7 +67,7 @@ class Gitlab extends Controller$removed_files = data_get($payload, 'commits.*.removed');$modified_files = data_get($payload, 'commits.*.modified');$changed_files = collect($added_files)->concat($removed_files)->concat($modified_files)->unique()->flatten();- ray('Manual Webhook GitLab Push Event with branch: '.$branch);+ ray('Manual Webhook GitLab Push Event with branch: ' . $branch);}if ($x_gitlab_event === 'merge_request') {$action = data_get($payload, 'object_attributes.action');@@ -76,7 +76,7 @@ class Gitlab extends Controller$full_name = data_get($payload, 'project.path_with_namespace');$pull_request_id = data_get($payload, 'object_attributes.iid');$pull_request_html_url = data_get($payload, 'object_attributes.url');- if (! $branch) {+ if (!$branch) {$return_payloads->push(['status' => 'failed','message' => 'Nothing to do. No branch found in the request.',@@ -84,7 +84,7 @@ class Gitlab extends Controllerreturn response($return_payloads);}- ray('Webhook GitHub Pull Request Event with branch: '.$branch.' and base branch: '.$base_branch.' and pull request id: '.$pull_request_id);+ ray('Webhook GitHub Pull Request Event with branch: ' . $branch . ' and base branch: ' . $base_branch . ' and pull request id: ' . $pull_request_id);}$applications = Application::where('git_repository', 'like', "%$full_name%");if ($x_gitlab_event === 'push') {@@ -122,13 +122,13 @@ class Gitlab extends Controllercontinue;}$isFunctional = $application->destination->server->isFunctional();- if (! $isFunctional) {+ if (!$isFunctional) {$return_payloads->push(['application' => $application->name,'status' => 'failed','message' => 'Server is not functional',]);- ray('Server is not functional: '.$application->destination->server->name);+ ray('Server is not functional: ' . $application->destination->server->name);continue;}@@ -136,7 +136,7 @@ class Gitlab extends Controllerif ($application->isDeployable()) {$is_watch_path_triggered = $application->isWatchPathsTriggered($changed_files);if ($is_watch_path_triggered || is_null($application->watch_paths)) {- ray('Deploying '.$application->name.' with branch '.$branch);+ ray('Deploying ' . $application->name . ' with branch ' . $branch);$deployment_uuid = new Cuid2(7);queue_application_deployment(application: $application,@@ -171,7 +171,7 @@ class Gitlab extends Controller'application_uuid' => $application->uuid,'application_name' => $application->name,]);- ray('Deployments disabled for '.$application->name);+ ray('Deployments disabled for ' . $application->name);}}if ($x_gitlab_event === 'merge_request') {@@ -179,13 +179,24 @@ class Gitlab extends Controllerif ($application->isPRDeployable()) {$deployment_uuid = new Cuid2(7);$found = ApplicationPreview::where('application_id', $application->id)->where('pull_request_id', $pull_request_id)->first();- if (! $found) {- ApplicationPreview::create([- 'git_type' => 'gitlab',- 'application_id' => $application->id,- 'pull_request_id' => $pull_request_id,- 'pull_request_html_url' => $pull_request_html_url,- ]);+ if (!$found) {+ if ($application->build_pack === 'dockercompose') {+ $pr_app = ApplicationPreview::create([+ 'git_type' => 'gitlab',+ 'application_id' => $application->id,+ 'pull_request_id' => $pull_request_id,+ 'pull_request_html_url' => $pull_request_html_url,+ 'docker_compose_domains' => $application->docker_compose_domains,+ ]);+ $pr_app->generate_preview_fqdn_compose();+ } else {+ ApplicationPreview::create([+ 'git_type' => 'gitlab',+ 'application_id' => $application->id,+ 'pull_request_id' => $pull_request_id,+ 'pull_request_html_url' => $pull_request_html_url,+ ]);+ }}queue_application_deployment(application: $application,@@ -196,7 +207,7 @@ class Gitlab extends Controlleris_webhook: true,git_type: 'gitlab');- ray('Deploying preview for '.$application->name.' with branch '.$branch.' and base branch '.$base_branch.' and pull request id '.$pull_request_id);+ ray('Deploying preview for ' . $application->name . ' with branch ' . $branch . ' and base branch ' . $base_branch . ' and pull request id ' . $pull_request_id);$return_payloads->push(['application' => $application->name,'status' => 'success',@@ -208,7 +219,7 @@ class Gitlab extends Controller'status' => 'failed','message' => 'Preview deployments disabled',]);- ray('Preview deployments disabled for '.$application->name);+ ray('Preview deployments disabled for ' . $application->name);}} elseif ($action === 'closed' || $action === 'close' || $action === 'merge') {$found = ApplicationPreview::where('application_id', $application->id)->where('pull_request_id', $pull_request_id)->first();diff --git a/app/Livewire/Project/Application/Previews.php b/app/Livewire/Project/Application/Previews.phpindex ca911339ed..ea8a197647 100644--- a/app/Livewire/Project/Application/Previews.php+++ b/app/Livewire/Project/Application/Previews.php@@ -131,6 +131,10 @@ class Previews extends Component}}+ public function add_and_deploy(int $pull_request_id, ?string $pull_request_html_url = null) {+ $this->add($pull_request_id, $pull_request_html_url);+ $this->deploy($pull_request_id, $pull_request_html_url);+ }public function deploy(int $pull_request_id, ?string $pull_request_html_url = null){try {diff --git a/resources/views/livewire/project/application/previews.blade.php b/resources/views/livewire/project/application/previews.blade.phpindex 79a7b88b03..2f142abbbd 100644--- a/resources/views/livewire/project/application/previews.blade.php+++ b/resources/views/livewire/project/application/previews.blade.php@@ -45,7 +45,7 @@Configure</x-forms.button><x-forms.button- wire:click="deploy('{{ data_get($pull_request, 'number') }}', '{{ data_get($pull_request, 'html_url') }}')">+ wire:click="add_and_deploy('{{ data_get($pull_request, 'number') }}', '{{ data_get($pull_request, 'html_url') }}')"><svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 dark:text-warning"viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"fill="none" stroke-linecap="round" stroke-linejoin="round">