2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
2017-09-19 11:38:55 -04:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
2017-09-21 06:21:50 -04:00
|
|
|
render json: ContainerRepositoriesSerializer
|
|
|
|
.new(project: project, current_user: current_user)
|
|
|
|
.represent(@images)
|
2017-09-19 11:38:55 -04:00
|
|
|
end
|
|
|
|
end
|
2017-03-31 07:08:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2018-09-06 02:33:30 -04:00
|
|
|
DeleteContainerRepositoryWorker.perform_async(current_user.id, image.id)
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.json { head :no_content }
|
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!
|
2018-09-06 02:33:30 -04:00
|
|
|
::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
|
|
|
|
2018-09-06 02:33:30 -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
|