From 682da0d6d58da4c7092d85920b21443af5ad0f64 Mon Sep 17 00:00:00 2001 From: Saeed Vaziry Date: Thu, 22 Feb 2024 20:30:21 +0100 Subject: [PATCH] load the actual env from the server --- app/Actions/Site/UpdateEnv.php | 0 app/Http/Livewire/Application/Env.php | 6 ++--- app/Jobs/Site/DeployEnv.php | 4 +-- app/Models/Site.php | 10 +++++++ app/SSHCommands/Website/GetEnvCommand.php | 26 +++++++++++++++++++ resources/commands/website/get-env.sh | 1 + .../views/livewire/application/env.blade.php | 2 +- 7 files changed, 42 insertions(+), 7 deletions(-) mode change 100755 => 100644 app/Actions/Site/UpdateEnv.php create mode 100755 app/SSHCommands/Website/GetEnvCommand.php create mode 100644 resources/commands/website/get-env.sh diff --git a/app/Actions/Site/UpdateEnv.php b/app/Actions/Site/UpdateEnv.php old mode 100755 new mode 100644 diff --git a/app/Http/Livewire/Application/Env.php b/app/Http/Livewire/Application/Env.php index 38ec33a..abfcfc0 100644 --- a/app/Http/Livewire/Application/Env.php +++ b/app/Http/Livewire/Application/Env.php @@ -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 diff --git a/app/Jobs/Site/DeployEnv.php b/app/Jobs/Site/DeployEnv.php index c4cd10a..1e396a3 100644 --- a/app/Jobs/Site/DeployEnv.php +++ b/app/Jobs/Site/DeployEnv.php @@ -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', [ diff --git a/app/Models/Site.php b/app/Models/Site.php index 9cd1681..f2c59fb 100755 --- a/app/Models/Site.php +++ b/app/Models/Site.php @@ -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 + ) + ); + } } diff --git a/app/SSHCommands/Website/GetEnvCommand.php b/app/SSHCommands/Website/GetEnvCommand.php new file mode 100755 index 0000000..0bc439f --- /dev/null +++ b/app/SSHCommands/Website/GetEnvCommand.php @@ -0,0 +1,26 @@ +file()) + ->replace('__domain__', $this->domain) + ->toString(); + } +} diff --git a/resources/commands/website/get-env.sh b/resources/commands/website/get-env.sh new file mode 100644 index 0000000..a7ded68 --- /dev/null +++ b/resources/commands/website/get-env.sh @@ -0,0 +1 @@ +[ -f /home/vito/__domain__/.env ] && cat /home/vito/__domain__/.env diff --git a/resources/views/livewire/application/env.blade.php b/resources/views/livewire/application/env.blade.php index 65ed561..da8c964 100644 --- a/resources/views/livewire/application/env.blade.php +++ b/resources/views/livewire/application/env.blade.php @@ -7,7 +7,7 @@
- + @error('env') @enderror