2017-03-31 11:08:09 +00:00
|
|
|
module Projects
|
|
|
|
module Registry
|
|
|
|
class RepositoriesController < ::Projects::Registry::ApplicationController
|
|
|
|
before_action :authorize_update_container_image!, only: [:destroy]
|
2017-04-03 10:49:54 +00:00
|
|
|
before_action :ensure_root_container_repository!, only: [:index]
|
2017-03-31 11:08:09 +00:00
|
|
|
|
|
|
|
def index
|
|
|
|
@images = project.container_repositories
|
2017-09-19 15:38:55 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
2017-09-20 18:03:53 +00:00
|
|
|
# Remove code below
|
2017-09-19 15:38:55 +00:00
|
|
|
render json: [
|
|
|
|
{
|
|
|
|
name: 'gitlab-org/omnibus-gitlab/foo',
|
|
|
|
tags_path: 'foo',
|
|
|
|
destroy_path: 'bar',
|
|
|
|
location: 'foo',
|
|
|
|
id: '134',
|
|
|
|
destroy_path: 'bar'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'gitlab-org/omnibus-gitlab',
|
|
|
|
tags_path: 'foo',
|
|
|
|
destroy_path: 'bar',
|
|
|
|
location: 'foo',
|
|
|
|
id: '123',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'gitlab-org/omnibus-gitlab/bar',
|
|
|
|
tags_path: 'foo',
|
|
|
|
destroy_path: 'bar',
|
|
|
|
location: 'foo',
|
|
|
|
id: '973',
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
2017-03-31 11:08:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
if image.destroy
|
2017-09-20 18:03:53 +00:00
|
|
|
respond_to do |format|
|
|
|
|
# TODO: @Kamil, I don't think this is used ever. Should we keep it or remove it?
|
|
|
|
format.html do
|
|
|
|
redirect_to project_container_registry_index_path(@project),
|
|
|
|
status: 302,
|
|
|
|
notice: 'Image repository has been removed successfully!'
|
|
|
|
end
|
|
|
|
|
|
|
|
format.json { head :no_content }
|
|
|
|
end
|
2017-03-31 11:08:09 +00:00
|
|
|
else
|
2017-09-20 18:03:53 +00:00
|
|
|
respond_to do |format|
|
|
|
|
# TODO: @Kamil, I don't think this is used ever. Should we keep it or remove it?
|
|
|
|
format.html do
|
|
|
|
redirect_to project_container_registry_index_path(@project),
|
|
|
|
status: 302,
|
|
|
|
alert: 'Failed to remove image repository!'
|
|
|
|
end
|
|
|
|
|
|
|
|
format.json { head :no_content }
|
|
|
|
end
|
2017-03-31 11:08:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-31 11:56:07 +00:00
|
|
|
private
|
2017-03-31 11:08:09 +00:00
|
|
|
|
|
|
|
def image
|
2017-04-05 12:18:42 +00:00
|
|
|
@image ||= project.container_repositories.find(params[:id])
|
2017-03-31 11:08:09 +00:00
|
|
|
end
|
2017-04-03 10:49:54 +00: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 13:53:51 +00:00
|
|
|
break if path.has_repository?
|
2017-04-03 10:49:54 +00:00
|
|
|
|
|
|
|
ContainerRepository.build_from_path(path).tap do |repository|
|
2017-04-05 12:44:35 +00:00
|
|
|
repository.save! if repository.has_tags?
|
2017-04-03 10:49:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-03-31 11:08:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|