mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-19 09:51:37 +00:00
fix consecutive deployment issue (#62)
* fix consecutive deployment issue * fix styles
This commit is contained in:
parent
1e1204fe40
commit
38e23a1ceb
@ -15,7 +15,7 @@ DB_USERNAME=root
|
|||||||
DB_PASSWORD=
|
DB_PASSWORD=
|
||||||
|
|
||||||
BROADCAST_DRIVER=null
|
BROADCAST_DRIVER=null
|
||||||
CACHE_DRIVER=redis
|
CACHE_DRIVER=file
|
||||||
FILESYSTEM_DRIVER=local
|
FILESYSTEM_DRIVER=local
|
||||||
QUEUE_CONNECTION=default
|
QUEUE_CONNECTION=default
|
||||||
SESSION_DRIVER=database
|
SESSION_DRIVER=database
|
||||||
|
@ -3,13 +3,12 @@
|
|||||||
namespace App\Jobs;
|
namespace App\Jobs;
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
abstract class Job implements ShouldQueue, ShouldBeUnique
|
abstract class Job implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
use App\Enums\DeploymentStatus;
|
use App\Enums\DeploymentStatus;
|
||||||
use App\Events\Broadcast;
|
use App\Events\Broadcast;
|
||||||
use App\Helpers\SSH;
|
|
||||||
use App\Jobs\Job;
|
use App\Jobs\Job;
|
||||||
use App\Models\Deployment;
|
use App\Models\Deployment;
|
||||||
use App\SSHCommands\System\RunScriptCommand;
|
use App\SSHCommands\System\RunScriptCommand;
|
||||||
@ -18,13 +17,11 @@ class Deploy extends Job
|
|||||||
|
|
||||||
protected string $script;
|
protected string $script;
|
||||||
|
|
||||||
protected SSH $ssh;
|
public function __construct(Deployment $deployment, string $path)
|
||||||
|
|
||||||
public function __construct(Deployment $deployment, string $path, string $script)
|
|
||||||
{
|
{
|
||||||
|
$this->script = $deployment->deploymentScript->content;
|
||||||
$this->deployment = $deployment;
|
$this->deployment = $deployment;
|
||||||
$this->path = $path;
|
$this->path = $path;
|
||||||
$this->script = $script;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,28 +29,31 @@ public function __construct(Deployment $deployment, string $path, string $script
|
|||||||
*/
|
*/
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
$this->ssh = $this->deployment->site->server->ssh();
|
$ssh = $this->deployment->site->server->ssh();
|
||||||
$this->ssh->exec(
|
try {
|
||||||
new RunScriptCommand($this->path, $this->script),
|
$ssh->exec(
|
||||||
'deploy',
|
new RunScriptCommand($this->path, $this->script),
|
||||||
$this->deployment->site_id
|
'deploy',
|
||||||
);
|
$this->deployment->site_id
|
||||||
$this->deployment->status = DeploymentStatus::FINISHED;
|
);
|
||||||
$this->deployment->log_id = $this->ssh->log->id;
|
$this->deployment->status = DeploymentStatus::FINISHED;
|
||||||
$this->deployment->save();
|
$this->deployment->log_id = $ssh->log->id;
|
||||||
event(
|
$this->deployment->save();
|
||||||
new Broadcast('deploy-site-finished', [
|
event(
|
||||||
'deployment' => $this->deployment,
|
new Broadcast('deploy-site-finished', [
|
||||||
])
|
'deployment' => $this->deployment,
|
||||||
);
|
])
|
||||||
|
);
|
||||||
|
} catch (Throwable) {
|
||||||
|
$this->deployment->log_id = $ssh->log->id;
|
||||||
|
$this->deployment->save();
|
||||||
|
$this->failed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function failed(): void
|
public function failed(): void
|
||||||
{
|
{
|
||||||
$this->deployment->status = DeploymentStatus::FAILED;
|
$this->deployment->status = DeploymentStatus::FAILED;
|
||||||
if ($this->ssh->log) {
|
|
||||||
$this->deployment->log_id = $this->ssh->log->id;
|
|
||||||
}
|
|
||||||
$this->deployment->save();
|
$this->deployment->save();
|
||||||
event(
|
event(
|
||||||
new Broadcast('deploy-site-failed', [
|
new Broadcast('deploy-site-failed', [
|
||||||
|
@ -266,13 +266,7 @@ public function deploy(): Deployment
|
|||||||
}
|
}
|
||||||
$deployment->save();
|
$deployment->save();
|
||||||
|
|
||||||
dispatch(
|
dispatch(new Deploy($deployment, $this->path))->onConnection('ssh');
|
||||||
new Deploy(
|
|
||||||
$deployment,
|
|
||||||
$this->path,
|
|
||||||
$this->deployment_script_text
|
|
||||||
)
|
|
||||||
)->onConnection('ssh');
|
|
||||||
|
|
||||||
return $deployment;
|
return $deployment;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,4 @@ if ! cd __path__; then
|
|||||||
echo 'VITO_SSH_ERROR' && exit 1
|
echo 'VITO_SSH_ERROR' && exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! __script__; then
|
__script__
|
||||||
echo 'VITO_SSH_ERROR' && exit 1
|
|
||||||
fi
|
|
||||||
|
@ -16,9 +16,7 @@ public function test_generate_command()
|
|||||||
echo 'VITO_SSH_ERROR' && exit 1
|
echo 'VITO_SSH_ERROR' && exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! script; then
|
script
|
||||||
echo 'VITO_SSH_ERROR' && exit 1
|
|
||||||
fi
|
|
||||||
EOD;
|
EOD;
|
||||||
|
|
||||||
$this->assertStringContainsString($expected, $command->content());
|
$this->assertStringContainsString($expected, $command->content());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user