Skip to content

Commit b2bab45

Browse files
authored
Merge pull request coollabsio#3457 from coollabsio/next
v4.0.0-beta.337
2 parents 0c4ce55 + 7b4559c commit b2bab45

24 files changed

+154
-95
lines changed

app/Actions/Service/StartService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function handle(Service $service)
1616
$service->saveComposeConfigs();
1717
$commands[] = 'cd '.$service->workdir();
1818
$commands[] = "echo 'Saved configuration files to {$service->workdir()}.'";
19-
if($service->networks()->count() > 0){
19+
if ($service->networks()->count() > 0) {
2020
$commands[] = "echo 'Creating Docker network.'";
2121
$commands[] = "docker network inspect $service->uuid >/dev/null 2>&1 || docker network create --attachable $service->uuid";
2222
}
@@ -31,7 +31,7 @@ public function handle(Service $service)
3131
$network = $service->destination->network;
3232
$serviceNames = data_get(Yaml::parse($compose), 'services', []);
3333
foreach ($serviceNames as $serviceName => $serviceConfig) {
34-
$commands[] = "docker network connect --alias {$serviceName}-{$service->uuid} $network {$serviceName}-{$service->uuid} || true";
34+
$commands[] = "docker network connect --alias {$serviceName}-{$service->uuid} $network {$serviceName}-{$service->uuid} >/dev/null 2>&1 || true";
3535
}
3636
}
3737
$activity = remote_process($commands, $service->server, type_uuid: $service->uuid, callEventOnFinish: 'ServiceStatusChanged');

app/Jobs/ApplicationDeploymentJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ private function deploy_docker_compose_buildpack()
514514
'hidden' => true,
515515
'ignore_errors' => true,
516516
], [
517-
"docker network connect {$networkId} coolify-proxy || true",
517+
"docker network connect {$networkId} coolify-proxy >/dev/null 2>&1 || true",
518518
'hidden' => true,
519519
'ignore_errors' => true,
520520
]);

app/Livewire/Project/Shared/ExecuteContainerCommand.php

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class ExecuteContainerCommand extends Component
1313
{
14-
public string $container;
14+
public $container;
1515

1616
public Collection $containers;
1717

@@ -57,24 +57,13 @@ public function mount()
5757
if ($this->resource->destination->server->isFunctional()) {
5858
$this->servers = $this->servers->push($this->resource->destination->server);
5959
}
60-
$this->container = $this->resource->uuid;
61-
$this->containers->push($this->container);
6260
} elseif (data_get($this->parameters, 'service_uuid')) {
6361
$this->type = 'service';
6462
$this->resource = Service::where('uuid', $this->parameters['service_uuid'])->firstOrFail();
65-
$this->resource->applications()->get()->each(function ($application) {
66-
$this->containers->push(data_get($application, 'name').'-'.data_get($this->resource, 'uuid'));
67-
});
68-
$this->resource->databases()->get()->each(function ($database) {
69-
$this->containers->push(data_get($database, 'name').'-'.data_get($this->resource, 'uuid'));
70-
});
7163
if ($this->resource->server->isFunctional()) {
7264
$this->servers = $this->servers->push($this->resource->server);
7365
}
7466
}
75-
if ($this->containers->count() > 0) {
76-
$this->container = $this->containers->first();
77-
}
7867
}
7968

8069
public function loadContainers()
@@ -97,37 +86,56 @@ public function loadContainers()
9786
];
9887
$this->containers = $this->containers->push($payload);
9988
}
100-
}
101-
}
102-
if ($this->containers->count() > 0) {
103-
if (data_get($this->parameters, 'application_uuid')) {
104-
$this->container = data_get($this->containers->first(), 'container.Names');
10589
} elseif (data_get($this->parameters, 'database_uuid')) {
106-
$this->container = $this->containers->first();
90+
if ($this->resource->isRunning()) {
91+
$this->containers = $this->containers->push([
92+
'server' => $server,
93+
'container' => [
94+
'Names' => $this->resource->uuid,
95+
],
96+
]);
97+
}
10798
} elseif (data_get($this->parameters, 'service_uuid')) {
108-
$this->container = $this->containers->first();
109-
}
110-
if ($this->containers->count() === 1) {
111-
$this->dispatch('connectToContainer');
99+
$this->resource->applications()->get()->each(function ($application) {
100+
ray($application);
101+
if ($application->isRunning()) {
102+
$this->containers->push([
103+
'server' => $this->resource->server,
104+
'container' => [
105+
'Names' => data_get($application, 'name').'-'.data_get($this->resource, 'uuid'),
106+
],
107+
]);
108+
}
109+
});
110+
$this->resource->databases()->get()->each(function ($database) {
111+
if ($database->isRunning()) {
112+
$this->containers->push([
113+
'server' => $this->resource->server,
114+
'container' => [
115+
'Names' => data_get($database, 'name').'-'.data_get($this->resource, 'uuid'),
116+
],
117+
]);
118+
}
119+
});
112120
}
121+
122+
}
123+
if ($this->containers->count() > 0) {
124+
$this->container = $this->containers->first();
113125
}
114126
}
115127

