diff --git a/app/Actions/Site/Deploy.php b/app/Actions/Site/Deploy.php index 32ad7420..2e9a4106 100644 --- a/app/Actions/Site/Deploy.php +++ b/app/Actions/Site/Deploy.php @@ -44,7 +44,12 @@ public function run(Site $site): Deployment $log->save(); $deployment->log_id = $log->id; $deployment->save(); - $site->server->os()->runScript($site->path, $site->deploymentScript->content, $log); + $site->server->os()->runScript( + path: $site->path, + script: $site->deploymentScript->content, + serverLog: $log, + variables: $site->environmentVariables($deployment) + ); $deployment->status = DeploymentStatus::FINISHED; $deployment->save(); })->catch(function () use ($deployment) { diff --git a/app/Models/Site.php b/app/Models/Site.php index 0daacf3b..d63e3167 100755 --- a/app/Models/Site.php +++ b/app/Models/Site.php @@ -283,4 +283,17 @@ public function hasSSL(): bool { return $this->ssls->isNotEmpty(); } + + public function environmentVariables(?Deployment $deployment = null): array + { + return [ + 'SITE_PATH' => $this->path, + 'DOMAIN' => $this->domain, + 'BRANCH' => $this->branch ?? '', + 'REPOSITORY' => $this->repository ?? '', + 'COMMIT_ID' => $deployment?->commit_id ?? '', + 'PHP_VERSION' => $this->php_version, + 'PHP_PATH' => '/usr/bin/php'.$this->php_version, + ]; + } } diff --git a/app/SSH/OS/OS.php b/app/SSH/OS/OS.php index f2796801..4f5b66ba 100644 --- a/app/SSH/OS/OS.php +++ b/app/SSH/OS/OS.php @@ -140,19 +140,23 @@ public function tail(string $path, int $lines): string ); } - public function runScript(string $path, string $script, ?ServerLog $serverLog, ?string $user = null): ServerLog + public function runScript(string $path, string $script, ?ServerLog $serverLog, ?string $user = null, ?array $variables = []): ServerLog { $ssh = $this->server->ssh($user); if ($serverLog) { $ssh->setLog($serverLog); } - $ssh->exec( - $this->getScript('run-script.sh', [ - 'path' => $path, - 'script' => $script, - ]), - 'run-script' - ); + $command = ''; + foreach ($variables as $key => $variable) { + $command .= "$key=$variable".PHP_EOL; + } + $command .= $this->getScript('run-script.sh', [ + 'path' => $path, + 'script' => $script, + ]); + $ssh->exec($command, 'run-script'); + + info($command); return $ssh->log; } diff --git a/resources/views/application/deployment-script.blade.php b/resources/views/application/deployment-script.blade.php index 1bedfcb3..4876449d 100644 --- a/resources/views/application/deployment-script.blade.php +++ b/resources/views/application/deployment-script.blade.php @@ -24,6 +24,27 @@ class="p-6" @enderror +
+
+ + ( + + {{ __("How to use?") }} + + ) +
+
+ @foreach ($site->environmentVariables() as $key => $variable) + {{ $key }}={{ $variable }} +
+ @endforeach +
+
+
{{ __("Cancel") }}