Accurate deployment statuses (#168)

This commit is contained in:
Saeed Vaziry
2024-04-21 16:26:26 +02:00
committed by GitHub
parent e2dd9177f7
commit f0da1c6d8c
11 changed files with 88 additions and 35 deletions

View File

@ -50,14 +50,9 @@ public function init(Server $server, ?string $asUser = null): self
return $this;
}
public function setLog(string $logType, $siteId = null): self
public function setLog(ServerLog $log): self
{
$this->log = $this->server->logs()->create([
'site_id' => $siteId,
'name' => $this->server->id.'-'.strtotime('now').'-'.$logType.'.log',
'type' => $logType,
'disk' => config('core.logs_disk'),
]);
$this->log = $log;
return $this;
}
@ -98,10 +93,18 @@ public function connect(bool $sftp = false): void
*/
public function exec(string $command, string $log = '', ?int $siteId = null, ?bool $stream = false): string
{
if ($log) {
$this->setLog($log, $siteId);
} else {
$this->log = null;
if (! $this->log && $log) {
$this->log = $this->server->logs()->create([
'site_id' => $siteId,
'name' => $this->server->id.'-'.strtotime('now').'-'.$log.'.log',
'type' => $log,
'disk' => config('core.logs_disk'),
]);
$this->log = ServerLog::make($this->server, $log);
if ($siteId) {
$this->log->forSite($siteId);
}
$this->log->save();
}
try {
@ -132,8 +135,8 @@ public function exec(string $command, string $log = '', ?int $siteId = null, ?bo
$this->log?->write($output);
if (Str::contains($output, 'VITO_SSH_ERROR')) {
throw new SSHCommandError('SSH command failed with an error');
if ($this->connection->getExitStatus() !== 0 || Str::contains($output, 'VITO_SSH_ERROR')) {
throw new SSHCommandError('SSH command failed with an error', $this->connection->getExitStatus());
}
return $output;