Add option to sync single execution environment

This commit is contained in:
Sebastian Serth
2021-12-09 16:44:05 +01:00
parent 8faa35e629
commit 8535cd9a9c
6 changed files with 33 additions and 4 deletions

View File

@ -4,7 +4,7 @@ class ExecutionEnvironmentsController < ApplicationController
include CommonBehavior include CommonBehavior
before_action :set_docker_images, only: %i[create edit new update] before_action :set_docker_images, only: %i[create edit new update]
before_action :set_execution_environment, only: MEMBER_ACTIONS + %i[execute_command shell statistics] before_action :set_execution_environment, only: MEMBER_ACTIONS + %i[execute_command shell statistics sync_to_runner_management]
before_action :set_testing_framework_adapters, only: %i[create edit new update] before_action :set_testing_framework_adapters, only: %i[create edit new update]
def authorize! def authorize!
@ -166,6 +166,20 @@ class ExecutionEnvironmentsController < ApplicationController
update_and_respond(object: @execution_environment, params: execution_environment_params) update_and_respond(object: @execution_environment, params: execution_environment_params)
end end
def sync_to_runner_management
return unless Runner.management_active?
begin
Runner.strategy_class.sync_environment(@execution_environment)
rescue Runner::Error => e
Rails.logger.debug { "Runner error while synchronizing execution environment with id #{@execution_environment.id}: #{e.message}" }
Sentry.capture_exception(e)
redirect_to @execution_environment, alert: t('execution_environments.index.synchronize.failure', error: e.message)
else
redirect_to @execution_environment, notice: t('execution_environments.index.synchronize.success')
end
end
def sync_all_to_runner_management def sync_all_to_runner_management
authorize ExecutionEnvironment authorize ExecutionEnvironment

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class ExecutionEnvironmentPolicy < AdminOnlyPolicy class ExecutionEnvironmentPolicy < AdminOnlyPolicy
%i[execute_command? shell? statistics? show?].each do |action| %i[execute_command? shell? statistics? show? sync_to_runner_management?].each do |action|
define_method(action) { admin? || author? } define_method(action) { admin? || author? }
end end

View File

@ -1,6 +1,12 @@
h1 h1.d-inline-block = @execution_environment
= @execution_environment .btn-group.float-right
= render('shared/edit_button', object: @execution_environment) = render('shared/edit_button', object: @execution_environment)
button.btn.btn-secondary.float-right.dropdown-toggle data-toggle='dropdown' type='button'
ul.dropdown-menu.dropdown-menu-right role='menu'
li = link_to(t('execution_environments.index.synchronize.button'), sync_to_runner_management_execution_environment_path(@execution_environment), method: :post, class: 'dropdown-item text-dark') if policy(@execution_environment).sync_to_runner_management?
li = link_to(t('execution_environments.index.shell'), shell_execution_environment_path(@execution_environment), class: 'dropdown-item text-dark') if policy(@execution_environment).shell?
li = link_to(t('shared.statistics'), statistics_execution_environment_path(@execution_environment), 'data-turbolinks' => "false", class: 'dropdown-item text-dark') if policy(@execution_environment).statistics?
li = link_to(t('shared.destroy'), @execution_environment, data: {confirm: t('shared.confirm_destroy')}, method: :delete, class: 'dropdown-item text-dark') if policy(@execution_environment).destroy?
= row(label: 'execution_environment.name', value: @execution_environment.name) = row(label: 'execution_environment.name', value: @execution_environment.name)
= row(label: 'execution_environment.user', value: link_to_if(policy(@execution_environment.author).show?, @execution_environment.author, @execution_environment.author)) = row(label: 'execution_environment.user', value: link_to_if(policy(@execution_environment.author).show?, @execution_environment.author, @execution_environment.author))

View File

@ -303,6 +303,10 @@ de:
not_synced_to_runner_management: Die Ausführungsumgebung wurde erstellt, aber aufgrund eines Fehlers nicht zum Runnermanagement synchronisiert. not_synced_to_runner_management: Die Ausführungsumgebung wurde erstellt, aber aufgrund eines Fehlers nicht zum Runnermanagement synchronisiert.
index: index:
shell: Shell shell: Shell
synchronize:
button: Synchronisieren
success: Die Ausführungsumgebung wurde erfolgreich synchronisiert.
failure: "Beim Synchronisieren der Ausführungsumgebung ist folgender Fehler aufgetreten: %{error}"
synchronize_all: synchronize_all:
button: Alle synchronisieren button: Alle synchronisieren
success: Alle Ausführungsumgebungen wurden erfolgreich synchronisiert. success: Alle Ausführungsumgebungen wurden erfolgreich synchronisiert.

View File

@ -303,6 +303,10 @@ en:
not_synced_to_runner_management: The execution environment was created but not synced to the runner management due to an error. not_synced_to_runner_management: The execution environment was created but not synced to the runner management due to an error.
index: index:
shell: Shell shell: Shell
synchronize:
button: Synchronize
success: The execution environemnt was synchronized successfully.
failure: "The execution environment could not be synchronised due to the following error: %{error}"
synchronize_all: synchronize_all:
button: Synchronize all button: Synchronize all
success: All execution environemnts were synchronized successfully. success: All execution environemnts were synchronized successfully.

View File

@ -66,6 +66,7 @@ Rails.application.routes.draw do
get :shell get :shell
post 'shell', as: :execute_command, action: :execute_command post 'shell', as: :execute_command, action: :execute_command
get :statistics get :statistics
post :sync_to_runner_management
end end
post :sync_all_to_runner_management, on: :collection post :sync_all_to_runner_management, on: :collection