diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-04-03 13:49:54 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-04-03 14:03:16 +0300 |
commit | fd30b3d4972180b6e91d0180b140f32622c48b1d (patch) | |
tree | 9ff40552f415568869ee3ec86c2f5a276c3ab4b9 /app | |
parent | 6fefa794304a6233368b592422ea0fb71a2700f0 (diff) |
Ensure root container repository when visiting registry
Root container repository is a images repository that had been created
before 9.1, before we introduced multi-level images support.
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/registry/repositories_controller.rb | 16 | ||||
-rw-r--r-- | app/models/container_repository.rb | 12 |
2 files changed, 26 insertions, 2 deletions
diff --git a/app/controllers/projects/registry/repositories_controller.rb b/app/controllers/projects/registry/repositories_controller.rb index 2901d83fcef..ab4344bcf3c 100644 --- a/app/controllers/projects/registry/repositories_controller.rb +++ b/app/controllers/projects/registry/repositories_controller.rb @@ -2,6 +2,7 @@ module Projects module Registry class RepositoriesController < ::Projects::Registry::ApplicationController before_action :authorize_update_container_image!, only: [:destroy] + before_action :ensure_root_container_repository!, only: [:index] def index @images = project.container_repositories @@ -22,6 +23,21 @@ module Projects def image @image ||= project.container_repositories.find_by(id: params[:id]) end + + ## + # Container repository object for root project path. + # + # Needed to maintain a backwards compatibility. + # + def ensure_root_container_repository! + ContainerRegistry::Path.new(@project.full_path).tap do |path| + return if path.has_repository? + + ContainerRepository.build_from_path(path).tap do |repository| + repository.save if repository.has_tags? + end + end + end end end end diff --git a/app/models/container_repository.rb b/app/models/container_repository.rb index 0cf781799e9..36158d75ae8 100644 --- a/app/models/container_repository.rb +++ b/app/models/container_repository.rb @@ -48,6 +48,10 @@ class ContainerRepository < ActiveRecord::Base tags.to_a.any? end + def root_repository? + name.empty? + end + def delete_tags! return unless has_tags? @@ -58,8 +62,12 @@ class ContainerRepository < ActiveRecord::Base end end + def self.build_from_path(path) + self.new(project: path.repository_project, + name: path.repository_name) + end + def self.create_from_path!(path) - self.create(project: path.repository_project, - name: path.repository_name) + build_from_path(path).tap(&:save!) end end |