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(git-settings): add support for shallow cloning in application settings
Andras Bacsaia6fc39e79812
diff --git a/app/Livewire/Project/Application/Advanced.php b/app/Livewire/Project/Application/Advanced.phpindex bd13888060..6020af715a 100644--- a/app/Livewire/Project/Application/Advanced.php+++ b/app/Livewire/Project/Application/Advanced.php@@ -19,6 +19,9 @@ class Advanced extends Component#[Validate(['boolean'])]public bool $isGitLfsEnabled = false;+ #[Validate(['boolean'])]+ public bool $isGitShallowCloneEnabled = false;+#[Validate(['boolean'])]public bool $isPreviewDeploymentsEnabled = false;@@ -83,6 +86,7 @@ class Advanced extends Component$this->application->settings->is_force_https_enabled = $this->isForceHttpsEnabled;$this->application->settings->is_git_submodules_enabled = $this->isGitSubmodulesEnabled;$this->application->settings->is_git_lfs_enabled = $this->isGitLfsEnabled;+ $this->application->settings->is_git_shallow_clone_enabled = $this->isGitShallowCloneEnabled;$this->application->settings->is_preview_deployments_enabled = $this->isPreviewDeploymentsEnabled;$this->application->settings->is_auto_deploy_enabled = $this->isAutoDeployEnabled;$this->application->settings->is_log_drain_enabled = $this->isLogDrainEnabled;@@ -108,6 +112,7 @@ class Advanced extends Component$this->isGitSubmodulesEnabled = $this->application->settings->is_git_submodules_enabled;$this->isGitLfsEnabled = $this->application->settings->is_git_lfs_enabled;+ $this->isGitShallowCloneEnabled = $this->application->settings->is_git_shallow_clone_enabled ?? false;$this->isPreviewDeploymentsEnabled = $this->application->settings->is_preview_deployments_enabled;$this->isAutoDeployEnabled = $this->application->settings->is_auto_deploy_enabled;$this->isGpuEnabled = $this->application->settings->is_gpu_enabled;diff --git a/app/Models/Application.php b/app/Models/Application.phpindex 1971488c7e..c2fec427e1 100644--- a/app/Models/Application.php+++ b/app/Models/Application.php@@ -980,15 +980,26 @@ class Application extends BaseModelpublic function setGitImportSettings(string $deployment_uuid, string $git_clone_command, bool $public = false){$baseDir = $this->generateBaseDir($deployment_uuid);+ $isShallowCloneEnabled = $this->settings?->is_git_shallow_clone_enabled ?? false;if ($this->git_commit_sha !== 'HEAD') {- $git_clone_command = "{$git_clone_command} && cd {$baseDir} && GIT_SSH_COMMAND=\"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\" git -c advice.detachedHead=false checkout {$this->git_commit_sha} >/dev/null 2>&1";+ // If shallow clone is enabled and we need a specific commit,+ // we need to fetch that specific commit with depth=1+ if ($isShallowCloneEnabled) {+ $git_clone_command = "{$git_clone_command} && cd {$baseDir} && GIT_SSH_COMMAND=\"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\" git fetch --depth=1 origin {$this->git_commit_sha} && git -c advice.detachedHead=false checkout {$this->git_commit_sha} >/dev/null 2>&1";+ } else {+ $git_clone_command = "{$git_clone_command} && cd {$baseDir} && GIT_SSH_COMMAND=\"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\" git -c advice.detachedHead=false checkout {$this->git_commit_sha} >/dev/null 2>&1";+ }}if ($this->settings->is_git_submodules_enabled) {+ // Check if .gitmodules file exists before running submodule commands+ $git_clone_command = "{$git_clone_command} && cd {$baseDir} && if [ -f .gitmodules ]; then";if ($public) {- $git_clone_command = "{$git_clone_command} && cd {$baseDir} && sed -i \"s#git@\(.*\):#https://\\1/#g\" {$baseDir}/.gitmodules || true";+ $git_clone_command = "{$git_clone_command} sed -i \"s#git@\(.*\):#https://\\1/#g\" {$baseDir}/.gitmodules || true &&";}- $git_clone_command = "{$git_clone_command} && cd {$baseDir} && GIT_SSH_COMMAND=\"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\" git submodule update --init --recursive";+ // Add shallow submodules flag if shallow clone is enabled+ $submoduleFlags = $isShallowCloneEnabled ? '--shallow-submodules' : '';+ $git_clone_command = "{$git_clone_command} GIT_SSH_COMMAND=\"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\" git submodule update --init --recursive {$submoduleFlags}; fi";}if ($this->settings->is_git_lfs_enabled) {$git_clone_command = "{$git_clone_command} && cd {$baseDir} && GIT_SSH_COMMAND=\"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\" git lfs pull";@@ -1118,9 +1129,14 @@ class Application extends BaseModel['repository' => $customRepository, 'port' => $customPort] = $this->customRepository();$baseDir = $custom_base_dir ?? $this->generateBaseDir($deployment_uuid);$commands = collect([]);- $git_clone_command = "git clone -b \"{$this->git_branch}\"";++ // Check if shallow clone is enabled+ $isShallowCloneEnabled = $this->settings?->is_git_shallow_clone_enabled ?? false;+ $depthFlag = $isShallowCloneEnabled ? ' --depth=1' : '';++ $git_clone_command = "git clone{$depthFlag} -b \"{$this->git_branch}\"";if ($only_checkout) {- $git_clone_command = "git clone --no-checkout -b \"{$this->git_branch}\"";+ $git_clone_command = "git clone{$depthFlag} --no-checkout -b \"{$this->git_branch}\"";}if ($pull_request_id !== 0) {$pr_branch_name = "pr-{$pull_request_id}-coolify";diff --git a/app/Models/ApplicationSetting.php b/app/Models/ApplicationSetting.phpindex c7624fdaa1..d05081d216 100644--- a/app/Models/ApplicationSetting.php+++ b/app/Models/ApplicationSetting.php@@ -15,6 +15,7 @@ class ApplicationSetting extends Model'is_preview_deployments_enabled' => 'boolean','is_git_submodules_enabled' => 'boolean','is_git_lfs_enabled' => 'boolean',+ 'is_git_shallow_clone_enabled' => 'boolean',];protected $guarded = [];diff --git a/database/migrations/2025_08_21_080234_add_git_shallow_clone_to_application_settings_table.php b/database/migrations/2025_08_21_080234_add_git_shallow_clone_to_application_settings_table.phpnew file mode 100644index 0000000000..399c49c7f3--- /dev/null+++ b/database/migrations/2025_08_21_080234_add_git_shallow_clone_to_application_settings_table.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('application_settings', function (Blueprint $table) {+ $table->boolean('is_git_shallow_clone_enabled')->default(true)->after('is_git_lfs_enabled');+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::table('application_settings', function (Blueprint $table) {+ $table->dropColumn('is_git_shallow_clone_enabled');+ });+ }+};diff --git a/resources/views/livewire/project/application/advanced.blade.php b/resources/views/livewire/project/application/advanced.blade.phpindex 82b154bcb3..ad5d115a26 100644--- a/resources/views/livewire/project/application/advanced.blade.php+++ b/resources/views/livewire/project/application/advanced.blade.php@@ -67,6 +67,8 @@helper="Allow Git Submodules during build process." /><x-forms.checkbox instantSave id="isGitLfsEnabled" label="LFS"helper="Allow Git LFS during build process." />+ <x-forms.checkbox instantSave id="isGitShallowCloneEnabled" label="Shallow Clone"+ helper="Use shallow cloning (--depth=1) to speed up deployments by only fetching the latest commit history. This reduces clone time and resource usage, especially for large repositories." />@endif</div>