Skip to content

Commit 2529496

Browse files
committed
feat: preserve git repository
1 parent 1b61140 commit 2529496

File tree

5 files changed

+71
-8
lines changed

5 files changed

+71
-8
lines changed

app/Jobs/ApplicationDeploymentJob.php

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
157157

158158
private ?string $coolify_variables = null;
159159

160+
private bool $preserveRepository = true;
161+
160162
public $tries = 1;
161163

162164
public function __construct(int $application_deployment_queue_id)
@@ -187,6 +189,7 @@ public function __construct(int $application_deployment_queue_id)
187189
$this->server = $this->mainServer = $this->destination->server;
188190
$this->serverUser = $this->server->user;
189191
$this->is_this_additional_server = $this->application->additional_servers()->wherePivot('server_id', $this->server->id)->count() > 0;
192+
$this->preserveRepository = $this->application->settings->is_preserve_repository_enabled;
190193

191194
$this->basedir = $this->application->generateBaseDir($this->deployment_uuid);
192195
$this->workdir = "{$this->basedir}".rtrim($this->application->base_directory, '/');
@@ -296,13 +299,13 @@ public function handle(): void
296299
} else {
297300
$this->write_deployment_configurations();
298301
}
299-
$this->execute_remote_command(
300-
[
301-
"docker rm -f {$this->deployment_uuid} >/dev/null 2>&1",
302-
'hidden' => true,
303-
'ignore_errors' => true,
304-
]
305-
);
302+
// $this->execute_remote_command(
303+
// [
304+
// "docker rm -f {$this->deployment_uuid} >/dev/null 2>&1",
305+
// 'hidden' => true,
306+
// 'ignore_errors' => true,
307+
// ]
308+
// );
306309

307310
// $this->execute_remote_command(
308311
// [
@@ -517,6 +520,8 @@ private function deploy_docker_compose_buildpack()
517520
$command .= " --env-file {$this->workdir}/{$this->env_filename}";
518521
}
519522
$command .= " --project-name {$this->application->uuid} --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} up -d";
523+
ray($command);
524+
520525
$this->execute_remote_command(
521526
[executeInDocker($this->deployment_uuid, $command), 'hidden' => true],
522527
);
@@ -605,6 +610,28 @@ private function deploy_static_buildpack()
605610

606611
private function write_deployment_configurations()
607612
{
613+
if ($this->preserveRepository) {
614+
if ($this->use_build_server) {
615+
$this->server = $this->original_server;
616+
}
617+
if (str($this->configuration_dir)->isNotEmpty()) {
618+
ray("docker cp {$this->deployment_uuid}:{$this->workdir} {$this->configuration_dir}");
619+
$this->execute_remote_command(
620+
[
621+
"mkdir -p $this->configuration_dir",
622+
],
623+
[
624+
"rm -rf $this->configuration_dir/{*,.*}",
625+
],
626+
[
627+
"docker cp {$this->deployment_uuid}:{$this->workdir}/. {$this->configuration_dir}",
628+
],
629+
);
630+
}
631+
if ($this->use_build_server) {
632+
$this->server = $this->build_server;
633+
}
634+
}
608635
if (isset($this->docker_compose_base64)) {
609636
if ($this->use_build_server) {
610637
$this->server = $this->original_server;

app/Livewire/Project/Application/General.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class General extends Component
8585
'application.settings.is_build_server_enabled' => 'boolean|required',
8686
'application.settings.is_container_label_escape_enabled' => 'boolean|required',
8787
'application.settings.is_container_label_readonly_enabled' => 'boolean|required',
88+
'application.settings.is_preserve_repository_enabled' => 'boolean|required',
8889
'application.watch_paths' => 'nullable',
8990
'application.redirect' => 'string|required',
9091
];
@@ -121,6 +122,7 @@ class General extends Component
121122
'application.settings.is_build_server_enabled' => 'Is build server enabled',
122123
'application.settings.is_container_label_escape_enabled' => 'Is container label escape enabled',
123124
'application.settings.is_container_label_readonly_enabled' => 'Is container label readonly',
125+
'application.settings.is_preserve_repository_enabled' => 'Is preserve repository enabled',
124126
'application.watch_paths' => 'Watch paths',
125127
'application.redirect' => 'Redirect',
126128
];
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('application_settings', function (Blueprint $table) {
15+
$table->boolean('is_preserve_repository_enabled')->default(false);
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('application_settings', function (Blueprint $table) {
25+
$table->dropColumn('is_preserve_repository_enabled');
26+
});
27+
}
28+
};

resources/views/livewire/project/application/advanced.blade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
<x-forms.checkbox
1717
helper="Your application will be available only on https if your domain starts with https://..."
1818
instantSave id="is_force_https_enabled" label="Force Https" />
19-
<x-forms.checkbox label="Enable gzip compression"
19+
<x-forms.checkbox label="Enable Gzip Compression"
2020
helper="You can disable gzip compression if you want. Some services are compressing data by default. In this case, you do not need this."
2121
instantSave id="is_gzip_enabled" />
2222
<x-forms.checkbox helper="Strip Prefix is used to remove prefixes from paths. Like /api/ to /api."
2323
instantSave id="is_stripprefix_enabled" label="Strip Prefixes" />
2424
@if ($application->build_pack === 'dockercompose')
25+
<h3>Docker Compose</h3>
2526
<x-forms.checkbox instantSave id="application.settings.is_raw_compose_deployment_enabled"
2627
label="Raw Compose Deployment"
2728
helper="WARNING: Advanced use cases only. Your docker compose file will be deployed as-is. Nothing is modified by Coolify. You need to configure the proxy parts. More info in the <a class='underline dark:text-white' href='https://coolify.io/docs/knowledge-base/docker/compose#raw-docker-compose-deployment'>documentation.</a>" />

resources/views/livewire/project/application/general.blade.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ class="underline" href="https://coolify.io/docs/knowledge-base/docker/registry"
166166
id="application.docker_compose_location" label="Docker Compose Location"
167167
helper="It is calculated together with the Base Directory:<br><span class='dark:text-warning'>{{ Str::start($application->base_directory . $application->docker_compose_location, '/') }}</span>" />
168168
</div>
169+
<div class="w-96">
170+
<x-forms.checkbox instantSave id="application.settings.is_preserve_repository_enabled"
171+
label="Preserve Repository During Deployment"
172+
helper="Git repository (based on the base directory settings) will be copied to the deployment directory." />
173+
</div>
169174
<div class="pt-4">The following commands are for advanced use cases. Only modify them if you
170175
know what are
171176
you doing.</div>

0 commit comments

Comments
 (0)