@@ -495,7 +495,6 @@ private function upload_to_s3(): void
495
495
$ network = $ this ->database ->destination ->network ;
496
496
}
497
497
498
- // Ensure helper image is available before using it
499
498
$ this ->ensureHelperImageAvailable ();
500
499
501
500
$ settings = InstanceSettings::get ();
@@ -508,7 +507,6 @@ private function upload_to_s3(): void
508
507
$ commands [] = "docker exec backup-of- {$ this ->backup ->uuid } mc cp $ this ->backup_location temporary/ $ bucket {$ this ->backup_dir }/ " ;
509
508
instant_remote_process ($ commands , $ this ->server );
510
509
$ this ->add_to_backup_output ('Uploaded to S3. ' );
511
- ray ('Uploaded to S3. ' .$ this ->backup_location .' to s3:// ' .$ bucket .$ this ->backup_dir );
512
510
} catch (\Throwable $ e ) {
513
511
$ this ->add_to_backup_output ($ e ->getMessage ());
514
512
throw $ e ;
@@ -521,38 +519,33 @@ private function upload_to_s3(): void
521
519
private function ensureHelperImageAvailable (): void
522
520
{
523
521
$ settings = InstanceSettings::get ();
524
- ray ($ settings );
525
-
526
522
$ 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
- }
523
+ $ latestVersion = $ settings ->helper_version ;
524
+ $ fullImageName = "{$ helperImage }: {$ latestVersion }" ;
525
+
526
+ $ imageExists = $ this ->checkImageExists ($ fullImageName );
527
+
528
+ if (!$ imageExists ) {
529
+ $ this ->pullHelperImage ($ fullImageName );
552
530
} else {
553
- $ message = "Helper image {$ fullImageName } is available. " ;
554
- ray ($ message );
555
- $ this ->add_to_backup_output ($ message );
531
+ return ;
532
+ }
533
+ }
534
+
535
+ private function checkImageExists (string $ fullImageName ): bool
536
+ {
537
+ $ result = instant_remote_process (["docker image inspect {$ fullImageName } >/dev/null 2>&1 && echo 'exists' || echo 'not exists' " ], $ this ->server , false );
538
+ return trim ($ result ) === 'exists ' ;
539
+ }
540
+
541
+ private function pullHelperImage (string $ fullImageName ): void
542
+ {
543
+ try {
544
+ instant_remote_process (["docker pull {$ fullImageName }" ], $ this ->server );
545
+ } catch (\Exception $ e ) {
546
+ $ errorMessage = "Failed to pull helper image: " . $ e ->getMessage ();
547
+ $ this ->add_to_backup_output ($ errorMessage );
548
+ throw new \RuntimeException ($ errorMessage );
556
549
}
557
550
}
558
551
}
0 commit comments