From 5196f8e993491e8e9dea6e36a7c5c3b8d95a5491 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Sun, 8 May 2016 22:50:30 +0200 Subject: [PATCH] WIP --- .../projects/container_registry_controller.rb | 31 +++++++++++++++++++ app/controllers/projects/images_controller.rb | 28 ----------------- app/helpers/gitlab_routing_helper.rb | 4 +-- app/models/project.rb | 4 +-- app/views/layouts/nav/_project.html.haml | 6 ++-- .../_header_title.html.haml | 1 + .../index.html.haml | 4 +-- .../projects/images/_header_title.html.haml | 1 - config/routes.rb | 2 +- lib/gitlab/regex.rb | 2 +- 10 files changed, 43 insertions(+), 40 deletions(-) create mode 100644 app/controllers/projects/container_registry_controller.rb delete mode 100644 app/controllers/projects/images_controller.rb create mode 100644 app/views/projects/container_registry/_header_title.html.haml rename app/views/projects/{images => container_registry}/index.html.haml (86%) delete mode 100644 app/views/projects/images/_header_title.html.haml diff --git a/app/controllers/projects/container_registry_controller.rb b/app/controllers/projects/container_registry_controller.rb new file mode 100644 index 00000000000..ffd455e6476 --- /dev/null +++ b/app/controllers/projects/container_registry_controller.rb @@ -0,0 +1,31 @@ +class Projects::ContainerRegistryController < Projects::ApplicationController + before_action :authorize_read_image! + before_action :authorize_update_image!, only: [:destroy] + before_action :tag, except: [:index] + layout 'project' + + def index + @tags = container_registry.tags + + other_repository = container_registry.registry["gitlab/gitlab-test3"] + container_registry.copy_to(other_repository) + end + + def destroy + if tag.delete + redirect_to namespace_project_container_registry_index_path(project.namespace, project) + else + redirect_to namespace_project_container_registry_index_path(project.namespace, project), alert: 'Failed to remove tag' + end + end + + private + + def container_registry + @container_registry ||= project.container_registry + end + + def tag + @tag ||= container_registry[params[:id]] + end +end diff --git a/app/controllers/projects/images_controller.rb b/app/controllers/projects/images_controller.rb deleted file mode 100644 index cf3bdd42cf4..00000000000 --- a/app/controllers/projects/images_controller.rb +++ /dev/null @@ -1,28 +0,0 @@ -class Projects::ImagesController < Projects::ApplicationController - before_action :authorize_read_image! - before_action :authorize_update_image!, only: [:destroy] - before_action :tag, except: [:index] - layout 'project' - - def index - @tags = image_repository.tags - end - - def destroy - if tag.delete - redirect_to namespace_project_images_path(project.namespace, project) - else - redirect_to namespace_project_images_path(project.namespace, project), alert: 'Failed to remove tag' - end - end - - private - - def image_repository - @image_repository ||= project.image_repository - end - - def tag - @tag ||= image_repository[params[:id]] - end -end diff --git a/app/helpers/gitlab_routing_helper.rb b/app/helpers/gitlab_routing_helper.rb index 66cb41cc496..dd9536b1460 100644 --- a/app/helpers/gitlab_routing_helper.rb +++ b/app/helpers/gitlab_routing_helper.rb @@ -33,8 +33,8 @@ module GitlabRoutingHelper namespace_project_builds_path(project.namespace, project, *args) end - def project_images_path(project, *args) - namespace_project_images_path(project.namespace, project, *args) + def project_container_registry_path(project, *args) + namespace_project_container_registry_index_url(project.namespace, project, *args) end def activity_project_path(project, *args) diff --git a/app/models/project.rb b/app/models/project.rb index c50ea45d3eb..0e32be5a536 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -370,10 +370,10 @@ class Project < ActiveRecord::Base @repository ||= Repository.new(path_with_namespace, self) end - def image_repository + def container_registry @registry_token ||= Jwt::DockerAuthenticationService.full_access_token(path_with_namespace) @registry ||= ImageRegistry::Registry.new(Gitlab.config.registry.api_url, token: @registry_token) - @image_repository ||= ImageRegistry::Repository.new(@registry, path_with_namespace) + @container_registry ||= ImageRegistry::Repository.new(@registry, path_with_namespace) end def registry_repository_url diff --git a/app/views/layouts/nav/_project.html.haml b/app/views/layouts/nav/_project.html.haml index bef350adf34..8448599c1cc 100644 --- a/app/views/layouts/nav/_project.html.haml +++ b/app/views/layouts/nav/_project.html.haml @@ -47,11 +47,11 @@ %span.count.builds_counter= number_with_delimiter(@project.builds.running_or_pending.count(:all)) - if project_nav_tab? :images - = nav_link(controller: %w(images)) do - = link_to project_images_path(@project), title: 'Images', class: 'shortcuts-images' do + = nav_link(controller: %w(container_registry)) do + = link_to project_container_registry_path(@project), title: 'Container Registry', class: 'shortcuts-images' do = icon('hdd-o fw') %span - Container Images + Container Registry - if project_nav_tab? :graphs = nav_link(controller: %w(graphs)) do diff --git a/app/views/projects/container_registry/_header_title.html.haml b/app/views/projects/container_registry/_header_title.html.haml new file mode 100644 index 00000000000..f1863c52a3e --- /dev/null +++ b/app/views/projects/container_registry/_header_title.html.haml @@ -0,0 +1 @@ +- header_title project_title(@project, "Container Registry", project_container_registry_path(@project)) diff --git a/app/views/projects/images/index.html.haml b/app/views/projects/container_registry/index.html.haml similarity index 86% rename from app/views/projects/images/index.html.haml rename to app/views/projects/container_registry/index.html.haml index 08f67345b4a..1ac3a62f54e 100644 --- a/app/views/projects/images/index.html.haml +++ b/app/views/projects/container_registry/index.html.haml @@ -1,4 +1,4 @@ -- page_title "Container Images" +- page_title "Container Registry" = render "header_title" .light.prepend-top-default @@ -53,5 +53,5 @@ = time_ago_in_words(tag.created_at) %td.content .controls.hidden-xs.pull-right - = link_to namespace_project_image_path(@project.namespace, @project, tag.name), class: 'btn btn-remove has-tooltip', title: "Remove", data: { confirm: "Are you sure?" }, method: :delete do + = link_to namespace_project_container_registry_path(@project.namespace, @project, tag.name), class: 'btn btn-remove has-tooltip', title: "Remove", data: { confirm: "Are you sure?" }, method: :delete do = icon("trash cred") diff --git a/app/views/projects/images/_header_title.html.haml b/app/views/projects/images/_header_title.html.haml deleted file mode 100644 index f583e7fcfef..00000000000 --- a/app/views/projects/images/_header_title.html.haml +++ /dev/null @@ -1 +0,0 @@ -- header_title project_title(@project, "Container Images", project_images_path(@project)) diff --git a/config/routes.rb b/config/routes.rb index 0280898accd..ce75329597b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -690,7 +690,7 @@ Rails.application.routes.draw do end end - resources :images, only: [:index, :destroy], constraints: { id: Gitlab::Regex.image_reference_regex } + resources :container_registry, only: [:index, :destroy], constraints: { id: Gitlab::Regex.container_registry_reference_regex } resources :milestones, constraints: { id: /\d+/ } do member do diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb index 9b8f416ddfa..1cbd6d945a0 100644 --- a/lib/gitlab/regex.rb +++ b/lib/gitlab/regex.rb @@ -97,7 +97,7 @@ module Gitlab }x.freeze end - def image_reference_regex + def container_registry_reference_regex git_reference_regex end end