feat(git-settings): add support for shallow cloning in application settings
- Introduced a new boolean setting `is_git_shallow_clone_enabled` to the application settings model. - Updated the `Advanced` component to include a checkbox for enabling shallow cloning. - Modified the `setGitImportSettings` and `generateGitImportCommands` methods to handle shallow clone logic. - Created a migration to add the new setting to the database schema. - Enhanced the deployment process to utilize shallow cloning for improved performance.
This commit is contained in:
@@ -19,6 +19,9 @@ class Advanced extends Component
|
|||||||
#[Validate(['boolean'])]
|
#[Validate(['boolean'])]
|
||||||
public bool $isGitLfsEnabled = false;
|
public bool $isGitLfsEnabled = false;
|
||||||
|
|
||||||
|
#[Validate(['boolean'])]
|
||||||
|
public bool $isGitShallowCloneEnabled = false;
|
||||||
|
|
||||||
#[Validate(['boolean'])]
|
#[Validate(['boolean'])]
|
||||||
public bool $isPreviewDeploymentsEnabled = false;
|
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_force_https_enabled = $this->isForceHttpsEnabled;
|
||||||
$this->application->settings->is_git_submodules_enabled = $this->isGitSubmodulesEnabled;
|
$this->application->settings->is_git_submodules_enabled = $this->isGitSubmodulesEnabled;
|
||||||
$this->application->settings->is_git_lfs_enabled = $this->isGitLfsEnabled;
|
$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_preview_deployments_enabled = $this->isPreviewDeploymentsEnabled;
|
||||||
$this->application->settings->is_auto_deploy_enabled = $this->isAutoDeployEnabled;
|
$this->application->settings->is_auto_deploy_enabled = $this->isAutoDeployEnabled;
|
||||||
$this->application->settings->is_log_drain_enabled = $this->isLogDrainEnabled;
|
$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->isGitSubmodulesEnabled = $this->application->settings->is_git_submodules_enabled;
|
||||||
$this->isGitLfsEnabled = $this->application->settings->is_git_lfs_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->isPreviewDeploymentsEnabled = $this->application->settings->is_preview_deployments_enabled;
|
||||||
$this->isAutoDeployEnabled = $this->application->settings->is_auto_deploy_enabled;
|
$this->isAutoDeployEnabled = $this->application->settings->is_auto_deploy_enabled;
|
||||||
$this->isGpuEnabled = $this->application->settings->is_gpu_enabled;
|
$this->isGpuEnabled = $this->application->settings->is_gpu_enabled;
|
||||||
|
@@ -980,15 +980,26 @@ class Application extends BaseModel
|
|||||||
public function setGitImportSettings(string $deployment_uuid, string $git_clone_command, bool $public = false)
|
public function setGitImportSettings(string $deployment_uuid, string $git_clone_command, bool $public = false)
|
||||||
{
|
{
|
||||||
$baseDir = $this->generateBaseDir($deployment_uuid);
|
$baseDir = $this->generateBaseDir($deployment_uuid);
|
||||||
|
$isShallowCloneEnabled = $this->settings?->is_git_shallow_clone_enabled ?? false;
|
||||||
|
|
||||||
if ($this->git_commit_sha !== 'HEAD') {
|
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) {
|
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) {
|
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) {
|
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";
|
$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();
|
['repository' => $customRepository, 'port' => $customPort] = $this->customRepository();
|
||||||
$baseDir = $custom_base_dir ?? $this->generateBaseDir($deployment_uuid);
|
$baseDir = $custom_base_dir ?? $this->generateBaseDir($deployment_uuid);
|
||||||
$commands = collect([]);
|
$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) {
|
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) {
|
if ($pull_request_id !== 0) {
|
||||||
$pr_branch_name = "pr-{$pull_request_id}-coolify";
|
$pr_branch_name = "pr-{$pull_request_id}-coolify";
|
||||||
|
@@ -15,6 +15,7 @@ class ApplicationSetting extends Model
|
|||||||
'is_preview_deployments_enabled' => 'boolean',
|
'is_preview_deployments_enabled' => 'boolean',
|
||||||
'is_git_submodules_enabled' => 'boolean',
|
'is_git_submodules_enabled' => 'boolean',
|
||||||
'is_git_lfs_enabled' => 'boolean',
|
'is_git_lfs_enabled' => 'boolean',
|
||||||
|
'is_git_shallow_clone_enabled' => 'boolean',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $guarded = [];
|
protected $guarded = [];
|
||||||
|
@@ -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');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
@@ -67,6 +67,8 @@
|
|||||||
helper="Allow Git Submodules during build process." />
|
helper="Allow Git Submodules during build process." />
|
||||||
<x-forms.checkbox instantSave id="isGitLfsEnabled" label="LFS"
|
<x-forms.checkbox instantSave id="isGitLfsEnabled" label="LFS"
|
||||||
helper="Allow Git LFS during build process." />
|
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
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user