Skip to content

Commit 3badbaf

Browse files
authored
Merge pull request coollabsio#3298 from coollabsio/next
v4.0.0-beta.326
2 parents eb6add3 + 7b041f3 commit 3badbaf

File tree

6 files changed

+62
-29
lines changed

6 files changed

+62
-29
lines changed

app/Models/Service.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
use Illuminate\Database\Eloquent\Relations\HasMany;
88
use Illuminate\Database\Eloquent\SoftDeletes;
99
use Illuminate\Support\Collection;
10+
use Illuminate\Support\Facades\Storage;
1011
use OpenApi\Attributes as OA;
1112
use Spatie\Url\Url;
12-
use Symfony\Component\Yaml\Yaml;
13+
use Visus\Cuid2\Cuid2;
1314

1415
#[OA\Schema(
1516
description: 'Service model',
@@ -999,14 +1000,18 @@ public function workdir()
9991000
public function saveComposeConfigs()
10001001
{
10011002
$workdir = $this->workdir();
1002-
$commands[] = "mkdir -p $workdir";
1003-
$commands[] = "cd $workdir";
10041003

1005-
$json = Yaml::parse($this->docker_compose);
1006-
$this->docker_compose = Yaml::dump($json, 10, 2, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK);
1007-
$docker_compose_base64 = base64_encode($this->docker_compose);
1004+
instant_remote_process([
1005+
"mkdir -p $workdir",
1006+
"cd $workdir",
1007+
], $this->server);
1008+
1009+
$filename = new Cuid2.'-docker-compose.yml';
1010+
Storage::disk('local')->put("tmp/{$filename}", $this->docker_compose);
1011+
$path = Storage::path("tmp/{$filename}");
1012+
instant_scp($path, "{$workdir}/docker-compose.yml", $this->server);
1013+
Storage::disk('local')->delete("tmp/{$filename}");
10081014

1009-
$commands[] = "echo $docker_compose_base64 | base64 -d | tee docker-compose.yml > /dev/null";
10101015
$commands[] = 'rm -f .env || true';
10111016

10121017
$envs_from_coolify = $this->environment_variables()->get();

bootstrap/helpers/shared.php

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3425,7 +3425,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
34253425
$defaultLabels = defaultLabels($resource->id, $containerName, type: 'service', subType: $isDatabase ? 'database' : 'application', subId: $savedService->id);
34263426
}
34273427
// Add COOLIFY_FQDN & COOLIFY_URL to environment
3428-
if (! $isDatabase && $fqdns?->count() > 0) {
3428+
if (! $isDatabase && $fqdns instanceof Collection && $fqdns->count() > 0) {
34293429
$environment->put('COOLIFY_URL', $fqdns->implode(','));
34303430

34313431
$urls = $fqdns->map(function ($fqdn) {
@@ -3436,7 +3436,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
34363436
add_coolify_default_environment_variables($resource, $environment, $resource->environment_variables);
34373437

34383438
$serviceLabels = $labels->merge($defaultLabels);
3439-
if (! $isDatabase && $fqdns?->count() > 0) {
3439+
if (! $isDatabase && $fqdns instanceof Collection && $fqdns->count() > 0) {
34403440
if ($isApplication) {
34413441
$shouldGenerateLabelsExactly = $resource->destination->server->settings->generate_exact_labels;
34423442
$uuid = $resource->uuid;
@@ -3544,7 +3544,6 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
35443544

35453545
$parsedServices->put($serviceName, $payload);
35463546
}
3547-
ray($parsedServices);
35483547
$topLevel->put('services', $parsedServices);
35493548
$customOrder = ['services', 'volumes', 'networks', 'configs', 'secrets'];
35503549

@@ -3574,6 +3573,23 @@ function generate_fluentd_configuration(): array
35743573
];
35753574
}
35763575

3576+
function isAssociativeArray($array)
3577+
{
3578+
if ($array instanceof Collection) {
3579+
$array = $array->toArray();
3580+
}
3581+
3582+
if (! is_array($array)) {
3583+
throw new \InvalidArgumentException('Input must be an array or a Collection.');
3584+
}
3585+
3586+
if ($array === []) {
3587+
return false;
3588+
}
3589+
3590+
return array_keys($array) !== range(0, count($array) - 1);
3591+
}
3592+
35773593
/**
35783594
* This method adds the default environment variables to the resource.
35793595
* - COOLIFY_APP_NAME
@@ -3585,42 +3601,45 @@ function generate_fluentd_configuration(): array
35853601
*/
35863602
function add_coolify_default_environment_variables(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|Application|Service $resource, Collection &$where_to_add, ?Collection $where_to_check = null)
35873603
{
3604+
if ($resource instanceof Service) {
3605+
$ip = $resource->server->ip;
3606+
} else {
3607+
$ip = $resource->destination->server->ip;
3608+
}
3609+
if (isAssociativeArray($where_to_add)) {
3610+
$isAssociativeArray = true;
3611+
} else {
3612+
$isAssociativeArray = false;
3613+
}
35883614
if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_APP_NAME')->isEmpty()) {
3589-
if ($resource instanceof Application && $resource->build_pack === 'dockercompose') {
3590-
$where_to_add->put('COOLIFY_APP_NAME', $resource->name);
3591-
} elseif ($resource instanceof Service) {
3615+
if ($isAssociativeArray) {
35923616
$where_to_add->put('COOLIFY_APP_NAME', $resource->name);
35933617
} else {
35943618
$where_to_add->push("COOLIFY_APP_NAME={$resource->name}");
35953619
}
35963620
}
35973621
if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) {
3598-
if ($resource instanceof Application && $resource->build_pack === 'dockercompose') {
3599-
$where_to_add->put('COOLIFY_SERVER_IP', $resource->destination->server->ip);
3600-
} elseif ($resource instanceof Service) {
3601-
$where_to_add->put('COOLIFY_SERVER_IP', $resource->server->ip);
3622+
if ($isAssociativeArray) {
3623+
$where_to_add->put('COOLIFY_SERVER_IP', $ip);
36023624
} else {
3603-
$where_to_add->push("COOLIFY_SERVER_IP={$resource->destination->server->ip}");
3625+
$where_to_add->push("COOLIFY_SERVER_IP={$ip}");
36043626
}
36053627
}
36063628
if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) {
3607-
if ($resource instanceof Application && $resource->build_pack === 'dockercompose') {
3608-
$where_to_add->put('COOLIFY_ENVIRONMENT_NAME', $resource->environment->name);
3609-
} elseif ($resource instanceof Service) {
3629+
if ($isAssociativeArray) {
36103630
$where_to_add->put('COOLIFY_ENVIRONMENT_NAME', $resource->environment->name);
36113631
} else {
36123632
$where_to_add->push("COOLIFY_ENVIRONMENT_NAME={$resource->environment->name}");
36133633
}
36143634
}
36153635
if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) {
3616-
if ($resource instanceof Application && $resource->build_pack === 'dockercompose') {
3617-
$where_to_add->put('COOLIFY_PROJECT_NAME', $resource->project()->name);
3618-
} elseif ($resource instanceof Service) {
3636+
if ($isAssociativeArray) {
36193637
$where_to_add->put('COOLIFY_PROJECT_NAME', $resource->project()->name);
36203638
} else {
36213639
$where_to_add->push("COOLIFY_PROJECT_NAME={$resource->project()->name}");
36223640
}
36233641
}
3642+
ray($where_to_add);
36243643
}
36253644

36263645
function convertComposeEnvironmentToArray($environment)
@@ -3648,7 +3667,9 @@ function convertComposeEnvironmentToArray($environment)
36483667
}
36493668
}
36503669
}
3651-
$convertedServiceVariables->put($key->value(), $value?->value() ?? null);
3670+
if ($key) {
3671+
$convertedServiceVariables->put($key->value(), $value?->value() ?? null);
3672+
}
36523673
}
36533674

36543675
return $convertedServiceVariables;

config/sentry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
// The release version of your application
99
// Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD'))
10-
'release' => '4.0.0-beta.325',
10+
'release' => '4.0.0-beta.326',
1111
// When left empty or `null` the Laravel environment will be used
1212
'environment' => config('app.env'),
1313

config/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
return '4.0.0-beta.325';
3+
return '4.0.0-beta.326';

tests/Feature/ConvertArraysTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
test('isAssociativeArray', function () {
4+
expect(isAssociativeArray([1, 2, 3]))->toBeFalse();
5+
expect(isAssociativeArray(collect([1, 2, 3])))->toBeFalse();
6+
expect(isAssociativeArray(collect(['a' => 1, 'b' => 2, 'c' => 3])))->toBeTrue();
7+
});

versions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"coolify": {
33
"v4": {
4-
"version": "4.0.0-beta.325"
4+
"version": "4.0.0-beta.326"
55
},
66
"nightly": {
7-
"version": "4.0.0-beta.325"
7+
"version": "4.0.0-beta.327"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)