116128
#[On('connectToContainer')]
117129
public function connectToContainer()
118130
{
119131
try {
120-
if (data_get($this->parameters, 'application_uuid')) {
121-
$container = $this->containers->where('container.Names', $this->container)->first();
122-
$container_name = data_get($container, 'container.Names');
123-
if (is_null($container)) {
124-
throw new \RuntimeException('Container not found.');
125-
}
126-
$server = data_get($container, 'server');
127-
} else {
128-
$container_name = $this->container;
129-
$server = $this->servers->first();
132+
$container_name = data_get($this->container, 'container.Names');
133+
ray($this->container);
134+
if (is_null($container_name)) {
135+
throw new \RuntimeException('Container not found.');
130136
}
137+
$server = data_get($this->container, 'server');
138+
131139
if ($server->isForceDisabled()) {
132140
throw new \RuntimeException('Server is disabled.');
133141
}

app/Livewire/Project/Shared/Terminal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function sendTerminalCommand($isContainer, $identifier, $serverUuid)
2424
if ($isContainer) {
2525
$status = getContainerStatus($server, $identifier);
2626
if ($status !== 'running') {
27-
return handleError(new \Exception('Container is not running'), $this);
27+
return;
2828
}
2929
$command = generateSshCommand($server, "docker exec -it {$identifier} sh -c 'if [ -f ~/.profile ]; then . ~/.profile; fi; if [ -n \"\$SHELL\" ]; then exec \$SHELL; else sh; fi'");
3030
} else {

app/Models/ServiceApplication.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ public static function ownedByCurrentTeamAPI(int $teamId)
3232
return ServiceApplication::whereRelation('service.environment.project.team', 'id', $teamId)->orderBy('name');
3333
}
3434

35+
public function isRunning()
36+
{
37+
return str($this->status)->contains('running');
38+
}
39+
40+
public function isExited()
41+
{
42+
return str($this->status)->contains('exited');
43+
}
44+
3545
public function isLogDrainEnabled()
3646
{
3747
return data_get($this, 'is_log_drain_enabled', false);

app/Models/ServiceDatabase.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ public function restart()
2525
remote_process(["docker restart {$container_id}"], $this->service->server);
2626
}
2727

28+
public function isRunning()
29+
{
30+
return str($this->status)->contains('running');
31+
}
32+
33+
public function isExited()
34+
{
35+
return str($this->status)->contains('exited');
36+
}
37+
2838
public function isLogDrainEnabled()
2939
{
3040
return data_get($this, 'is_log_drain_enabled', false);

app/Models/StandaloneClickhouse.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public function isConfigurationChanged(bool $save = false)
7575
}
7676
}
7777

78+
public function isRunning()
79+
{
80+
return (bool) str($this->status)->contains('running');
81+
}
82+
7883
public function isExited()
7984
{
8085
return (bool) str($this->status)->startsWith('exited');

app/Models/StandaloneDragonfly.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public function isConfigurationChanged(bool $save = false)
7575
}
7676
}
7777

78+
public function isRunning()
79+
{
80+
return (bool) str($this->status)->contains('running');
81+
}
82+
7883
public function isExited()
7984
{
8085
return (bool) str($this->status)->startsWith('exited');

app/Models/StandaloneKeydb.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public function isConfigurationChanged(bool $save = false)
7575
}
7676
}
7777

78+
public function isRunning()
79+
{
80+
return (bool) str($this->status)->contains('running');
81+
}
82+
7883
public function isExited()
7984
{
8085
return (bool) str($this->status)->startsWith('exited');

app/Models/StandaloneMariadb.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public function isConfigurationChanged(bool $save = false)
7575
}
7676
}
7777

78+
public function isRunning()
79+
{
80+
return (bool) str($this->status)->contains('running');
81+
}
82+
7883
public function isExited()
7984
{
8085
return (bool) str($this->status)->startsWith('exited');

0 commit comments

Comments
 (0)