fix: new dev volumes and service files

fix: new parser version (4) that will fix data layout (applications goes to /applications, services goes to /services)
This commit is contained in:
Andras Bacsai
2024-09-30 14:15:22 +02:00
parent 68f541ded3
commit 987b90ead2
5 changed files with 27 additions and 8 deletions

View File

@@ -962,7 +962,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
} }
} }
if ($this->application->environment_variables->where('key', 'COOLIFY_FQDN')->isEmpty()) { if ($this->application->environment_variables->where('key', 'COOLIFY_FQDN')->isEmpty()) {
if ($this->application->compose_parsing_version === '3') { if ((int) $this->application->compose_parsing_version >= 3) {
$envs->push("COOLIFY_URL={$this->application->fqdn}"); $envs->push("COOLIFY_URL={$this->application->fqdn}");
} else { } else {
$envs->push("COOLIFY_FQDN={$this->application->fqdn}"); $envs->push("COOLIFY_FQDN={$this->application->fqdn}");
@@ -970,7 +970,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
} }
if ($this->application->environment_variables->where('key', 'COOLIFY_URL')->isEmpty()) { if ($this->application->environment_variables->where('key', 'COOLIFY_URL')->isEmpty()) {
$url = str($this->application->fqdn)->replace('http://', '')->replace('https://', ''); $url = str($this->application->fqdn)->replace('http://', '')->replace('https://', '');
if ($this->application->compose_parsing_version === '3') { if ((int) $this->application->compose_parsing_version >= 3) {
$envs->push("COOLIFY_FQDN={$url}"); $envs->push("COOLIFY_FQDN={$url}");
} else { } else {
$envs->push("COOLIFY_URL={$url}"); $envs->push("COOLIFY_URL={$url}");

View File

@@ -104,7 +104,7 @@ class Application extends BaseModel
{ {
use SoftDeletes; use SoftDeletes;
private static $parserVersion = '3'; private static $parserVersion = '4';
protected $guarded = []; protected $guarded = [];
@@ -1150,7 +1150,7 @@ class Application extends BaseModel
public function parse(int $pull_request_id = 0, ?int $preview_id = null) public function parse(int $pull_request_id = 0, ?int $preview_id = null)
{ {
if ($this->compose_parsing_version === '3') { if ((int) $this->compose_parsing_version >= 3) {
return newParser($this, $pull_request_id, $preview_id); return newParser($this, $pull_request_id, $preview_id);
} elseif ($this->docker_compose_raw) { } elseif ($this->docker_compose_raw) {
return parseDockerComposeFile(resource: $this, isNew: false, pull_request_id: $pull_request_id, preview_id: $preview_id); return parseDockerComposeFile(resource: $this, isNew: false, pull_request_id: $pull_request_id, preview_id: $preview_id);

View File

@@ -42,7 +42,7 @@ class Service extends BaseModel
{ {
use HasFactory, SoftDeletes; use HasFactory, SoftDeletes;
private static $parserVersion = '3'; private static $parserVersion = '4';
protected $guarded = []; protected $guarded = [];
@@ -1105,7 +1105,7 @@ class Service extends BaseModel
public function parse(bool $isNew = false): Collection public function parse(bool $isNew = false): Collection
{ {
if ($this->compose_parsing_version === '3') { if ((int) $this->compose_parsing_version >= 3) {
return newParser($this); return newParser($this);
} elseif ($this->docker_compose_raw) { } elseif ($this->docker_compose_raw) {
return parseDockerComposeFile($this, $isNew); return parseDockerComposeFile($this, $isNew);

View File

@@ -3264,7 +3264,15 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
} elseif ($source->value() === '/tmp' || $source->value() === '/tmp/') { } elseif ($source->value() === '/tmp' || $source->value() === '/tmp/') {
$volume = $source->value().':'.$target->value(); $volume = $source->value().':'.$target->value();
} else { } else {
if ((int) $resource->compose_parsing_version >= 4) {
if ($isApplication) {
$mainDirectory = str(base_configuration_dir().'/applications/'.$uuid); $mainDirectory = str(base_configuration_dir().'/applications/'.$uuid);
} elseif ($isService) {
$mainDirectory = str(base_configuration_dir().'/services/'.$uuid);
}
} else {
$mainDirectory = str(base_configuration_dir().'/applications/'.$uuid);
}
$source = replaceLocalSource($source, $mainDirectory); $source = replaceLocalSource($source, $mainDirectory);
if ($isApplication && $isPullRequest) { if ($isApplication && $isPullRequest) {
$source = $source."-pr-$pullRequestId"; $source = $source."-pr-$pullRequestId";
@@ -3284,6 +3292,17 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
'resource_type' => get_class($originalResource), 'resource_type' => get_class($originalResource),
] ]
); );
if (isDev()) {
if ((int) $resource->compose_parsing_version >= 4) {
if ($isApplication) {
$source = $source->replace($mainDirectory, '/var/lib/docker/volumes/coolify_dev_coolify_data/_data/applications/'.$uuid);
} elseif ($isService) {
$source = $source->replace($mainDirectory, '/var/lib/docker/volumes/coolify_dev_coolify_data/_data/services/'.$uuid);
}
} else {
$source = $source->replace($mainDirectory, '/var/lib/docker/volumes/coolify_dev_coolify_data/_data/applications/'.$uuid);
}
}
$volume = "$source:$target"; $volume = "$source:$target";
} }
} elseif ($type->value() === 'volume') { } elseif ($type->value() === 'volume') {

View File

@@ -256,7 +256,7 @@
helper="You need to modify the docker compose file." monacoEditorLanguage="yaml" helper="You need to modify the docker compose file." monacoEditorLanguage="yaml"
useMonacoEditor /> useMonacoEditor />
@else @else
@if ($application->compose_parsing_version === '3') @if ((int) $application->compose_parsing_version >= 3)
<x-forms.textarea rows="10" readonly id="application.docker_compose_raw" <x-forms.textarea rows="10" readonly id="application.docker_compose_raw"
label="Docker Compose Content (raw)" helper="You need to modify the docker compose file." label="Docker Compose Content (raw)" helper="You need to modify the docker compose file."
monacoEditorLanguage="yaml" useMonacoEditor /> monacoEditorLanguage="yaml" useMonacoEditor />