feat: debuggable executeNow commands

This commit is contained in:
Andras Bacsai 2023-04-14 13:18:55 +02:00
parent 1ba57ef6c3
commit 14919980c2
5 changed files with 42 additions and 23 deletions

View File

@ -53,6 +53,14 @@ public function stop()
$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()
{

View File

@ -19,6 +19,14 @@ public function __construct(
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 @@ protected function checkContainerStatus()
Log::error($e->getMessage());
}
}
public function handle(): void
{
if ($this->container_id) {
$this->checkContainerStatus();
} else {
$this->checkAllServers();
}
}
}

View File

@ -97,7 +97,7 @@ public function handle(): void
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 @@ public function handle(): void
$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 @@ private function set_labels_for_applications()
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 @@ private function executeNow(array|Collection $command, string $propertyName = nu
'command' => $commandText,
]);
$this->activity->save();
if ($isDebuggable && !$this->application->settings->is_debug) {
$hideFromOutput = true;
}
$remoteProcess = resolve(RunRemoteProcess::class, [
'activity' => $this->activity,
'hideFromOutput' => $hideFromOutput,

View File

@ -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();
}
}

View File

@ -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>