Commit b7f37fd6 authored by Kerri Miller's avatar Kerri Miller

Merge branch 'jivanvl-runner-guided-install-backend' into 'master'

Add runner setup methods

See merge request gitlab-org/gitlab!42878
parents 3ddb797c 5fb63a55
# frozen_string_literal: true # frozen_string_literal: true
class Admin::RunnersController < Admin::ApplicationController class Admin::RunnersController < Admin::ApplicationController
before_action :runner, except: [:index, :tag_list] include RunnerSetupScripts
before_action :runner, except: [:index, :tag_list, :runner_setup_scripts]
def index def index
finder = Ci::RunnersFinder.new(current_user: current_user, params: params) finder = Ci::RunnersFinder.new(current_user: current_user, params: params)
...@@ -53,6 +55,10 @@ class Admin::RunnersController < Admin::ApplicationController ...@@ -53,6 +55,10 @@ class Admin::RunnersController < Admin::ApplicationController
render json: ActsAsTaggableOn::TagSerializer.new.represent(tags) render json: ActsAsTaggableOn::TagSerializer.new.represent(tags)
end end
def runner_setup_scripts
private_runner_setup_scripts
end
private private
def runner def runner
......
# frozen_string_literal: true
module RunnerSetupScripts
extend ActiveSupport::Concern
private
def private_runner_setup_scripts(**kwargs)
instructions = Gitlab::Ci::RunnerInstructions.new(current_user: current_user, os: script_params[:os], arch: script_params[:arch], **kwargs)
output = {
install: instructions.install_script,
register: instructions.register_command
}
if instructions.errors.any?
render json: { errors: instructions.errors }, status: :bad_request
else
render json: output
end
end
def script_params
params.permit(:os, :arch)
end
end
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
module Groups module Groups
module Settings module Settings
class CiCdController < Groups::ApplicationController class CiCdController < Groups::ApplicationController
include RunnerSetupScripts
skip_cross_project_access_check :show skip_cross_project_access_check :show
before_action :authorize_admin_group! before_action :authorize_admin_group!
before_action :authorize_update_max_artifacts_size!, only: [:update] before_action :authorize_update_max_artifacts_size!, only: [:update]
...@@ -49,6 +51,10 @@ module Groups ...@@ -49,6 +51,10 @@ module Groups
redirect_to group_settings_ci_cd_path redirect_to group_settings_ci_cd_path
end end
def runner_setup_scripts
private_runner_setup_scripts(group: group)
end
private private
def define_variables def define_variables
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
module Projects module Projects
module Settings module Settings
class CiCdController < Projects::ApplicationController class CiCdController < Projects::ApplicationController
include RunnerSetupScripts
before_action :authorize_admin_pipeline! before_action :authorize_admin_pipeline!
before_action :define_variables before_action :define_variables
before_action do before_action do
...@@ -52,6 +54,10 @@ module Projects ...@@ -52,6 +54,10 @@ module Projects
redirect_to namespace_project_settings_ci_cd_path redirect_to namespace_project_settings_ci_cd_path
end end
def runner_setup_scripts
private_runner_setup_scripts(project: @project)
end
private private
def update_params def update_params
......
# frozen_string_literal: true
class RunnerSetupController < ApplicationController
def platforms
render json: Gitlab::Ci::RunnerInstructions::OS.merge(Gitlab::Ci::RunnerInstructions::OTHER_ENVIRONMENTS)
end
end
---
title: Add runner setup methods
merge_request: 42878
author:
type: added
...@@ -89,6 +89,8 @@ Rails.application.routes.draw do ...@@ -89,6 +89,8 @@ Rails.application.routes.draw do
resources :metrics, only: [:index] resources :metrics, only: [:index]
mount Peek::Railtie => '/peek', as: 'peek_routes' mount Peek::Railtie => '/peek', as: 'peek_routes'
get 'runner_setup/platforms' => 'runner_setup#platforms'
# Boards resources shared between group and projects # Boards resources shared between group and projects
resources :boards, only: [] do resources :boards, only: [] do
resources :lists, module: :boards, only: [:index, :create, :update, :destroy] do resources :lists, module: :boards, only: [:index, :create, :update, :destroy] do
......
...@@ -151,6 +151,7 @@ namespace :admin do ...@@ -151,6 +151,7 @@ namespace :admin do
collection do collection do
get :tag_list, format: :json get :tag_list, format: :json
get :runner_setup_scripts, format: :json
end end
end end
......
...@@ -35,6 +35,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do ...@@ -35,6 +35,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
put :reset_registration_token put :reset_registration_token
patch :update_auto_devops patch :update_auto_devops
post :create_deploy_token, path: 'deploy_token/create', to: 'repository#create_deploy_token' post :create_deploy_token, path: 'deploy_token/create', to: 'repository#create_deploy_token'
get :runner_setup_scripts, format: :json
end end
resource :repository, only: [:show], controller: 'repository' do resource :repository, only: [:show], controller: 'repository' do
......
...@@ -93,6 +93,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -93,6 +93,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
post :reset_cache post :reset_cache
put :reset_registration_token put :reset_registration_token
post :create_deploy_token, path: 'deploy_token/create', to: 'repository#create_deploy_token' post :create_deploy_token, path: 'deploy_token/create', to: 'repository#create_deploy_token'
get :runner_setup_scripts, format: :json
end end
resource :operations, only: [:show, :update] do resource :operations, only: [:show, :update] do
......
...@@ -151,4 +151,21 @@ RSpec.describe Admin::RunnersController do ...@@ -151,4 +151,21 @@ RSpec.describe Admin::RunnersController do
expect(runner.active).to eq(false) expect(runner.active).to eq(false)
end end
end end
describe 'GET #runner_setup_scripts' do
it 'renders the setup scripts' do
get :runner_setup_scripts, params: { os: 'linux', arch: 'amd64' }
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to have_key("install")
expect(json_response).to have_key("register")
end
it 'renders errors if they occur' do
get :runner_setup_scripts, params: { os: 'foo', arch: 'bar' }
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response).to have_key("errors")
end
end
end end
...@@ -225,4 +225,25 @@ RSpec.describe Groups::Settings::CiCdController do ...@@ -225,4 +225,25 @@ RSpec.describe Groups::Settings::CiCdController do
end end
end end
end end
describe 'GET #runner_setup_scripts' do
before do
group.add_owner(user)
end
it 'renders the setup scripts' do
get :runner_setup_scripts, params: { os: 'linux', arch: 'amd64', group_id: group }
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to have_key("install")
expect(json_response).to have_key("register")
end
it 'renders errors if they occur' do
get :runner_setup_scripts, params: { os: 'foo', arch: 'bar', group_id: group }
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response).to have_key("errors")
end
end
end end
...@@ -266,4 +266,21 @@ RSpec.describe Projects::Settings::CiCdController do ...@@ -266,4 +266,21 @@ RSpec.describe Projects::Settings::CiCdController do
end end
end end
end end
describe 'GET #runner_setup_scripts' do
it 'renders the setup scripts' do
get :runner_setup_scripts, params: { os: 'linux', arch: 'amd64', namespace_id: project.namespace, project_id: project }
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to have_key("install")
expect(json_response).to have_key("register")
end
it 'renders errors if they occur' do
get :runner_setup_scripts, params: { os: 'foo', arch: 'bar', namespace_id: project.namespace, project_id: project }
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response).to have_key("errors")
end
end
end end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe RunnerSetupController do
let(:user) { create(:user) }
before do
sign_in(user)
end
describe 'GET #platforms' do
it 'renders the platforms' do
get :platforms
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to have_key("windows")
expect(json_response).to have_key("kubernetes")
end
end
end
...@@ -184,3 +184,9 @@ RSpec.describe Admin::PlanLimitsController, "routing" do ...@@ -184,3 +184,9 @@ RSpec.describe Admin::PlanLimitsController, "routing" do
expect(post("/admin/plan_limits")).to route_to('admin/plan_limits#create') expect(post("/admin/plan_limits")).to route_to('admin/plan_limits#create')
end end
end end
RSpec.describe Admin::RunnersController, "routing" do
it "to #runner_setup_scripts" do
expect(get("/admin/runners/runner_setup_scripts")).to route_to('admin/runners#runner_setup_scripts')
end
end
...@@ -43,6 +43,10 @@ RSpec.shared_examples 'groups routing' do ...@@ -43,6 +43,10 @@ RSpec.shared_examples 'groups routing' do
expect(get("/groups/#{group_path}/-/milestones")).to route_to('groups/milestones#index', group_id: group_path) expect(get("/groups/#{group_path}/-/milestones")).to route_to('groups/milestones#index', group_id: group_path)
end end
it "to #runner_setup_scripts" do
expect(get("/groups/#{group_path}/-/settings/ci_cd/runner_setup_scripts")).to route_to('groups/settings/ci_cd#runner_setup_scripts', group_id: group_path)
end
it 'routes to the avatars controller' do it 'routes to the avatars controller' do
expect(delete("/groups/#{group_path}/-/avatar")) expect(delete("/groups/#{group_path}/-/avatar"))
.to route_to(group_id: group_path, .to route_to(group_id: group_path,
......
...@@ -731,6 +731,12 @@ RSpec.describe 'project routing' do ...@@ -731,6 +731,12 @@ RSpec.describe 'project routing' do
end end
end end
describe Projects::Settings::CiCdController, 'routing' do
it "to #runner_setup_scripts" do
expect(get("/gitlab/gitlabhq/-/settings/ci_cd/runner_setup_scripts")).to route_to('projects/settings/ci_cd#runner_setup_scripts', namespace_id: 'gitlab', project_id: 'gitlabhq')
end
end
describe Projects::TemplatesController, 'routing' do describe Projects::TemplatesController, 'routing' do
describe '#show' do describe '#show' do
def show_with_template_type(template_type) def show_with_template_type(template_type)
......
...@@ -374,3 +374,9 @@ RSpec.describe Snippets::BlobsController, "routing" do ...@@ -374,3 +374,9 @@ RSpec.describe Snippets::BlobsController, "routing" do
.to route_to('snippets/blobs#raw', snippet_id: '1', ref: 'master', path: 'lib/version.rb') .to route_to('snippets/blobs#raw', snippet_id: '1', ref: 'master', path: 'lib/version.rb')
end end
end end
RSpec.describe RunnerSetupController, 'routing' do
it 'to #platforms' do
expect(get("/-/runner_setup/platforms")).to route_to('runner_setup#platforms')
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment