2017-03-31 07:08:09 -04:00
|
|
|
module Projects
|
|
|
|
module Registry
|
|
|
|
class RepositoriesController < ::Projects::Registry::ApplicationController
|
|
|
|
before_action :authorize_update_container_image!, only: [:destroy]
|
2017-04-03 06:49:54 -04:00
|
|
|
before_action :ensure_root_container_repository!, only: [:index]
|
2017-03-31 07:08:09 -04:00
|
|
|
|
|
|
|
def index
|
|
|
|
@images = project.container_repositories
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
if image.destroy
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to project_container_registry_index_path(@project),
|
2017-06-06 18:45:16 -04:00
|
|
|
status: 302,
|
2017-04-04 05:50:26 -04:00
|
|
|
notice: 'Image repository has been removed successfully!'
|
2017-03-31 07:08:09 -04:00
|
|
|
else
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to project_container_registry_index_path(@project),
|
2017-06-06 18:45:16 -04:00
|
|
|
status: 302,
|
2017-04-04 05:50:26 -04:00
|
|
|
alert: 'Failed to remove image repository!'
|
2017-03-31 07:08:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-31 07:56:07 -04:00
|
|
|
private
|
2017-03-31 07:08:09 -04:00
|
|
|
|
|
|
|
def image
|
2017-04-05 08:18:42 -04:00
|
|
|
@image ||= project.container_repositories.find(params[:id])
|
2017-03-31 07:08:09 -04:00
|
|
|
end
|
2017-04-03 06:49:54 -04:00
|
|
|
|
|
|
|
##
|
|
|
|
# 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|
|
2017-04-03 09:53:51 -04:00
|
|
|
break if path.has_repository?
|
2017-04-03 06:49:54 -04:00
|
|
|
|
|
|
|
ContainerRepository.build_from_path(path).tap do |repository|
|
2017-04-05 08:44:35 -04:00
|
|
|
repository.save! if repository.has_tags?
|
2017-04-03 06:49:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-03-31 07:08:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|