fix: order
feat: add batch counter
This commit is contained in:
parent
040e5a5198
commit
174fc76fb8
@ -4,6 +4,7 @@ namespace App\Actions\RemoteProcess;
|
|||||||
|
|
||||||
use App\Enums\ActivityTypes;
|
use App\Enums\ActivityTypes;
|
||||||
use App\Enums\ProcessStatus;
|
use App\Enums\ProcessStatus;
|
||||||
|
use App\Jobs\DeployApplicationJob;
|
||||||
use Illuminate\Process\ProcessResult;
|
use Illuminate\Process\ProcessResult;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Process;
|
use Illuminate\Support\Facades\Process;
|
||||||
@ -69,6 +70,15 @@ class RunRemoteProcess
|
|||||||
return $processResult;
|
return $processResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getLatestCounter(): int
|
||||||
|
{
|
||||||
|
$description = json_decode($this->activity->description, associative: true, flags: JSON_THROW_ON_ERROR);
|
||||||
|
if ($description === null || count($description) === 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return end($description)['order'] + 1;
|
||||||
|
}
|
||||||
|
|
||||||
protected function getCommand(): string
|
protected function getCommand(): string
|
||||||
{
|
{
|
||||||
$user = $this->activity->getExtraProperty('user');
|
$user = $this->activity->getExtraProperty('user');
|
||||||
@ -106,8 +116,9 @@ class RunRemoteProcess
|
|||||||
$outputStack[] = [
|
$outputStack[] = [
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'output' => $output,
|
'output' => $output,
|
||||||
'elapsed_time' => $this->elapsedTime(),
|
'timestamp' => hrtime(true),
|
||||||
'order' => $this->counter++,
|
'batch' => DeployApplicationJob::$batch_counter,
|
||||||
|
'order' => $this->getLatestCounter(),
|
||||||
];
|
];
|
||||||
|
|
||||||
return json_encode($outputStack, flags: JSON_THROW_ON_ERROR);
|
return json_encode($outputStack, flags: JSON_THROW_ON_ERROR);
|
||||||
@ -115,12 +126,13 @@ class RunRemoteProcess
|
|||||||
|
|
||||||
public static function decodeOutput(?Activity $activity = null): string
|
public static function decodeOutput(?Activity $activity = null): string
|
||||||
{
|
{
|
||||||
if(is_null($activity)) {
|
if (is_null($activity)) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$decoded = json_decode(data_get($activity, 'description'),
|
$decoded = json_decode(
|
||||||
|
data_get($activity, 'description'),
|
||||||
associative: true,
|
associative: true,
|
||||||
flags: JSON_THROW_ON_ERROR
|
flags: JSON_THROW_ON_ERROR
|
||||||
);
|
);
|
||||||
@ -129,9 +141,9 @@ class RunRemoteProcess
|
|||||||
}
|
}
|
||||||
|
|
||||||
return collect($decoded)
|
return collect($decoded)
|
||||||
->sortBy(fn($i) => $i['order'])
|
->sortBy(fn ($i) => $i['order'])
|
||||||
->map(fn($i) => $i['output'])
|
->map(fn ($i) => $i['output'])
|
||||||
->implode("\n");
|
->implode("");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,6 +33,7 @@ class DeployApplicationJob implements ShouldQueue
|
|||||||
protected Activity $activity;
|
protected Activity $activity;
|
||||||
protected string $git_commit;
|
protected string $git_commit;
|
||||||
protected string $workdir;
|
protected string $workdir;
|
||||||
|
public static int $batch_counter = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
@ -93,14 +94,14 @@ class DeployApplicationJob implements ShouldQueue
|
|||||||
"echo -n 'Pulling latest version of the builder image (ghcr.io/coollabsio/coolify-builder)... '",
|
"echo -n 'Pulling latest version of the builder image (ghcr.io/coollabsio/coolify-builder)... '",
|
||||||
"docker run --pull=always -d --name {$this->deployment_uuid} --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/coollabsio/coolify-builder >/dev/null 2>&1",
|
"docker run --pull=always -d --name {$this->deployment_uuid} --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/coollabsio/coolify-builder >/dev/null 2>&1",
|
||||||
"echo 'Done.'",
|
"echo 'Done.'",
|
||||||
], 'docker_pull_builder_image');
|
]);
|
||||||
|
|
||||||
// Import git repository
|
// Import git repository
|
||||||
$this->executeNow([
|
$this->executeNow([
|
||||||
"echo -n 'Importing {$this->application->git_repository}:{$this->application->git_branch} to {$this->workdir}... '",
|
"echo -n 'Importing {$this->application->git_repository}:{$this->application->git_branch} to {$this->workdir}... '",
|
||||||
$this->gitImport(),
|
$this->gitImport(),
|
||||||
"echo 'Done.'"
|
"echo 'Done.'"
|
||||||
], 'importing_git_repository');
|
]);
|
||||||
|
|
||||||
// Get git commit
|
// Get git commit
|
||||||
$this->executeNow([$this->execute_in_builder("cd {$this->workdir} && git rev-parse HEAD")], 'commit_sha', hideFromOutput: true);
|
$this->executeNow([$this->execute_in_builder("cd {$this->workdir} && git rev-parse HEAD")], 'commit_sha', hideFromOutput: true);
|
||||||
@ -256,6 +257,7 @@ class DeployApplicationJob implements ShouldQueue
|
|||||||
|
|
||||||
private function executeNow(array $command, string $propertyName = null, bool $hideFromOutput = false, $setStatus = false)
|
private function executeNow(array $command, string $propertyName = null, bool $hideFromOutput = false, $setStatus = false)
|
||||||
{
|
{
|
||||||
|
static::$batch_counter++;
|
||||||
$commandText = collect($command)->implode("\n");
|
$commandText = collect($command)->implode("\n");
|
||||||
|
|
||||||
$this->activity->properties = $this->activity->properties->merge([
|
$this->activity->properties = $this->activity->properties->merge([
|
||||||
|
Loading…
x
Reference in New Issue
Block a user