mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-19 09:51: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();
|
$log->save();
|
||||||
$deployment->log_id = $log->id;
|
$deployment->log_id = $log->id;
|
||||||
$deployment->save();
|
$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->status = DeploymentStatus::FINISHED;
|
||||||
$deployment->save();
|
$deployment->save();
|
||||||
})->catch(function () use ($deployment) {
|
})->catch(function () use ($deployment) {
|
||||||
|
@ -283,4 +283,17 @@ public function hasSSL(): bool
|
|||||||
{
|
{
|
||||||
return $this->ssls->isNotEmpty();
|
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);
|
$ssh = $this->server->ssh($user);
|
||||||
if ($serverLog) {
|
if ($serverLog) {
|
||||||
$ssh->setLog($serverLog);
|
$ssh->setLog($serverLog);
|
||||||
}
|
}
|
||||||
$ssh->exec(
|
$command = '';
|
||||||
$this->getScript('run-script.sh', [
|
foreach ($variables as $key => $variable) {
|
||||||
'path' => $path,
|
$command .= "$key=$variable".PHP_EOL;
|
||||||
'script' => $script,
|
}
|
||||||
]),
|
$command .= $this->getScript('run-script.sh', [
|
||||||
'run-script'
|
'path' => $path,
|
||||||
);
|
'script' => $script,
|
||||||
|
]);
|
||||||
|
$ssh->exec($command, 'run-script');
|
||||||
|
|
||||||
|
info($command);
|
||||||
|
|
||||||
return $ssh->log;
|
return $ssh->log;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,27 @@ class="p-6"
|
|||||||
@enderror
|
@enderror
|
||||||
</div>
|
</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">
|
<div class="mt-6 flex items-center justify-end">
|
||||||
<x-secondary-button type="button" x-on:click="$dispatch('close')">
|
<x-secondary-button type="button" x-on:click="$dispatch('close')">
|
||||||
{{ __("Cancel") }}
|
{{ __("Cancel") }}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user