diff --git a/app/Livewire/Project/Shared/GetLogs.php b/app/Livewire/Project/Shared/GetLogs.php
index b1398f909..bb80a4c84 100644
--- a/app/Livewire/Project/Shared/GetLogs.php
+++ b/app/Livewire/Project/Shared/GetLogs.php
@@ -23,6 +23,7 @@ class GetLogs extends Component
public ServiceApplication|ServiceDatabase|null $servicesubtype = null;
public Server $server;
public ?string $container = null;
+ public ?string $pull_request = null;
public ?bool $streamLogs = false;
public ?bool $showTimeStamps = true;
public int $numberOfLines = 100;
@@ -72,6 +73,11 @@ class GetLogs extends Component
{
if (!$refresh && $this->resource?->getMorphClass() === 'App\Models\Service') return;
if ($this->container) {
+ if (str($this->container)->contains('-pr-')) {
+ $this->pull_request = "Pull Request: " . str($this->container)->afterLast('-pr-')->beforeLast('_')->value();
+ } else {
+ $this->pull_request = 'branch';
+ }
if ($this->showTimeStamps) {
if ($this->server->isSwarm()) {
$sshCommand = generateSshCommand($this->server, "docker service logs -n {$this->numberOfLines} -t {$this->container}");
diff --git a/app/Livewire/Project/Shared/Logs.php b/app/Livewire/Project/Shared/Logs.php
index 19edbdd7b..3b9a121b8 100644
--- a/app/Livewire/Project/Shared/Logs.php
+++ b/app/Livewire/Project/Shared/Logs.php
@@ -41,13 +41,19 @@ class Logs extends Component
]
]);
} else {
- $containers = getCurrentApplicationContainerStatus($this->server, $this->resource->id, 0);
+ $containers = getCurrentApplicationContainerStatus($this->server, $this->resource->id, includePullrequests: true);
}
if ($containers->count() > 0) {
$containers->each(function ($container) {
$this->containers->push(str_replace('/', '', $container['Names']));
});
}
+ $this->containers = $this->containers->sortByDesc(function ($container) {
+ if (str_contains($container, '-pr-')) {
+ return explode('-pr-', $container)[1];
+ }
+ return $container;
+ });
} else if (data_get($this->parameters, 'database_uuid')) {
$this->type = 'database';
$resource = StandalonePostgresql::where('uuid', $this->parameters['database_uuid'])->first();
@@ -70,21 +76,15 @@ class Logs extends Component
$this->status = $this->resource->status;
$this->server = $this->resource->destination->server;
$this->container = $this->resource->uuid;
- // if (str(data_get($this, 'resource.status'))->startsWith('running')) {
- $this->containers->push($this->container);
- // }
+ $this->containers->push($this->container);
} else if (data_get($this->parameters, 'service_uuid')) {
$this->type = 'service';
$this->resource = Service::where('uuid', $this->parameters['service_uuid'])->firstOrFail();
$this->resource->applications()->get()->each(function ($application) {
- // if (str(data_get($application, 'status'))->contains('running')) {
- $this->containers->push(data_get($application, 'name') . '-' . data_get($this->resource, 'uuid'));
- // }
+ $this->containers->push(data_get($application, 'name') . '-' . data_get($this->resource, 'uuid'));
});
$this->resource->databases()->get()->each(function ($database) {
- // if (str(data_get($database, 'status'))->contains('running')) {
- $this->containers->push(data_get($database, 'name') . '-' . data_get($this->resource, 'uuid'));
- // }
+ $this->containers->push(data_get($database, 'name') . '-' . data_get($this->resource, 'uuid'));
});
$this->server = $this->resource->server;
diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.php
index 6a3e3f839..008bd4d7f 100644
--- a/bootstrap/helpers/docker.php
+++ b/bootstrap/helpers/docker.php
@@ -8,18 +8,21 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Spatie\Url\Url;
-function getCurrentApplicationContainerStatus(Server $server, int $id, ?int $pullRequestId = null): Collection
+function getCurrentApplicationContainerStatus(Server $server, int $id, ?int $pullRequestId = null, ?bool $includePullrequests = false): Collection
{
$containers = collect([]);
if (!$server->isSwarm()) {
$containers = instant_remote_process(["docker ps -a --filter='label=coolify.applicationId={$id}' --format '{{json .}}' "], $server);
$containers = format_docker_command_output_to_json($containers);
- $containers = $containers->map(function ($container) use ($pullRequestId) {
+ $containers = $containers->map(function ($container) use ($pullRequestId, $includePullrequests) {
$labels = data_get($container, 'Labels');
if (!str($labels)->contains("coolify.pullRequestId=")) {
data_set($container, 'Labels', $labels . ",coolify.pullRequestId={$pullRequestId}");
return $container;
}
+ if ($includePullrequests) {
+ return $container;
+ }
if (str($labels)->contains("coolify.pullRequestId=$pullRequestId")) {
return $container;
}
diff --git a/resources/views/livewire/project/application/previews.blade.php b/resources/views/livewire/project/application/previews.blade.php
index dfa76cc83..6aa9f1d28 100644
--- a/resources/views/livewire/project/application/previews.blade.php
+++ b/resources/views/livewire/project/application/previews.blade.php
@@ -86,15 +86,21 @@
Redeploy
@endif
-