mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-17 17:01:37 +00:00
deployment script variables (#238)
This commit is contained in:
parent
eec83f577c
commit
7d367465ff
@ -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) {
|
||||
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -24,6 +24,27 @@ class="p-6"
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="mt-6">
|
||||
<div class="flex items-center">
|
||||
<x-input-label class="mr-1" :value="__('Available Variables')" />
|
||||
(
|
||||
<a
|
||||
href="https://vitodeploy.com/sites/application.html#deployment-script"
|
||||
target="_blank"
|
||||
class="text-primary-500"
|
||||
>
|
||||
{{ __("How to use?") }}
|
||||
</a>
|
||||
)
|
||||
</div>
|
||||
<div class="mt-1 rounded-lg bg-gray-100 p-4 dark:bg-gray-700">
|
||||
@foreach ($site->environmentVariables() as $key => $variable)
|
||||
{{ $key }}={{ $variable }}
|
||||
<br />
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 flex items-center justify-end">
|
||||
<x-secondary-button type="button" x-on:click="$dispatch('close')">
|
||||
{{ __("Cancel") }}
|
||||
|
Loading…
x
Reference in New Issue
Block a user