feat: debuggable executeNow commands
This commit is contained in:
parent
1ba57ef6c3
commit
14919980c2
@ -53,6 +53,14 @@ class DeployApplication extends Component
|
||||
$this->application->status = 'stopped';
|
||||
$this->application->save();
|
||||
}
|
||||
public function kill()
|
||||
{
|
||||
runRemoteCommandSync($this->destination->server, ["docker rm -f {$this->application_uuid}"]);
|
||||
if ($this->application->status != 'exited') {
|
||||
$this->application->status = 'exited';
|
||||
$this->application->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function pollingStatus()
|
||||
{
|
||||
|
@ -19,6 +19,14 @@ class ContainerStatusJob implements ShouldQueue
|
||||
public string|null $container_id = null,
|
||||
) {
|
||||
}
|
||||
public function handle(): void
|
||||
{
|
||||
if ($this->container_id) {
|
||||
$this->checkContainerStatus();
|
||||
} else {
|
||||
$this->checkAllServers();
|
||||
}
|
||||
}
|
||||
protected function checkAllServers()
|
||||
{
|
||||
try {
|
||||
@ -69,12 +77,4 @@ class ContainerStatusJob implements ShouldQueue
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
public function handle(): void
|
||||
{
|
||||
if ($this->container_id) {
|
||||
$this->checkContainerStatus();
|
||||
} else {
|
||||
$this->checkAllServers();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ class DeployApplicationJob implements ShouldQueue
|
||||
|
||||
if ($this->activity->properties->get('stopped_container_check') == 0) {
|
||||
$this->executeNow([
|
||||
"echo 'Container {$this->application->uuid} was stopped, starting it...'"
|
||||
"echo -n 'Container {$this->application->uuid} was stopped, starting it...'"
|
||||
]);
|
||||
$this->executeNow([
|
||||
"docker start {$this->application->uuid}"
|
||||
@ -144,30 +144,39 @@ class DeployApplicationJob implements ShouldQueue
|
||||
|
||||
$this->executeNow([
|
||||
"echo -n 'Generating nixpacks configuration... '",
|
||||
]);
|
||||
$this->executeNow([
|
||||
$this->nixpacks_build_cmd(),
|
||||
$this->execute_in_builder("cp {$this->workdir}/.nixpacks/Dockerfile {$this->workdir}/Dockerfile"),
|
||||
$this->execute_in_builder("rm -f {$this->workdir}/.nixpacks/Dockerfile"),
|
||||
"echo 'Done.'",
|
||||
]);
|
||||
], isDebuggable: true);
|
||||
|
||||
$this->executeNow([
|
||||
"echo 'Done.'",
|
||||
"echo -n 'Building image... '",
|
||||
$this->execute_in_builder("docker build -f {$this->workdir}/Dockerfile --build-arg SOURCE_COMMIT={$this->git_commit} --progress plain -t {$this->application->uuid}:{$this->git_commit} {$this->workdir}"),
|
||||
"echo 'Done.'",
|
||||
]);
|
||||
|
||||
$this->executeNow([
|
||||
"echo -n 'Removing old container... '",
|
||||
$this->execute_in_builder("docker build -f {$this->workdir}/Dockerfile --build-arg SOURCE_COMMIT={$this->git_commit} --progress plain -t {$this->application->uuid}:{$this->git_commit} {$this->workdir}"),
|
||||
], isDebuggable: true);
|
||||
|
||||
$this->executeNow([
|
||||
"echo 'Done.'",
|
||||
"echo -n 'Removing old instance... '",
|
||||
$this->execute_in_builder("docker rm -f {$this->application->uuid} >/dev/null 2>&1"),
|
||||
"echo 'Done.'",
|
||||
"echo -n 'Starting your application... '",
|
||||
]);
|
||||
$this->executeNow([
|
||||
"echo -n 'Starting new container... '",
|
||||
$this->execute_in_builder("docker compose --project-directory {$this->workdir} up -d >/dev/null"),
|
||||
], isDebuggable: true);
|
||||
|
||||
$this->executeNow([
|
||||
"echo 'Done. 🎉'",
|
||||
"docker stop -t 0 {$this->deployment_uuid} >/dev/null"
|
||||
], setStatus: true);
|
||||
}
|
||||
|
||||
|
||||
dispatch(new ContainerStatusJob($this->application_uuid));
|
||||
|
||||
// Saving docker-compose.yml
|
||||
@ -305,9 +314,10 @@ class DeployApplicationJob implements ShouldQueue
|
||||
return $labels;
|
||||
}
|
||||
|
||||
private function executeNow(array|Collection $command, string $propertyName = null, bool $hideFromOutput = false, $setStatus = false)
|
||||
private function executeNow(array|Collection $command, string $propertyName = null, bool $hideFromOutput = false, $setStatus = false, bool $isDebuggable = false)
|
||||
{
|
||||
static::$batch_counter++;
|
||||
|
||||
if ($command instanceof Collection) {
|
||||
$commandText = $command->implode("\n");
|
||||
} else {
|
||||
@ -318,7 +328,9 @@ class DeployApplicationJob implements ShouldQueue
|
||||
'command' => $commandText,
|
||||
]);
|
||||
$this->activity->save();
|
||||
|
||||
if ($isDebuggable && !$this->application->settings->is_debug) {
|
||||
$hideFromOutput = true;
|
||||
}
|
||||
$remoteProcess = resolve(RunRemoteProcess::class, [
|
||||
'activity' => $this->activity,
|
||||
'hideFromOutput' => $hideFromOutput,
|
||||
|
@ -17,10 +17,8 @@ class ApplicationSettingsSeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $application_1 = Application::find(1);
|
||||
// ApplicationSetting::create([
|
||||
// 'id' => 1,
|
||||
// 'application_id' => $application_1->id,
|
||||
// ]);
|
||||
$application_1 = Application::find(1)->load(['settings']);
|
||||
$application_1->settings->is_debug = false;
|
||||
$application_1->settings->save();
|
||||
}
|
||||
}
|
||||
|
@ -4,5 +4,6 @@
|
||||
@else
|
||||
<button wire:click='start'>Start</button>
|
||||
@endif
|
||||
<button wire:click='kill'>Kill</button>
|
||||
<span wire:poll='pollingStatus'>status: {{ $application->status }}</span>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user