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-21 10:21:50 +00:00
|
|
|
render json: ContainerRepositoriesSerializer
|
|
|
|
.new(project: project, current_user: current_user)
|
|
|
|
.represent(@images)
|
2017-09-19 15:38:55 +00:00
|
|
|
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|
|
|
|
|
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|
|
2017-09-21 10:21:50 +00:00
|
|
|
format.json { head :bad_request }
|
2017-09-20 18:03:53 +00:00
|
|
|
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
|