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: watch paths
Andras Bacsai51d716253f19
diff --git a/app/Http/Controllers/Webhook/Github.php b/app/Http/Controllers/Webhook/Github.phpindex 02ba017ca5..433d29c58e 100644--- a/app/Http/Controllers/Webhook/Github.php+++ b/app/Http/Controllers/Webhook/Github.php@@ -204,6 +204,7 @@ class Github extends Controller}public function normal(Request $request){+ ray('asdf');try {$return_payloads = collect([]);$id = null;@@ -266,6 +267,10 @@ class Github extends Controllerif (Str::isMatch('/refs\/heads\/*/', $branch)) {$branch = Str::after($branch, 'refs/heads/');}+ $added_files = data_get($payload, 'commits.*.added');+ $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);}if ($x_github_event === 'pull_request') {@@ -306,19 +311,32 @@ class Github extends Controller}if ($x_github_event === 'push') {if ($application->isDeployable()) {- ray('Deploying ' . $application->name . ' with branch ' . $branch);- $deployment_uuid = new Cuid2(7);- queue_application_deployment(- application: $application,- deployment_uuid: $deployment_uuid,- force_rebuild: false,- is_webhook: true- );- $return_payloads->push([- 'application' => $application->name,- 'status' => 'success',- 'message' => 'Deployment queued.',- ]);+ $watch_files_trigger = $application->watchPathCheck($changed_files);+ if (!$watch_files_trigger) {+ $return_payloads->push([+ 'application' => $application->name,+ 'status' => 'failed',+ 'message' => 'Watch paths does not have the changed files. Deployment ignored.',+ 'details' => [+ 'changed_files' => $changed_files,+ 'watch_paths' => $application->watch_paths,+ ],+ ]);+ } else {+ ray('Deploying ' . $application->name . ' with branch ' . $branch);+ $deployment_uuid = new Cuid2(7);+ queue_application_deployment(+ application: $application,+ deployment_uuid: $deployment_uuid,+ force_rebuild: false,+ is_webhook: true,+ );+ $return_payloads->push([+ 'application' => $application->name,+ 'status' => 'success',+ 'message' => 'Deployment queued.',+ ]);+ }} else {$return_payloads->push(['application' => $application->name,diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.phpindex 9485cdd034..c6b8f2e517 100644--- a/app/Livewire/Project/Application/General.php+++ b/app/Livewire/Project/Application/General.php@@ -73,6 +73,7 @@ class General extends Component'application.settings.is_static' => 'boolean|required','application.settings.is_raw_compose_deployment_enabled' => 'boolean|required','application.settings.is_build_server_enabled' => 'boolean|required',+ 'application.watch_paths' => 'nullable',];protected $validationAttributes = ['application.name' => 'name',@@ -108,6 +109,7 @@ class General extends Component'application.settings.is_static' => 'Is static','application.settings.is_raw_compose_deployment_enabled' => 'Is raw compose deployment enabled','application.settings.is_build_server_enabled' => 'Is build server enabled',+ 'application.watch_paths' => 'Watch paths',];public function mount(){diff --git a/app/Models/Application.php b/app/Models/Application.phpindex bc3b27bb09..fc03f8b1e7 100644--- a/app/Models/Application.php+++ b/app/Models/Application.php@@ -6,6 +6,7 @@ use App\Enums\ApplicationDeploymentStatus;use Illuminate\Database\Eloquent\Casts\Attribute;use Illuminate\Database\Eloquent\Relations\HasMany;use Illuminate\Database\Eloquent\SoftDeletes;+use Illuminate\Support\Collection;use Spatie\Activitylog\Models\Activity;use Illuminate\Support\Str;use RuntimeException;@@ -903,4 +904,24 @@ class Application extends BaseModel: explode(',', $this->fqdn),);}+ public function watchPaths(): Attribute+ {+ return Attribute::make(+ set: function ($value) {+ if ($value) {+ return trim($value);+ }+ }+ );+ }+ public function watchPathCheck(Collection $modified_files): bool+ {+ $watch_paths = collect(explode("\n", $this->watch_paths));+ $matches = $modified_files->filter(function ($file) use ($watch_paths) {+ return $watch_paths->contains(function ($glob) use ($file) {+ return fnmatch($glob, $file);+ });+ });+ return $matches->count() > 0;+ }}diff --git a/bootstrap/helpers/applications.php b/bootstrap/helpers/applications.phpindex bf3f155143..8d810da0f5 100644--- a/bootstrap/helpers/applications.php+++ b/bootstrap/helpers/applications.php@@ -6,6 +6,7 @@ use App\Models\Application;use App\Models\ApplicationDeploymentQueue;use App\Models\Server;use App\Models\StandaloneDocker;+use Illuminate\Support\Collection;use Spatie\Url\Url;function queue_application_deployment(Application $application, string $deployment_uuid, int | null $pull_request_id = 0, string $commit = 'HEAD', bool $force_rebuild = false, bool $is_webhook = false, bool $restart_only = false, ?string $git_type = null, bool $no_questions_asked = false, Server $server = null, StandaloneDocker $destination = null, bool $only_this_server = false)diff --git a/database/migrations/2024_03_28_114620_add_watch_paths_to_apps.php b/database/migrations/2024_03_28_114620_add_watch_paths_to_apps.phpnew file mode 100644index 0000000000..d58adcd623--- /dev/null+++ b/database/migrations/2024_03_28_114620_add_watch_paths_to_apps.php@@ -0,0 +1,28 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration+{+ /**+ * Run the migrations.+ */+ public function up(): void+ {+ Schema::table('applications', function (Blueprint $table) {+ $table->longText('watch_paths')->nullable();+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::table('applications', function (Blueprint $table) {+ $table->dropColumn('watch_paths');+ });+ }+};diff --git a/resources/css/app.css b/resources/css/app.cssindex c2ca9f612a..5976e2285a 100644--- a/resources/css/app.css+++ b/resources/css/app.css@@ -13,7 +13,7 @@ body {.input,.select {- @apply text-black dark:bg-coolgray-100 dark:text-white ring-neutral-300 dark:ring-coolgray-300;+ @apply text-black dark:bg-coolgray-100 dark:text-white ring-neutral-200 dark:ring-coolgray-300;}/* Readonly */diff --git a/resources/views/livewire/project/application/general.blade.php b/resources/views/livewire/project/application/general.blade.phpindex 44578c23ce..e894313655 100644--- a/resources/views/livewire/project/application/general.blade.php+++ b/resources/views/livewire/project/application/general.blade.php@@ -148,7 +148,8 @@id="application.start_command" label="Start Command" /></div><div>Nixpacks will detect the required configuration automatically.- <a class="underline" href="https://coolify.io/docs/resources/introduction">Framework Specific Docs</a>+ <a class="underline" href="https://coolify.io/docs/resources/introduction">Framework+ Specific Docs</a></div>@endif@endif@@ -201,7 +202,12 @@label="Publish Directory" />@endif@endif+</div>+ @if ($this->application->is_github_based())+ <x-forms.textarea helper="Gitignore-style rules to filter Git based webhook deployments."+ placeholder="src/pages/**" id="application.watch_paths" label="Watch Paths" />+ @endif<div>The following options are for advanced use cases. Only modify them if youknow what areyou doing.</div>