@@ -3425,7 +3425,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
3425
3425
$ defaultLabels = defaultLabels ($ resource ->id , $ containerName , type: 'service ' , subType: $ isDatabase ? 'database ' : 'application ' , subId: $ savedService ->id );
3426
3426
}
3427
3427
// Add COOLIFY_FQDN & COOLIFY_URL to environment
3428
- if (! $ isDatabase && $ fqdns? ->count() > 0 ) {
3428
+ if (! $ isDatabase && $ fqdns instanceof Collection && $ fqdns ->count () > 0 ) {
3429
3429
$ environment ->put ('COOLIFY_URL ' , $ fqdns ->implode (', ' ));
3430
3430
3431
3431
$ urls = $ fqdns ->map (function ($ fqdn ) {
@@ -3436,7 +3436,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
3436
3436
add_coolify_default_environment_variables ($ resource , $ environment , $ resource ->environment_variables );
3437
3437
3438
3438
$ serviceLabels = $ labels ->merge ($ defaultLabels );
3439
- if (! $ isDatabase && $ fqdns? ->count() > 0 ) {
3439
+ if (! $ isDatabase && $ fqdns instanceof Collection && $ fqdns ->count () > 0 ) {
3440
3440
if ($ isApplication ) {
3441
3441
$ shouldGenerateLabelsExactly = $ resource ->destination ->server ->settings ->generate_exact_labels ;
3442
3442
$ uuid = $ resource ->uuid ;
@@ -3544,7 +3544,6 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
3544
3544
3545
3545
$ parsedServices ->put ($ serviceName , $ payload );
3546
3546
}
3547
- ray ($ parsedServices );
3548
3547
$ topLevel ->put ('services ' , $ parsedServices );
3549
3548
$ customOrder = ['services ' , 'volumes ' , 'networks ' , 'configs ' , 'secrets ' ];
3550
3549
@@ -3574,6 +3573,23 @@ function generate_fluentd_configuration(): array
3574
3573
];
3575
3574
}
3576
3575
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
+
3577
3593
/**
3578
3594
* This method adds the default environment variables to the resource.
3579
3595
* - COOLIFY_APP_NAME
@@ -3585,42 +3601,45 @@ function generate_fluentd_configuration(): array
3585
3601
*/
3586
3602
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 )
3587
3603
{
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
+ }
3588
3614
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 ) {
3592
3616
$ where_to_add ->put ('COOLIFY_APP_NAME ' , $ resource ->name );
3593
3617
} else {
3594
3618
$ where_to_add ->push ("COOLIFY_APP_NAME= {$ resource ->name }" );
3595
3619
}
3596
3620
}
3597
3621
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 );
3602
3624
} else {
3603
- $ where_to_add ->push ("COOLIFY_SERVER_IP= {$ resource -> destination -> server -> ip }" );
3625
+ $ where_to_add ->push ("COOLIFY_SERVER_IP= {$ ip }" );
3604
3626
}
3605
3627
}
3606
3628
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 ) {
3610
3630
$ where_to_add ->put ('COOLIFY_ENVIRONMENT_NAME ' , $ resource ->environment ->name );
3611
3631
} else {
3612
3632
$ where_to_add ->push ("COOLIFY_ENVIRONMENT_NAME= {$ resource ->environment ->name }" );
3613
3633
}
3614
3634
}
3615
3635
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 ) {
3619
3637
$ where_to_add ->put ('COOLIFY_PROJECT_NAME ' , $ resource ->project ()->name );
3620
3638
} else {
3621
3639
$ where_to_add ->push ("COOLIFY_PROJECT_NAME= {$ resource ->project ()->name }" );
3622
3640
}
3623
3641
}
3642
+ ray ($ where_to_add );
3624
3643
}
3625
3644
3626
3645
function convertComposeEnvironmentToArray ($ environment )
@@ -3648,7 +3667,9 @@ function convertComposeEnvironmentToArray($environment)
3648
3667
}
3649
3668
}
3650
3669
}
3651
- $ convertedServiceVariables ->put ($ key ->value (), $ value ?->value() ?? null );
3670
+ if ($ key ) {
3671
+ $ convertedServiceVariables ->put ($ key ->value (), $ value ?->value() ?? null );
3672
+ }
3652
3673
}
3653
3674
3654
3675
return $ convertedServiceVariables ;
0 commit comments