load the actual env from the server

This commit is contained in:
Saeed Vaziry 2024-02-22 20:30:21 +01:00
parent 9db310a06b
commit 682da0d6d5
7 changed files with 42 additions and 7 deletions

0
app/Actions/Site/UpdateEnv.php Executable file → Normal file
View File

View File

@ -14,11 +14,11 @@ class Env extends Component
public Site $site;
public string $env;
public string $env = 'Loading...';
public function mount(): void
public function loadEnv(): void
{
$this->env = $this->site->env;
$this->env = $this->site->getEnv();
}
public function save(): void

View File

@ -26,9 +26,7 @@ public function handle(): void
new EditFileCommand(
$this->site->path.'/.env',
$this->site->env
),
'update-env',
$this->site->id
)
);
event(
new Broadcast('deploy-site-env-finished', [

View File

@ -15,6 +15,7 @@
use App\Jobs\Site\UpdateBranch;
use App\Notifications\SiteInstallationFailed;
use App\Notifications\SiteInstallationSucceed;
use App\SSHCommands\Website\GetEnvCommand;
use Exception;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@ -442,4 +443,13 @@ public function isReady(): bool
{
return $this->status === SiteStatus::READY;
}
public function getEnv(): string
{
return $this->server->ssh()->exec(
new GetEnvCommand(
$this->domain
)
);
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\SSHCommands\Website;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class GetEnvCommand extends Command
{
public function __construct(
protected string $domain
) {
}
public function file(): string
{
return File::get(resource_path('commands/website/get-env.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__domain__', $this->domain)
->toString();
}
}

View File

@ -0,0 +1 @@
[ -f /home/vito/__domain__/.env ] && cat /home/vito/__domain__/.env

View File

@ -7,7 +7,7 @@
<div class="mt-6">
<x-input-label for="env" :value="__('.env')" />
<x-textarea wire:model="env" rows="10" id="env" name="env" class="mt-1 w-full" />
<x-textarea id="env" wire:init="loadEnv" wire:model="env" rows="10" class="mt-1 block w-full"></x-textarea>
@error('env')
<x-input-error class="mt-2" :messages="$message" />
@enderror