From d18c8d0e8895995bc84bc8963aa4bbb41b30508b Mon Sep 17 00:00:00 2001 From: cong meng Date: Tue, 19 Oct 2021 14:54:53 +1300 Subject: [PATCH] fix(registry) EE-1861 improve registry selection (#5925) * fix(registry) EE-1861 improve registry selection (#5899) * fix(registry) EE-1861 hide anonymous dockerhub registry if user has an authenticated one * fix(registry) EE-1861 pick up a best match dockerhub registry * fix(registry) EE-1861 set the anonymous registry as default if it is shown * fix(registry) EE-1861 refactor how to match registry Co-authored-by: Simon Meng * fix(registry) EE-1861 fail to select registry with same name * fix(registry) EE-1861 show registry modal when pull and push image * fix(registry) EE-1861 cleanup code Co-authored-by: Simon Meng --- .../por-image-registry.controller.js | 12 +++- .../imageRegistry/por-image-registry.html | 2 +- .../views/images/edit/imageController.js | 35 +++++++--- app/portainer/services/api/registryService.js | 65 ++++++++++++++++--- app/portainer/services/modalService.js | 11 ++++ .../services/registryModalService.js | 39 +++++++++++ 6 files changed, 141 insertions(+), 23 deletions(-) create mode 100644 app/portainer/services/registryModalService.js diff --git a/app/docker/components/imageRegistry/por-image-registry.controller.js b/app/docker/components/imageRegistry/por-image-registry.controller.js index 055249917..3e07c77bc 100644 --- a/app/docker/components/imageRegistry/por-image-registry.controller.js +++ b/app/docker/components/imageRegistry/por-image-registry.controller.js @@ -77,13 +77,19 @@ class porImageRegistryController { async reloadRegistries() { return this.$async(async () => { try { - const registries = await this.EndpointService.registries(this.endpoint.Id, this.namespace); - this.registries = _.concat(this.defaultRegistry, registries); + let showDefaultRegistry = false; + this.registries = await this.EndpointService.registries(this.endpoint.Id, this.namespace); + + // hide default(anonymous) dockerhub registry if user has an authenticated one + if (!this.registries.some((registry) => registry.Type === RegistryTypes.DOCKERHUB)) { + showDefaultRegistry = true; + this.registries.push(this.defaultRegistry); + } const id = this.model.Registry.Id; const registry = _.find(this.registries, { Id: id }); if (!registry) { - this.model.Registry = this.defaultRegistry; + this.model.Registry = showDefaultRegistry ? this.defaultRegistry : this.registries[0]; } } catch (err) { this.Notifications.error('Failure', err, 'Unable to retrieve registries'); diff --git a/app/docker/components/imageRegistry/por-image-registry.html b/app/docker/components/imageRegistry/por-image-registry.html index 6fbcd0e21..b3a485ba1 100644 --- a/app/docker/components/imageRegistry/por-image-registry.html +++ b/app/docker/components/imageRegistry/por-image-registry.html @@ -6,7 +6,7 @@