diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-04-09 16:58:54 +0300 |
---|---|---|
committer | Valery Sizov <vsv2711@gmail.com> | 2015-04-21 19:28:17 +0300 |
commit | 26ea08c2b05b2050f16224f6dd729b195c9e5d5e (patch) | |
tree | df49d480ba543b00f789ba35620c074882db86e7 | |
parent | b3e2939aa2904c92aba0399d511cb05228bfc9be (diff) | |
download | gitlab-ci-26ea08c2b05b2050f16224f6dd729b195c9e5d5e.tar.gz |
Improved runner page for project
* ability to add runner to several projects
* render runner status (online, offline, disabled)
* two column style of page: specific and shared runners
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r-- | app/assets/stylesheets/generic/common.scss | 27 | ||||
-rw-r--r-- | app/assets/stylesheets/sections/runners.scss | 22 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 1 | ||||
-rw-r--r-- | app/controllers/runner_projects_controller.rb | 32 | ||||
-rw-r--r-- | app/controllers/runners_controller.rb | 6 | ||||
-rw-r--r-- | app/helpers/runners_helper.rb | 24 | ||||
-rw-r--r-- | app/models/user.rb | 9 | ||||
-rw-r--r-- | app/views/layouts/project.html.haml | 3 | ||||
-rw-r--r-- | app/views/runners/_runner.html.haml | 66 | ||||
-rw-r--r-- | app/views/runners/_shared_runners.html.haml | 23 | ||||
-rw-r--r-- | app/views/runners/_specific_runners.html.haml | 29 | ||||
-rw-r--r-- | app/views/runners/index.html.haml | 49 | ||||
-rw-r--r-- | config/routes.rb | 2 |
13 files changed, 219 insertions, 74 deletions
diff --git a/app/assets/stylesheets/generic/common.scss b/app/assets/stylesheets/generic/common.scss index 1b6a90f..721d931 100644 --- a/app/assets/stylesheets/generic/common.scss +++ b/app/assets/stylesheets/generic/common.scss @@ -74,3 +74,30 @@ line-height: 1.6; } } + +/** light list with border-bottom between li **/ +ul.bordered-list { + margin: 5px 0px; + padding: 0px; + li { + padding: 5px 0; + border-bottom: 1px solid #EEE; + overflow: hidden; + display: block; + margin: 0px; + &:last-child { border:none } + &.active { + background: #f9f9f9; + a { font-weight: bold; } + } + } + + &.top-list { + li:first-child { + padding-top: 0; + h4, h5 { + margin-top: 0; + } + } + } +} diff --git a/app/assets/stylesheets/sections/runners.scss b/app/assets/stylesheets/sections/runners.scss index ae098fe..a9111a7 100644 --- a/app/assets/stylesheets/sections/runners.scss +++ b/app/assets/stylesheets/sections/runners.scss @@ -10,3 +10,25 @@ background: #3498db; } } + +.runner-status-online { + color: green; +} + +.runner-status-offline { + color: gray; +} + +.runner-status-paused { + color: red; +} + +.runner { + .btn { + padding: 1px 6px; + } + + h4 { + font-weight: normal; + } +} diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 2fbf3f6..4171983 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -63,7 +63,6 @@ class ProjectsController < ApplicationController def update if project.update_attributes(project_params) - EventService.new.change_project_settings(current_user, project) redirect_to project, notice: 'Project was successfully updated.' diff --git a/app/controllers/runner_projects_controller.rb b/app/controllers/runner_projects_controller.rb new file mode 100644 index 0000000..b27f888 --- /dev/null +++ b/app/controllers/runner_projects_controller.rb @@ -0,0 +1,32 @@ +class RunnerProjectsController < ApplicationController + before_filter :authenticate_user! + before_filter :project + before_filter :authorize_manage_project! + + layout 'project' + + def create + @runner = Runner.find(params[:runner_project][:runner_id]) + + return head(403) unless current_user.authorized_runners.include?(@runner) + + if @runner.assign_to(project, current_user) + redirect_to project_runners_path(project) + else + redirect_to project_runners_path(project), alert: 'Failed adding runner to project' + end + end + + def destroy + runner_project = project.runner_projects.find(params[:id]) + runner_project.destroy + + redirect_to project_runners_path(project) + end + + private + + def project + @project ||= Project.find(params[:project_id]) + end +end diff --git a/app/controllers/runners_controller.rb b/app/controllers/runners_controller.rb index 02465d6..76bdae1 100644 --- a/app/controllers/runners_controller.rb +++ b/app/controllers/runners_controller.rb @@ -8,7 +8,11 @@ class RunnersController < ApplicationController layout 'project' def index - @runners = @project.runners.order('id DESC').page(params[:page]).per(20) + @runners = @project.runners.order('id DESC') + @specific_runners = current_user.authorized_runners. + where.not(id: @runners).order('id DESC').page(params[:page]).per(20) + @shared_runners = Runner.shared.active + @shared_runners_count = @shared_runners.count(:all) end def edit diff --git a/app/helpers/runners_helper.rb b/app/helpers/runners_helper.rb new file mode 100644 index 0000000..487fba0 --- /dev/null +++ b/app/helpers/runners_helper.rb @@ -0,0 +1,24 @@ +module RunnersHelper + def runner_status_icon(runner) + unless runner.contacted_at + return content_tag :i, nil, + class: "icon-warning-sign", + title: "New runner. Has no connect yet" + end + + status = + if runner.active? + if runner.contacted_at > 1.hour.ago + :online + else + :offline + end + else + :paused + end + + content_tag :i, nil, + class: "icon-circle runner-status-#{status}", + title: "Runner is #{status}, last contact was #{time_ago_in_words(runner.contacted_at)} ago" + end +end diff --git a/app/models/user.rb b/app/models/user.rb index 129ddc1..3f2e046 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -65,6 +65,15 @@ class User end end + def authorized_runners + Runner.specific.joins(:runner_projects). + where(runner_projects: { project_id: authorized_projects } ) + end + + def authorized_projects + @authorized_projects ||= Project.where(gitlab_id: gitlab_projects.map(&:id)) + end + private def project_info(project_gitlab_id) diff --git a/app/views/layouts/project.html.haml b/app/views/layouts/project.html.haml index 495dc6c..231bded 100644 --- a/app/views/layouts/project.html.haml +++ b/app/views/layouts/project.html.haml @@ -24,5 +24,4 @@ .col-md-10 = yield - else - .col-md-12 - = yield + = yield diff --git a/app/views/runners/_runner.html.haml b/app/views/runners/_runner.html.haml index 1c75058..5262953 100644 --- a/app/views/runners/_runner.html.haml +++ b/app/views/runners/_runner.html.haml @@ -1,37 +1,33 @@ -%tr{id: dom_id(runner)} - %td - %strong ##{runner.id} - %td - - if runner.active? - %span.label.label-success active - - else - %span.label.label-danger paused - - %td - = runner.short_sha - %td - .runner-description - = runner.description - %td - - if build = runner.builds.last - = link_to "##{build.id}", [build.project, build] - %td - - runner.tag_list.each do |tag| - %span.label.label-primary - = tag - %td - - if runner.contacted_at - #{time_ago_in_words(runner.contacted_at)} ago - - else - Never - %td +%li.runner{id: dom_id(runner)} + %h4 + = runner_status_icon(runner) + %span.monospace + = runner.short_sha .pull-right - = link_to 'Edit', edit_project_runner_path(@project, runner), class: 'btn btn-small' - - - if runner.active? - = link_to 'Pause', [:pause, @project, runner], data: { confirm: "Are you sure?" }, method: :get, class: 'btn btn-danger btn-small' - - else - = link_to 'Resume', [:resume, @project, runner], method: :get, class: 'btn btn-success btn-small' - - if runner.only_for?(@project) - = link_to 'Remove', [@project, runner], data: { confirm: "Are you sure?" }, method: :delete, class: 'btn btn-danger btn-small' + - if @runners.include?(runner) + = link_to 'Edit', edit_project_runner_path(@project, runner), class: 'btn btn-small' + - if runner.active? + = link_to 'Pause', [:pause, @project, runner], data: { confirm: "Are you sure?" }, method: :get, class: 'btn btn-danger btn-small' + - else + = link_to 'Resume', [:resume, @project, runner], method: :get, class: 'btn btn-success btn-small' + - if runner.only_for?(@project) + = link_to 'Remove', [@project, runner], data: { confirm: "Are you sure?" }, method: :delete, class: 'btn btn-danger btn-small' + - else + - runner_project = @project.runner_projects.find_by(runner_id: runner) + = link_to 'Disable for this project', [@project, runner_project], data: { confirm: "Are you sure?" }, method: :delete, class: 'btn btn-danger btn-small' + - elsif runner.specific? + = form_for [@project, @project.runner_projects.new] do |f| + = f.hidden_field :runner_id, value: runner.id + = f.submit 'Enable for this project', class: 'btn btn-small' + .pull-right + %small.light + \##{runner.id} + - if runner.description.present? + %p.runner-description + = runner.description + - if runner.tag_list.present? + %p + - runner.tag_list.each do |tag| + %span.label.label-primary + = tag diff --git a/app/views/runners/_shared_runners.html.haml b/app/views/runners/_shared_runners.html.haml new file mode 100644 index 0000000..45d967f --- /dev/null +++ b/app/views/runners/_shared_runners.html.haml @@ -0,0 +1,23 @@ +%h3 Shared runners + +.bs-callout.bs-callout-warning + Put text about secutiry impact of using shared runner + %hr + - if @project.shared_runners_enabled + = link_to '#', class: 'btn btn-warning' do + Disable shared runners + - else + = link_to '#', class: 'btn btn-warning' do + Enable shared runners + for this project + +- if @shared_runners_count.zero? + This application has no shared runners yet. + Please use specific runners or ask administrator to create one +- else + %h4 Available shared runners - #{@shared_runners_count} + %ul.bordered-list + = render @shared_runners.first(10) + - if @shared_runners_count > 10 + .light + and #{@shared_runners_count - 10} more... diff --git a/app/views/runners/_specific_runners.html.haml b/app/views/runners/_specific_runners.html.haml new file mode 100644 index 0000000..055071c --- /dev/null +++ b/app/views/runners/_specific_runners.html.haml @@ -0,0 +1,29 @@ +%h3 Specific runners + +.bs-callout.help-callout + %h4 How to setup a new project specific runner + + %ol + %li + Install GitLab Runner software. + Checkout the #{link_to 'GitLab Runner section', 'https://about.gitlab.com/gitlab-ci/#gitlab-runner', target: '_blank'} to install it + %li + Specify following URL during runner setup: + %code #{root_url(only_path: false)} + %li + Use the following registration token during setup: + %code #{@project.token} + %li + Start runner! + + +- if @runners.any? + %h4 Runners activated for this project + %ul.bordered-list + = render @runners + +- if @specific_runners.any? + %h4 Available specific runners + %ul.bordered-list + = render @specific_runners + = paginate @specific_runners diff --git a/app/views/runners/index.html.haml b/app/views/runners/index.html.haml index 6df2e8d..529fb9c 100644 --- a/app/views/runners/index.html.haml +++ b/app/views/runners/index.html.haml @@ -1,26 +1,11 @@ -%p.slead - A 'runner' is a process which runs a build. - You can setup as many runners as you need. - %br - Runners can be placed on separate users, servers, and even on your local machine. +.light + %p + A 'runner' is a process which runs a build. + You can setup as many runners as you need. + %br + Runners can be placed on separate users, servers, and even on your local machine. -.bs-callout.help-callout - %h4 How to setup a new project specific runner - - %ol - %li - Install GitLab Runner software. - Checkout the #{link_to 'GitLab Runner section', 'https://about.gitlab.com/gitlab-ci/#gitlab-runner', target: '_blank'} to install it - %li - Specify following URL during runner setup: - %code #{root_url(only_path: false)} - %li - Use the following registration token during setup: - %code #{@project.token} - %li - Start runner! - - %h4 Each runner can be in one of the following states: + %p Each runner can be in one of the following states: %div %ul %li @@ -30,17 +15,11 @@ %span.label.label-danger paused \- runner is paused and will not receive any new build -%table.table - %thead - %tr - %th ID - %th Type - %th Runner token - %th Description - %th Last build - %th Tags - %th Last contact - %th +%hr - = render @runners -= paginate @runners +%p.lead To start serving your builds you can either add specific runners to your project or use shared runners +.row + .col-sm-6 + = render 'specific_runners' + .col-sm-6 + = render 'shared_runners' diff --git a/config/routes.rb b/config/routes.rb index a176114..95e9d14 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -58,6 +58,8 @@ Rails.application.routes.draw do end end + resources :runner_projects, only: [:create, :destroy] + resources :jobs, only: [:index] do collection do get :deploy_jobs |