@@ -474,19 +474,47 @@ export class ImageRunModal extends React.Component {
474
474
475
475
this . setState ( { searchFinished : false , searchInProgress : true } ) ;
476
476
this . activeConnection = rest . connect ( client . getAddress ( this . state . isSystem ) , this . state . isSystem ) ;
477
+ let searches = [ ] ;
478
+
479
+ // If there are registries configured search in them, or if a user searches for `docker.io/cockpit` let
480
+ // podman search in the user specified registry.
481
+ if ( Object . keys ( this . props . registries ) . length !== 0 || value . includes ( '/' ) ) {
482
+ searches . push ( this . activeConnection . call ( {
483
+ method : "GET" ,
484
+ path : client . VERSION + "libpod/images/search" ,
485
+ body : "" ,
486
+ params : {
487
+ term : value ,
488
+ }
489
+ } ) ) ;
490
+ } else {
491
+ searches = searches . concat ( utils . fallbackRegistries . map ( registry =>
492
+ this . activeConnection . call ( {
493
+ method : "GET" ,
494
+ path : client . VERSION + "libpod/images/search" ,
495
+ body : "" ,
496
+ params : {
497
+ term : registry + "/" + value
498
+ }
499
+ } ) ) ) ;
500
+ }
477
501
478
- const options = {
479
- method : "GET" ,
480
- path : client . VERSION + "libpod/images/search" ,
481
- body : "" ,
482
- params : {
483
- term : value ,
484
- } ,
485
- } ;
486
- this . activeConnection . call ( options )
502
+ Promise . allSettled ( searches )
487
503
. then ( reply => {
488
504
if ( reply && this . _isMounted ) {
489
- const imageResults = JSON . parse ( reply ) ;
505
+ let imageResults = [ ] ;
506
+ let dialogError = "" ;
507
+ let dialogErrorDetail = "" ;
508
+
509
+ for ( const result of reply ) {
510
+ if ( result . status === "fulfilled" ) {
511
+ imageResults = imageResults . concat ( JSON . parse ( result . value ) ) ;
512
+ } else {
513
+ dialogError = _ ( "Failed to search for new images" ) ;
514
+ // TODO: add registry context, podman does not include it in the reply.
515
+ dialogErrorDetail = cockpit . format ( _ ( "Failed to search for images: $0" ) , result . reason ) ;
516
+ }
517
+ }
490
518
// Group images on registry
491
519
const images = { } ;
492
520
imageResults . forEach ( image => {
@@ -516,17 +544,8 @@ export class ImageRunModal extends React.Component {
516
544
imageResults : images || { } ,
517
545
searchFinished : true ,
518
546
searchInProgress : false ,
519
- dialogError : ""
520
- } ) ;
521
- }
522
- } )
523
- . catch ( ex => {
524
- if ( this . _isMounted ) {
525
- this . setState ( {
526
- searchFinished : true ,
527
- searchInProgress : false ,
528
- dialogError : _ ( "Failed to search for new images" ) ,
529
- dialogErrorDetail : cockpit . format ( _ ( "Failed to search for images: $0" ) , ex . message ? ex . message : "" )
547
+ dialogError,
548
+ dialogErrorDetail,
530
549
} ) ;
531
550
}
532
551
} ) ;
@@ -665,6 +684,8 @@ export class ImageRunModal extends React.Component {
665
684
imageListOptions = this . filterImages ( ) ;
666
685
}
667
686
687
+ const registries = this . props . registries && this . props . registries . search ? this . props . registries . search : utils . fallbackRegistries ;
688
+
668
689
// Add the search component
669
690
const footer = (
670
691
< ToggleGroup className = 'image-search-footer' aria-label = { _ ( "Search by registry" ) } >
@@ -685,19 +706,18 @@ export class ImageRunModal extends React.Component {
685
706
ev . stopPropagation ( ) ;
686
707
} }
687
708
/>
688
- { this . props . registries && this . props . registries . search &&
689
- this . props . registries . search . map ( registry => {
690
- const index = this . truncateRegistryDomain ( registry ) ;
691
- return (
692
- < ToggleGroupItem text = { index } key = { index } isSelected = { this . state . searchByRegistry == index } onChange = { ( _ , ev ) => {
693
- ev . stopPropagation ( ) ;
694
- this . setState ( { searchByRegistry : index } ) ;
695
- } }
709
+ { registries . map ( registry => {
710
+ const index = this . truncateRegistryDomain ( registry ) ;
711
+ return (
712
+ < ToggleGroupItem text = { index } key = { index } isSelected = { this . state . searchByRegistry == index } onChange = { ( _ , ev ) => {
713
+ ev . stopPropagation ( ) ;
714
+ this . setState ( { searchByRegistry : index } ) ;
715
+ } }
696
716
onTouchStart = { ev => {
697
717
ev . stopPropagation ( ) ;
698
718
} }
699
- /> ) ;
700
- } ) }
719
+ /> ) ;
720
+ } ) }
701
721
</ ToggleGroup >
702
722
) ;
703
723
0 commit comments