This commit is contained in:
Andras Bacsai 2023-05-31 14:57:42 +02:00
parent 25870dadd8
commit 8991de2610
8 changed files with 20 additions and 19 deletions

View File

@ -9,6 +9,7 @@ class Deployments extends Component
{
public int $application_id;
public $deployments = [];
public int $deployments_count = 0;
public string $current_url;
public int $skip = 0;
public int $default_take = 8;
@ -24,15 +25,14 @@ public function reload_deployments()
}
public function load_deployments(int|null $take = null)
{
ray('Take' . $take);
if ($take) {
ray('Take is not null');
$this->skip = $this->skip + $take;
}
$take = $this->default_take;
$this->deployments = Application::find($this->application_id)->deployments($this->skip, $take);
['deployments' => $deployments, 'count' => $count] = Application::find($this->application_id)->deployments($this->skip, $take);
$this->deployments = $deployments;
$this->deployments_count = $count;
if (count($this->deployments) !== 0 && count($this->deployments) < $take) {
$this->show_next = false;
return;

View File

@ -37,7 +37,6 @@ public function submit()
{
$this->validate();
$this->application->preview_url_template = str_replace(' ', '', $this->application->preview_url_template);
ray($this->application->preview_url_template);
$this->application->save();
$this->generate_real_url();
}

View File

@ -41,12 +41,12 @@ public function load_prs()
$this->rate_limit_remaining = $rate_limit_remaining;
$this->pull_requests = $data->sortBy('number')->values();
}
public function deploy(int $pull_request_id, string|null $pull_request_html_url)
public function deploy(int $pull_request_id, string|null $pull_request_html_url = null)
{
try {
$this->set_deployment_uuid();
$found = ApplicationPreview::where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
if (!$found) {
if (!$found && !is_null($pull_request_html_url)) {
ApplicationPreview::create([
'application_id' => $this->application->id,
'pull_request_id' => $pull_request_id,

View File

@ -269,7 +269,6 @@ public function failed(): void
private function next(string $status)
{
ray($this->application_deployment_queue->status, Str::of($this->application_deployment_queue->status)->startsWith('cancelled'));
if (!Str::of($this->application_deployment_queue->status)->startsWith('cancelled')) {
$this->application_deployment_queue->update([
'status' => $status,
@ -522,7 +521,7 @@ private function execute_now(
} else {
$commandText = collect($command)->implode("\n");
}
ray('Executing command', $commandText);
ray('Executing command: ' . $commandText);
$this->activity->properties = $this->activity->properties->merge([
'command' => $commandText,
]);
@ -623,7 +622,6 @@ private function nixpacks_build_cmd()
$nixpacks_command .= " --install-cmd \"{$this->application->install_command}\"";
}
$nixpacks_command .= " {$this->workdir}";
ray('Build command: ' . $nixpacks_command);
return $this->execute_in_builder($nixpacks_command);
}
private function stop_running_container()

View File

@ -34,9 +34,8 @@ public function uniqueId(): string
public function handle(): void
{
try {
ray('running ContainerStatusJob', $this->container_name, $this->pull_request_id);
$status = get_container_status(server: $this->application->destination->server, container_id: $this->container_name, throwError: false);
ray('ContainerStatusJob', $status);
ray('Container ' . $this->container_name . ' statuus is ' . $status);
if ($this->pull_request_id) {
$preview = ApplicationPreview::findPreviewByApplicationAndPullId($this->application->id, $this->pull_request_id);
$preview->status = $status;

View File

@ -146,8 +146,13 @@ public function persistentStorages()
public function deployments(int $skip = 0, int $take = 10)
{
ray('Skip ' . $skip . ' Take ' . $take);
return ApplicationDeploymentQueue::where('application_id', $this->id)->orderBy('created_at', 'desc')->skip($skip)->take($take)->get();
$deployments = ApplicationDeploymentQueue::where('application_id', $this->id)->orderBy('created_at', 'desc');
$count = $deployments->count();
$deployments = $deployments->skip($skip)->take($take)->get();
return [
'count' => $count,
'deployments' => $deployments
];
}
public function get_deployment(string $deployment_uuid)
{

View File

@ -16,7 +16,7 @@ function queue_application_deployment(int $application_id, string $deployment_uu
]);
$queued_deployments = ApplicationDeploymentQueue::where('application_id', $application_id)->where('status', 'queued')->get()->sortByDesc('created_at');
$running_deployments = ApplicationDeploymentQueue::where('application_id', $application_id)->where('status', 'in_progress')->get()->sortByDesc('created_at');
ray('Q:' . $queued_deployments->count() . 'R:' . $running_deployments->count() . '|Queuing deployment: ' . $deployment_uuid . ' of applicationID: ' . $application_id . ' pull request: ' . $pull_request_id . ' with commit: ' . $commit . ' and is it forced: ' . $force_rebuild);
ray('Q:' . $queued_deployments->count() . 'R:' . $running_deployments->count() . '| Queuing deployment: ' . $deployment_uuid . ' of applicationID: ' . $application_id . ' pull request: ' . $pull_request_id . ' with commit: ' . $commit . ' and is it forced: ' . $force_rebuild);
if ($queued_deployments->count() > 1) {
$queued_deployments = $queued_deployments->skip(1);
$queued_deployments->each(function ($queued_deployment, $key) {

View File

@ -3,13 +3,13 @@
<div>
<h3>Actions</h3>
@if ($show_next)
<x-forms.button isHighlighted wire:click="load_deployments({{ $default_take }})">Load More
<x-forms.button isHighlighted wire:click="load_deployments({{ $default_take }})">Load Previous
Deployments</x-forms.button>
@else
<x-forms.button disabled>No More Deployments</x-forms.button>
@endif
</div>
<h3>Deployments</h3>
<h3>Deployments <span class="text-xs">({{ $deployments_count }})</span></h3>
@foreach ($deployments as $deployment)
<a @class([
'bg-coolgray-200 p-2 border-l border-dashed transition-colors hover:no-underline',
@ -28,7 +28,8 @@
class="hover:no-underline">
<div class="flex flex-col justify-start">
<div>
{{ $deployment->deployment_uuid }} <span class="text-sm text-warning">></span>
{{ $deployment->id }} <span class="text-sm text-warning">></span> {{ $deployment->deployment_uuid }} <span
class="text-sm text-warning">></span>
{{ $deployment->status }}
</div>
@if (data_get($deployment, 'pull_request_id'))
@ -47,7 +48,6 @@ class="hover:no-underline">
@endif
</div>
@endif
<div class="flex flex-col" x-data="elapsedTime('{{ $deployment->deployment_uuid }}', '{{ $deployment->status }}', '{{ $deployment->created_at }}', '{{ $deployment->updated_at }}')">
<div>Finished <span x-text="measure_since_started()">0s</span> in <span class="font-bold"
x-text="measure_finished_time()">0s</span></div>