feat: required envs
This commit is contained in:
@@ -39,6 +39,7 @@ class Navbar extends Component
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
"echo-private:user.{$userId},ServiceStatusChanged" => 'serviceStarted',
|
"echo-private:user.{$userId},ServiceStatusChanged" => 'serviceStarted',
|
||||||
|
"envsUpdated" => '$refresh',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ class Show extends Component
|
|||||||
'env.is_literal' => 'required|boolean',
|
'env.is_literal' => 'required|boolean',
|
||||||
'env.is_shown_once' => 'required|boolean',
|
'env.is_shown_once' => 'required|boolean',
|
||||||
'env.real_value' => 'nullable',
|
'env.real_value' => 'nullable',
|
||||||
|
'env.is_required' => 'required|boolean',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $validationAttributes = [
|
protected $validationAttributes = [
|
||||||
@@ -46,6 +47,7 @@ class Show extends Component
|
|||||||
'env.is_multiline' => 'Multiline',
|
'env.is_multiline' => 'Multiline',
|
||||||
'env.is_literal' => 'Literal',
|
'env.is_literal' => 'Literal',
|
||||||
'env.is_shown_once' => 'Shown Once',
|
'env.is_shown_once' => 'Shown Once',
|
||||||
|
'env.is_required' => 'Required',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function refresh()
|
public function refresh()
|
||||||
@@ -109,14 +111,14 @@ class Show extends Component
|
|||||||
} else {
|
} else {
|
||||||
$this->validate();
|
$this->validate();
|
||||||
}
|
}
|
||||||
// if (str($this->env->value)->startsWith('{{') && str($this->env->value)->endsWith('}}')) {
|
|
||||||
// $type = str($this->env->value)->after('{{')->before('.')->value;
|
|
||||||
// if (! collect(SHARED_VARIABLE_TYPES)->contains($type)) {
|
|
||||||
// $this->dispatch('error', 'Invalid shared variable type.', 'Valid types are: team, project, environment.');
|
|
||||||
|
|
||||||
// return;
|
if ($this->env->is_required && str($this->env->real_value)->isEmpty()) {
|
||||||
// }
|
$oldValue = $this->env->getOriginal('value');
|
||||||
// }
|
$this->env->value = $oldValue;
|
||||||
|
$this->dispatch('error', 'Required environment variable cannot be empty.');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
$this->serialize();
|
$this->serialize();
|
||||||
$this->env->save();
|
$this->env->save();
|
||||||
$this->dispatch('success', 'Environment variable updated.');
|
$this->dispatch('success', 'Environment variable updated.');
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class EnvironmentVariable extends Model
|
|||||||
'version' => 'string',
|
'version' => 'string',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $appends = ['real_value', 'is_shared'];
|
protected $appends = ['real_value', 'is_shared', 'is_really_required'];
|
||||||
|
|
||||||
protected static function booted()
|
protected static function booted()
|
||||||
{
|
{
|
||||||
@@ -130,6 +130,13 @@ class EnvironmentVariable extends Model
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function isReallyRequired(): Attribute
|
||||||
|
{
|
||||||
|
return Attribute::make(
|
||||||
|
get: fn () => $this->is_required && str($this->real_value)->isEmpty(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected function isShared(): Attribute
|
protected function isShared(): Attribute
|
||||||
{
|
{
|
||||||
return Attribute::make(
|
return Attribute::make(
|
||||||
|
|||||||
@@ -1232,7 +1232,6 @@ class Service extends BaseModel
|
|||||||
|
|
||||||
public function environment_variables(): HasMany
|
public function environment_variables(): HasMany
|
||||||
{
|
{
|
||||||
|
|
||||||
return $this->hasMany(EnvironmentVariable::class)->orderByRaw("LOWER(key) LIKE LOWER('SERVICE%') DESC, LOWER(key) ASC");
|
return $this->hasMany(EnvironmentVariable::class)->orderByRaw("LOWER(key) LIKE LOWER('SERVICE%') DESC, LOWER(key) ASC");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1316,4 +1315,20 @@ class Service extends BaseModel
|
|||||||
|
|
||||||
return $networks;
|
return $networks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function isDeployable(): Attribute
|
||||||
|
{
|
||||||
|
return Attribute::make(
|
||||||
|
get: function () {
|
||||||
|
$envs = $this->environment_variables()->where('is_required', true)->get();
|
||||||
|
foreach ($envs as $env) {
|
||||||
|
if ($env->is_really_required) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3569,6 +3569,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
|||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
if ($value->startsWith('$')) {
|
if ($value->startsWith('$')) {
|
||||||
|
$isRequired = false;
|
||||||
if ($value->contains(':-')) {
|
if ($value->contains(':-')) {
|
||||||
$value = replaceVariables($value);
|
$value = replaceVariables($value);
|
||||||
$key = $value->before(':');
|
$key = $value->before(':');
|
||||||
@@ -3583,11 +3584,13 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
|||||||
|
|
||||||
$key = $value->before(':');
|
$key = $value->before(':');
|
||||||
$value = $value->after(':?');
|
$value = $value->after(':?');
|
||||||
|
$isRequired = true;
|
||||||
} elseif ($value->contains('?')) {
|
} elseif ($value->contains('?')) {
|
||||||
$value = replaceVariables($value);
|
$value = replaceVariables($value);
|
||||||
|
|
||||||
$key = $value->before('?');
|
$key = $value->before('?');
|
||||||
$value = $value->after('?');
|
$value = $value->after('?');
|
||||||
|
$isRequired = true;
|
||||||
}
|
}
|
||||||
if ($originalValue->value() === $value->value()) {
|
if ($originalValue->value() === $value->value()) {
|
||||||
// This means the variable does not have a default value, so it needs to be created in Coolify
|
// This means the variable does not have a default value, so it needs to be created in Coolify
|
||||||
@@ -3598,6 +3601,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
|||||||
], [
|
], [
|
||||||
'is_build_time' => false,
|
'is_build_time' => false,
|
||||||
'is_preview' => false,
|
'is_preview' => false,
|
||||||
|
'is_required' => $isRequired,
|
||||||
]);
|
]);
|
||||||
// Add the variable to the environment so it will be shown in the deployable compose file
|
// Add the variable to the environment so it will be shown in the deployable compose file
|
||||||
$environment[$parsedKeyValue->value()] = $resource->environment_variables()->where('key', $parsedKeyValue)->where($nameOfId, $resource->id)->first()->value;
|
$environment[$parsedKeyValue->value()] = $resource->environment_variables()->where('key', $parsedKeyValue)->where($nameOfId, $resource->id)->first()->value;
|
||||||
@@ -3611,6 +3615,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
|||||||
'value' => $value,
|
'value' => $value,
|
||||||
'is_build_time' => false,
|
'is_build_time' => false,
|
||||||
'is_preview' => false,
|
'is_preview' => false,
|
||||||
|
'is_required' => $isRequired,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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('environment_variables', function (Blueprint $table) {
|
||||||
|
$table->boolean('is_required')->default(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('environment_variables', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('is_required');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
</a>
|
</a>
|
||||||
<x-services.links :service="$service" />
|
<x-services.links :service="$service" />
|
||||||
</nav>
|
</nav>
|
||||||
|
@if ($service->isDeployable)
|
||||||
<div class="flex flex-wrap order-first gap-2 items-center sm:order-last">
|
<div class="flex flex-wrap order-first gap-2 items-center sm:order-last">
|
||||||
@if (str($service->status())->contains('running'))
|
@if (str($service->status())->contains('running'))
|
||||||
<x-dropdown>
|
<x-dropdown>
|
||||||
@@ -27,8 +28,9 @@
|
|||||||
Advanced
|
Advanced
|
||||||
</x-slot>
|
</x-slot>
|
||||||
<div class="dropdown-item" @click="$wire.dispatch('pullAndRestartEvent')">
|
<div class="dropdown-item" @click="$wire.dispatch('pullAndRestartEvent')">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" viewBox="0 0 24 24" stroke-width="1.5"
|
<svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" viewBox="0 0 24 24"
|
||||||
stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round"
|
||||||
|
stroke-linejoin="round">
|
||||||
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
||||||
<path
|
<path
|
||||||
d="M12.983 8.978c3.955 -.182 7.017 -1.446 7.017 -2.978c0 -1.657 -3.582 -3 -8 -3c-1.661 0 -3.204 .19 -4.483 .515m-2.783 1.228c-.471 .382 -.734 .808 -.734 1.257c0 1.22 1.944 2.271 4.734 2.74" />
|
d="M12.983 8.978c3.955 -.182 7.017 -1.446 7.017 -2.978c0 -1.657 -3.582 -3 -8 -3c-1.661 0 -3.204 .19 -4.483 .515m-2.783 1.228c-.471 .382 -.734 .808 -.734 1.257c0 1.22 1.944 2.271 4.734 2.74" />
|
||||||
@@ -51,8 +53,9 @@
|
|||||||
Restart
|
Restart
|
||||||
</x-forms.button>
|
</x-forms.button>
|
||||||
<x-modal-confirmation title="Confirm Service Stopping?" buttonTitle="Stop" submitAction="stop"
|
<x-modal-confirmation title="Confirm Service Stopping?" buttonTitle="Stop" submitAction="stop"
|
||||||
:checkboxes="$checkboxes" :actions="[__('service.stop'), __('resource.non_persistent')]" :confirmWithText="false" :confirmWithPassword="false" step1ButtonText="Continue"
|
:checkboxes="$checkboxes" :actions="[__('service.stop'), __('resource.non_persistent')]" :confirmWithText="false" :confirmWithPassword="false"
|
||||||
step2ButtonText="Stop Service" :dispatchEvent="true" dispatchEventType="stopEvent">
|
step1ButtonText="Continue" step2ButtonText="Stop Service" :dispatchEvent="true"
|
||||||
|
dispatchEventType="stopEvent">
|
||||||
<x-slot:button-title>
|
<x-slot:button-title>
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-error" viewBox="0 0 24 24"
|
<svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-error" viewBox="0 0 24 24"
|
||||||
stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
|
stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
|
||||||
@@ -60,7 +63,8 @@
|
|||||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
||||||
<path d="M6 5m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z">
|
<path d="M6 5m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z">
|
||||||
</path>
|
</path>
|
||||||
<path d="M14 5m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z">
|
<path
|
||||||
|
d="M14 5m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z">
|
||||||
</path>
|
</path>
|
||||||
</svg>
|
</svg>
|
||||||
Stop
|
Stop
|
||||||
@@ -88,7 +92,8 @@
|
|||||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
||||||
<path d="M6 5m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z">
|
<path d="M6 5m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z">
|
||||||
</path>
|
</path>
|
||||||
<path d="M14 5m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z">
|
<path
|
||||||
|
d="M14 5m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z">
|
||||||
</path>
|
</path>
|
||||||
</svg>
|
</svg>
|
||||||
Stop
|
Stop
|
||||||
@@ -124,7 +129,8 @@
|
|||||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
||||||
<path d="M6 5m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z">
|
<path d="M6 5m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z">
|
||||||
</path>
|
</path>
|
||||||
<path d="M14 5m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z">
|
<path
|
||||||
|
d="M14 5m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z">
|
||||||
</path>
|
</path>
|
||||||
</svg>
|
</svg>
|
||||||
Stop
|
Stop
|
||||||
@@ -141,6 +147,16 @@
|
|||||||
</button>
|
</button>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
@else
|
||||||
|
<div class="flex flex-wrap order-first gap-2 items-center sm:order-last">
|
||||||
|
<div class="text-error">
|
||||||
|
Unable to deploy. <a
|
||||||
|
class="underline font-bold cursor-pointer"
|
||||||
|
@click.prevent="activeTab = 'environment-variables'; window.location.hash = 'environment-variables'">
|
||||||
|
Required environment variables missing.</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
@script
|
@script
|
||||||
<script>
|
<script>
|
||||||
|
|||||||
@@ -37,7 +37,14 @@
|
|||||||
<h3>Production Environment Variables</h3>
|
<h3>Production Environment Variables</h3>
|
||||||
<div>Environment (secrets) variables for Production.</div>
|
<div>Environment (secrets) variables for Production.</div>
|
||||||
</div>
|
</div>
|
||||||
@forelse ($resource->environment_variables as $env)
|
@php
|
||||||
|
$requiredEmptyVars = $resource->environment_variables->filter(function($env) {
|
||||||
|
return $env->is_required && empty($env->value);
|
||||||
|
});
|
||||||
|
$otherVars = $resource->environment_variables->diff($requiredEmptyVars);
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
@forelse ($requiredEmptyVars->merge($otherVars) as $env)
|
||||||
<livewire:project.shared.environment-variable.show wire:key="environment-{{ $env->id }}"
|
<livewire:project.shared.environment-variable.show wire:key="environment-{{ $env->id }}"
|
||||||
:env="$env" :type="$resource->type()" />
|
:env="$env" :type="$resource->type()" />
|
||||||
@empty
|
@empty
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
<div>
|
<div>
|
||||||
<form wire:submit='submit'
|
<form wire:submit='submit'
|
||||||
class="flex flex-col items-center gap-4 p-4 bg-white border lg:items-start dark:bg-base dark:border-coolgray-300">
|
@class([
|
||||||
|
'flex flex-col items-center gap-4 p-4 bg-white border lg:items-start dark:bg-base',
|
||||||
|
'border-error' => $env->is_really_required,
|
||||||
|
'dark:border-coolgray-300' => !$env->is_really_required,
|
||||||
|
])
|
||||||
|
>
|
||||||
@if ($isLocked)
|
@if ($isLocked)
|
||||||
<div class="flex flex-1 w-full gap-2">
|
<div class="flex flex-1 w-full gap-2">
|
||||||
<x-forms.input disabled id="env.key" />
|
<x-forms.input disabled id="env.key" />
|
||||||
|
|||||||
Reference in New Issue
Block a user