2018-09-26 03:45:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
2018-09-06 06:33:30 +00:00
|
|
|
DeleteContainerRepositoryWorker.perform_async(current_user.id, image.id)
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.json { head :no_content }
|
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!
|
2018-09-06 06:33:30 +00:00
|
|
|
::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
|
|
|
|
2018-09-06 06:33:30 +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
|