diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index df034a2f7..fd5d741e0 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -708,17 +708,67 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted private function save_environment_variables() { $envs = collect([]); + $ports = $this->application->settings->is_static ? [80] : $this->application->ports_exposes_array; if ($this->pull_request_id !== 0) { $this->env_filename = ".env-pr-$this->pull_request_id"; foreach ($this->application->environment_variables_preview as $env) { - $envs->push($env->key . '=' . $env->real_value); + $real_value = $env->real_value; + if ($env->version === '4.0.0-beta.239') { + $real_value = $env->real_value; + } else { + $real_value = escapeEnvVariables($env->real_value); + } + if ($env->is_literal) { + $real_value = '\'' . $real_value . '\''; + } + $envs->push($env->key . '=' . $real_value); + } + // Add PORT if not exists, use the first port as default + if ($this->application->environment_variables_preview->filter(fn ($env) => Str::of($env)->startsWith('PORT'))->isEmpty()) { + $envs->push("PORT={$ports[0]}"); + } + // Add HOST if not exists + if ($this->application->environment_variables_preview->filter(fn ($env) => Str::of($env)->startsWith('HOST'))->isEmpty()) { + $envs->push("HOST=0.0.0.0"); + } + if ($this->application->environment_variables_preview->filter(fn ($env) => Str::of($env)->startsWith('SOURCE_COMMIT'))->isEmpty()) { + if (!is_null($this->commit)) { + $envs->push("SOURCE_COMMIT={$this->commit}"); + } else { + $envs->push("SOURCE_COMMIT=unknown"); + } } } else { $this->env_filename = ".env"; foreach ($this->application->environment_variables as $env) { - $envs->push($env->key . '=' . $env->real_value); + $real_value = $env->real_value; + if ($env->version === '4.0.0-beta.239') { + $real_value = $env->real_value; + } else { + $real_value = escapeEnvVariables($env->real_value); + } + if ($env->is_literal) { + $real_value = '\'' . $real_value . '\''; + } + $envs->push($env->key . '=' . $real_value); + } + // Add PORT if not exists, use the first port as default + if ($this->application->environment_variables->filter(fn ($env) => Str::of($env)->startsWith('PORT'))->isEmpty()) { + $envs->push("PORT={$ports[0]}"); + } + // Add HOST if not exists + if ($this->application->environment_variables->filter(fn ($env) => Str::of($env)->startsWith('HOST'))->isEmpty()) { + $envs->push("HOST=0.0.0.0"); + } + if ($this->application->environment_variables->filter(fn ($env) => Str::of($env)->startsWith('SOURCE_COMMIT'))->isEmpty()) { + if (!is_null($this->commit)) { + $envs->push("SOURCE_COMMIT={$this->commit}"); + } else { + $envs->push("SOURCE_COMMIT=unknown"); + } } } + if ($envs->isEmpty()) { $this->env_filename = null; $this->execute_remote_command( @@ -1128,7 +1178,8 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted } $persistent_storages = $this->generate_local_persistent_volumes(); $volume_names = $this->generate_local_persistent_volumes_only_volume_names(); - $environment_variables = $this->generate_environment_variables($ports); + // $environment_variables = $this->generate_environment_variables($ports); + $this->save_environment_variables(); if (data_get($this->application, 'custom_labels')) { $this->application->parseContainerLabels(); $labels = collect(preg_split("/\r\n|\n|\r/", base64_decode($this->application->custom_labels))); @@ -1182,7 +1233,8 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted 'image' => $this->production_image_name, 'container_name' => $this->container_name, 'restart' => RESTART_MODE, - 'environment' => $environment_variables, + // 'env_file' => $this->env_filename, + // 'environment' => $environment_variables, 'expose' => $ports, 'networks' => [ $this->destination->network, @@ -1361,7 +1413,6 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted $this->docker_compose = Yaml::dump($docker_compose, 10); $this->docker_compose_base64 = base64_encode($this->docker_compose); $this->execute_remote_command([executeInDocker($this->deployment_uuid, "echo '{$this->docker_compose_base64}' | base64 -d > {$this->workdir}/docker-compose.yml"), "hidden" => true]); - $this->save_environment_variables(); } private function generate_local_persistent_volumes() diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.php index 7eb910533..f10da3563 100644 --- a/app/Livewire/Project/Application/General.php +++ b/app/Livewire/Project/Application/General.php @@ -165,7 +165,6 @@ class General extends Component return handleError($e, $this); } finally { $this->initLoadingCompose = false; - } } public function generateDomain(string $serviceName) diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/All.php b/app/Livewire/Project/Shared/EnvironmentVariable/All.php index c4e14c905..e7ce3894a 100644 --- a/app/Livewire/Project/Shared/EnvironmentVariable/All.php +++ b/app/Livewire/Project/Shared/EnvironmentVariable/All.php @@ -15,8 +15,10 @@ class All extends Component public ?string $variables = null; public ?string $variablesPreview = null; public string $view = 'normal'; - protected $listeners = ['refreshEnvs', 'saveKey' => 'submit']; - + protected $listeners = [ + 'refreshEnvs', + 'saveKey' => 'submit', + ]; public function mount() { $resourceClass = get_class($this->resource); diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php b/app/Livewire/Project/Shared/EnvironmentVariable/Show.php index a9854c196..65e91e60a 100644 --- a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php +++ b/app/Livewire/Project/Shared/EnvironmentVariable/Show.php @@ -16,6 +16,9 @@ class Show extends Component public bool $isLocked = false; public bool $isSharedVariable = false; public string $type; + protected $listeners = [ + "compose_loaded" => '$refresh', + ]; protected $rules = [ 'env.key' => 'required|string', @@ -43,7 +46,6 @@ class Show extends Component $this->modalId = new Cuid2(7); $this->parameters = get_route_parameters(); $this->checkEnvs(); - ray($this->env); } public function checkEnvs() { diff --git a/app/Models/EnvironmentVariable.php b/app/Models/EnvironmentVariable.php index 03930fba4..32bc04285 100644 --- a/app/Models/EnvironmentVariable.php +++ b/app/Models/EnvironmentVariable.php @@ -6,6 +6,7 @@ use App\Models\EnvironmentVariable as ModelsEnvironmentVariable; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Str; +use Symfony\Component\Yaml\Yaml; class EnvironmentVariable extends Model { @@ -81,6 +82,44 @@ class EnvironmentVariable extends Model } ); } + protected function isFoundInCompose(): Attribute + { + return Attribute::make( + get: function () { + if (!$this->application_id) { + return true; + } + $found_in_compose = false; + $resource = $this->resource(); + $compose = data_get($resource, 'docker_compose_raw'); + if (!$compose) { + return true; + } + $yaml = Yaml::parse($compose); + $services = collect(data_get($yaml, 'services')); + if ($services->isEmpty()) { + return false; + } + foreach ($services as $service) { + $environments = collect(data_get($service, 'environment')); + if ($environments->isEmpty()) { + $found_in_compose = false; + break; + } + $found_in_compose = $environments->contains(function ($item) { + if (str($item)->contains('=')) { + $item = str($item)->before('='); + } + return strpos($item, $this->key) !== false; + }); + if ($found_in_compose) { + break; + } + } + return $found_in_compose; + } + ); + } protected function isShared(): Attribute { return Attribute::make( diff --git a/config/livewire.php b/config/livewire.php index 83229fcea..cf9bcd206 100644 --- a/config/livewire.php +++ b/config/livewire.php @@ -146,4 +146,5 @@ return [ */ 'pagination_theme' => 'tailwind', + 'lazy_placeholder' => 'components.page-loading', ]; diff --git a/resources/views/components/page-loading.blade.php b/resources/views/components/page-loading.blade.php new file mode 100644 index 000000000..ca2a89e31 --- /dev/null +++ b/resources/views/components/page-loading.blade.php @@ -0,0 +1,13 @@ +@props(['text' => "Loading..."]) +
+ @if (isset($text)) +
{{ $text }}
+ @endif + + + + + +
diff --git a/resources/views/livewire/project/application/configuration.blade.php b/resources/views/livewire/project/application/configuration.blade.php index 719c60bc1..102f8681b 100644 --- a/resources/views/livewire/project/application/configuration.blade.php +++ b/resources/views/livewire/project/application/configuration.blade.php @@ -83,48 +83,48 @@
- +
- +
- +
@if ($application->git_based())
- +
@endif
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
diff --git a/resources/views/livewire/project/service/configuration.blade.php b/resources/views/livewire/project/service/configuration.blade.php index 3d85d9ee5..0f847f5ec 100644 --- a/resources/views/livewire/project/service/configuration.blade.php +++ b/resources/views/livewire/project/service/configuration.blade.php @@ -159,29 +159,29 @@ Please modify storage layout in your Docker Compose file. @foreach ($applications as $application) + :resource="$application" lazy /> @endforeach @foreach ($databases as $database) - + @endforeach
- +
- +
- +
- +
- +
- +
diff --git a/resources/views/livewire/project/shared/environment-variable/all.blade.php b/resources/views/livewire/project/shared/environment-variable/all.blade.php index d698b6350..c6a0a0707 100644 --- a/resources/views/livewire/project/shared/environment-variable/all.blade.php +++ b/resources/views/livewire/project/shared/environment-variable/all.blade.php @@ -11,7 +11,7 @@ wire:click='switch'>{{ $view === 'normal' ? 'Developer view' : 'Normal view' }}
Environment variables (secrets) for this resource.
- @if ($resource->type() === 'service') + @if ($resource->type() === 'service' || $resource?->build_pack === 'dockercompose')
Hardcoded variables are not shown here.
@endif diff --git a/resources/views/livewire/project/shared/environment-variable/show.blade.php b/resources/views/livewire/project/shared/environment-variable/show.blade.php index fca2d2bf4..499b24955 100644 --- a/resources/views/livewire/project/shared/environment-variable/show.blade.php +++ b/resources/views/livewire/project/shared/environment-variable/show.blade.php @@ -1,6 +1,15 @@
+ @if (!$env->isFoundInCompose) +
This variable is not found in the compose file, so it won't be used.
+ @endif @if ($isLocked)
@@ -49,7 +58,7 @@ helper="This means that when you use $VARIABLES, it should be interpreted as the actual characters '$VARIABLES' and not as the value of a variable named VARIABLE.

Useful if you have $ sign in your value and there are some characters after it, but you would not like to interpolate it form another value. In this case, you should set this to true." label="Is Literal?" /> @else - @if ($type === 'team' || $type === 'environment' || $type === 'project') + @if ($isSharedVariable) @else diff --git a/resources/views/livewire/project/shared/tags.blade.php b/resources/views/livewire/project/shared/tags.blade.php index d8c8fb320..22add2dde 100644 --- a/resources/views/livewire/project/shared/tags.blade.php +++ b/resources/views/livewire/project/shared/tags.blade.php @@ -1,18 +1,22 @@

Tags

- @forelse ($this->resource->tags as $tagId => $tag) -
- {{ $tag->name }} - - - -
- @empty -
No tags yet
- @endforelse + @if (data_get($this->resource, 'tags')) + @forelse (data_get($this->resource,'tags') as $tagId => $tag) +
+ {{ $tag->name }} + + + + +
+ @empty +
No tags yet
+ @endforelse + @endif