25
25
use Illuminate \Queue \Middleware \WithoutOverlapping ;
26
26
use Illuminate \Queue \SerializesModels ;
27
27
use Illuminate \Support \Str ;
28
+ use App \Models \InstanceSettings ;
28
29
29
30
class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
30
31
{
@@ -493,7 +494,16 @@ private function upload_to_s3(): void
493
494
} else {
494
495
$ network = $ this ->database ->destination ->network ;
495
496
}
496
- $ commands [] = "docker run -d --network {$ network } --name backup-of- {$ this ->backup ->uuid } --rm -v $ this ->backup_location : $ this ->backup_location :ro ghcr.io/coollabsio/coolify-helper " ;
497
+
498
+ // Ensure helper image is available before using it
499
+ $ this ->ensureHelperImageAvailable ();
500
+
501
+ $ settings = InstanceSettings::get ();
502
+ $ helperImage = config ('coolify.helper_image ' );
503
+ $ helperImageTag = $ settings ->helper_version ;
504
+ $ fullImageName = "{$ helperImage }: {$ helperImageTag }" ;
505
+
506
+ $ commands [] = "docker run -d --network {$ network } --name backup-of- {$ this ->backup ->uuid } --rm -v $ this ->backup_location : $ this ->backup_location :ro {$ fullImageName }" ;
497
507
$ commands [] = "docker exec backup-of- {$ this ->backup ->uuid } mc config host add temporary {$ endpoint } $ key $ secret " ;
498
508
$ commands [] = "docker exec backup-of- {$ this ->backup ->uuid } mc cp $ this ->backup_location temporary/ $ bucket {$ this ->backup_dir }/ " ;
499
509
instant_remote_process ($ commands , $ this ->server );
@@ -507,4 +517,42 @@ private function upload_to_s3(): void
507
517
instant_remote_process ([$ command ], $ this ->server );
508
518
}
509
519
}
520
+
521
+ private function ensureHelperImageAvailable (): void
522
+ {
523
+ $ settings = InstanceSettings::get ();
524
+ ray ($ settings );
525
+
526
+ $ helperImage = config ('coolify.helper_image ' );
527
+ ray ('Helper Image: ' , $ helperImage );
528
+
529
+ $ helperImageTag = $ settings ->helper_version ;
530
+ ray ('Helper Image Tag: ' , $ helperImageTag );
531
+
532
+ $ fullImageName = "{$ helperImage }: {$ helperImageTag }" ;
533
+ ray ('Full Image Name: ' , $ fullImageName );
534
+
535
+ $ imageExists = instant_remote_process (["docker image inspect {$ fullImageName }" ], $ this ->server , false );
536
+ ray ('Image Exists: ' , $ imageExists );
537
+
538
+ if (empty ($ imageExists )) {
539
+ $ this ->add_to_backup_output ("Helper image not found. Pulling {$ fullImageName }. " );
540
+ ray ('Helper image not found. Attempting to pull. ' );
541
+ try {
542
+ $ pullResult = instant_remote_process (["docker pull {$ fullImageName }" ], $ this ->server );
543
+ ray ('Pull Result: ' , $ pullResult );
544
+ $ this ->add_to_backup_output ("Helper image pulled successfully. " );
545
+ ray ('Helper image pulled successfully. ' );
546
+ } catch (\Exception $ e ) {
547
+ $ errorMessage = "Failed to pull helper image: " . $ e ->getMessage ();
548
+ ray ('Error: ' , $ errorMessage );
549
+ $ this ->add_to_backup_output ($ errorMessage );
550
+ throw new \RuntimeException ($ errorMessage );
551
+ }
552
+ } else {
553
+ $ message = "Helper image {$ fullImageName } is available. " ;
554
+ ray ($ message );
555
+ $ this ->add_to_backup_output ($ message );
556
+ }
557
+ }
510
558
}
0 commit comments