Merge pull request #3298 from coollabsio/next

v4.0.0-beta.326
This commit is contained in:
Andras Bacsai 2024-09-03 17:13:26 +02:00 committed by GitHub
commit 3badbafd89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 62 additions and 29 deletions

View File

@ -7,9 +7,10 @@
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Storage;
use OpenApi\Attributes as OA; use OpenApi\Attributes as OA;
use Spatie\Url\Url; use Spatie\Url\Url;
use Symfony\Component\Yaml\Yaml; use Visus\Cuid2\Cuid2;
#[OA\Schema( #[OA\Schema(
description: 'Service model', description: 'Service model',
@ -999,14 +1000,18 @@ public function workdir()
public function saveComposeConfigs() public function saveComposeConfigs()
{ {
$workdir = $this->workdir(); $workdir = $this->workdir();
$commands[] = "mkdir -p $workdir";
$commands[] = "cd $workdir";
$json = Yaml::parse($this->docker_compose); instant_remote_process([
$this->docker_compose = Yaml::dump($json, 10, 2, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK); "mkdir -p $workdir",
$docker_compose_base64 = base64_encode($this->docker_compose); "cd $workdir",
], $this->server);
$filename = new Cuid2.'-docker-compose.yml';
Storage::disk('local')->put("tmp/{$filename}", $this->docker_compose);
$path = Storage::path("tmp/{$filename}");
instant_scp($path, "{$workdir}/docker-compose.yml", $this->server);
Storage::disk('local')->delete("tmp/{$filename}");
$commands[] = "echo $docker_compose_base64 | base64 -d | tee docker-compose.yml > /dev/null";
$commands[] = 'rm -f .env || true'; $commands[] = 'rm -f .env || true';
$envs_from_coolify = $this->environment_variables()->get(); $envs_from_coolify = $this->environment_variables()->get();

View File

@ -3425,7 +3425,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
$defaultLabels = defaultLabels($resource->id, $containerName, type: 'service', subType: $isDatabase ? 'database' : 'application', subId: $savedService->id); $defaultLabels = defaultLabels($resource->id, $containerName, type: 'service', subType: $isDatabase ? 'database' : 'application', subId: $savedService->id);
} }
// Add COOLIFY_FQDN & COOLIFY_URL to environment // Add COOLIFY_FQDN & COOLIFY_URL to environment
if (! $isDatabase && $fqdns?->count() > 0) { if (! $isDatabase && $fqdns instanceof Collection && $fqdns->count() > 0) {
$environment->put('COOLIFY_URL', $fqdns->implode(',')); $environment->put('COOLIFY_URL', $fqdns->implode(','));
$urls = $fqdns->map(function ($fqdn) { $urls = $fqdns->map(function ($fqdn) {
@ -3436,7 +3436,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
add_coolify_default_environment_variables($resource, $environment, $resource->environment_variables); add_coolify_default_environment_variables($resource, $environment, $resource->environment_variables);
$serviceLabels = $labels->merge($defaultLabels); $serviceLabels = $labels->merge($defaultLabels);
if (! $isDatabase && $fqdns?->count() > 0) { if (! $isDatabase && $fqdns instanceof Collection && $fqdns->count() > 0) {
if ($isApplication) { if ($isApplication) {
$shouldGenerateLabelsExactly = $resource->destination->server->settings->generate_exact_labels; $shouldGenerateLabelsExactly = $resource->destination->server->settings->generate_exact_labels;
$uuid = $resource->uuid; $uuid = $resource->uuid;
@ -3544,7 +3544,6 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
$parsedServices->put($serviceName, $payload); $parsedServices->put($serviceName, $payload);
} }
ray($parsedServices);
$topLevel->put('services', $parsedServices); $topLevel->put('services', $parsedServices);
$customOrder = ['services', 'volumes', 'networks', 'configs', 'secrets']; $customOrder = ['services', 'volumes', 'networks', 'configs', 'secrets'];
@ -3574,6 +3573,23 @@ function generate_fluentd_configuration(): array
]; ];
} }
function isAssociativeArray($array)
{
if ($array instanceof Collection) {
$array = $array->toArray();
}
if (! is_array($array)) {
throw new \InvalidArgumentException('Input must be an array or a Collection.');
}
if ($array === []) {
return false;
}
return array_keys($array) !== range(0, count($array) - 1);
}
/** /**
* This method adds the default environment variables to the resource. * This method adds the default environment variables to the resource.
* - COOLIFY_APP_NAME * - COOLIFY_APP_NAME
@ -3585,42 +3601,45 @@ function generate_fluentd_configuration(): array
*/ */
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) 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)
{ {
if ($resource instanceof Service) {
$ip = $resource->server->ip;
} else {
$ip = $resource->destination->server->ip;
}
if (isAssociativeArray($where_to_add)) {
$isAssociativeArray = true;
} else {
$isAssociativeArray = false;
}
if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_APP_NAME')->isEmpty()) {
if ($resource instanceof Application && $resource->build_pack === 'dockercompose') { if ($isAssociativeArray) {
$where_to_add->put('COOLIFY_APP_NAME', $resource->name);
} elseif ($resource instanceof Service) {
$where_to_add->put('COOLIFY_APP_NAME', $resource->name); $where_to_add->put('COOLIFY_APP_NAME', $resource->name);
} else { } else {
$where_to_add->push("COOLIFY_APP_NAME={$resource->name}"); $where_to_add->push("COOLIFY_APP_NAME={$resource->name}");
} }
} }
if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) {
if ($resource instanceof Application && $resource->build_pack === 'dockercompose') { if ($isAssociativeArray) {
$where_to_add->put('COOLIFY_SERVER_IP', $resource->destination->server->ip); $where_to_add->put('COOLIFY_SERVER_IP', $ip);
} elseif ($resource instanceof Service) {
$where_to_add->put('COOLIFY_SERVER_IP', $resource->server->ip);
} else { } else {
$where_to_add->push("COOLIFY_SERVER_IP={$resource->destination->server->ip}"); $where_to_add->push("COOLIFY_SERVER_IP={$ip}");
} }
} }
if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) {
if ($resource instanceof Application && $resource->build_pack === 'dockercompose') { if ($isAssociativeArray) {
$where_to_add->put('COOLIFY_ENVIRONMENT_NAME', $resource->environment->name);
} elseif ($resource instanceof Service) {
$where_to_add->put('COOLIFY_ENVIRONMENT_NAME', $resource->environment->name); $where_to_add->put('COOLIFY_ENVIRONMENT_NAME', $resource->environment->name);
} else { } else {
$where_to_add->push("COOLIFY_ENVIRONMENT_NAME={$resource->environment->name}"); $where_to_add->push("COOLIFY_ENVIRONMENT_NAME={$resource->environment->name}");
} }
} }
if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) {
if ($resource instanceof Application && $resource->build_pack === 'dockercompose') { if ($isAssociativeArray) {
$where_to_add->put('COOLIFY_PROJECT_NAME', $resource->project()->name);
} elseif ($resource instanceof Service) {
$where_to_add->put('COOLIFY_PROJECT_NAME', $resource->project()->name); $where_to_add->put('COOLIFY_PROJECT_NAME', $resource->project()->name);
} else { } else {
$where_to_add->push("COOLIFY_PROJECT_NAME={$resource->project()->name}"); $where_to_add->push("COOLIFY_PROJECT_NAME={$resource->project()->name}");
} }
} }
ray($where_to_add);
} }
function convertComposeEnvironmentToArray($environment) function convertComposeEnvironmentToArray($environment)
@ -3648,7 +3667,9 @@ function convertComposeEnvironmentToArray($environment)
} }
} }
} }
$convertedServiceVariables->put($key->value(), $value?->value() ?? null); if ($key) {
$convertedServiceVariables->put($key->value(), $value?->value() ?? null);
}
} }
return $convertedServiceVariables; return $convertedServiceVariables;

View File

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

View File

@ -1,3 +1,3 @@
<?php <?php
return '4.0.0-beta.325'; return '4.0.0-beta.326';

View File

@ -0,0 +1,7 @@
<?php
test('isAssociativeArray', function () {
expect(isAssociativeArray([1, 2, 3]))->toBeFalse();
expect(isAssociativeArray(collect([1, 2, 3])))->toBeFalse();
expect(isAssociativeArray(collect(['a' => 1, 'b' => 2, 'c' => 3])))->toBeTrue();
});

View File

@ -1,10 +1,10 @@
{ {
"coolify": { "coolify": {
"v4": { "v4": {
"version": "4.0.0-beta.325" "version": "4.0.0-beta.326"
}, },
"nightly": { "nightly": {
"version": "4.0.0-beta.325" "version": "4.0.0-beta.327"
} }
} }
} }