Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-07-06 08:38:24 +0300
committerShinya Maeda <shinya@gitlab.com>2018-07-06 08:38:24 +0300
commit25bd5413200c9cd9368c753e2752f07735604547 (patch)
treec4cc75a53face6a6d0da8adca9a3994d3cc688b5 /app/models/ci
parentb025e89e08888f3b393108f984a25c209526491b (diff)
parent969b7c565c6fe5cdfc54830d1da35f254ddaf530 (diff)
Merge branch 'master' into build-chunks-on-object-storage
Diffstat (limited to 'app/models/ci')
-rw-r--r--app/models/ci/build.rb14
-rw-r--r--app/models/ci/build_runner_session.rb25
-rw-r--r--app/models/ci/runner.rb34
3 files changed, 51 insertions, 22 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 41446946a5e..bf93a2caf72 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -27,7 +27,13 @@ module Ci
has_one :job_artifacts_trace, -> { where(file_type: Ci::JobArtifact.file_types[:trace]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id
has_one :metadata, class_name: 'Ci::BuildMetadata'
+ has_one :runner_session, class_name: 'Ci::BuildRunnerSession', validate: true, inverse_of: :build
+
+ accepts_nested_attributes_for :runner_session
+
delegate :timeout, to: :metadata, prefix: true, allow_nil: true
+ delegate :url, to: :runner_session, prefix: true, allow_nil: true
+ delegate :terminal_specification, to: :runner_session, allow_nil: true
delegate :gitlab_deploy_token, to: :project
##
@@ -174,6 +180,10 @@ module Ci
after_transition pending: :running do |build|
build.ensure_metadata.update_timeout_state
end
+
+ after_transition running: any do |build|
+ Ci::BuildRunnerSession.where(build: build).delete_all
+ end
end
def ensure_metadata
@@ -584,6 +594,10 @@ module Ci
super(options).merge(when: read_attribute(:when))
end
+ def has_terminal?
+ running? && runner_session_url.present?
+ end
+
private
def update_artifacts_size
diff --git a/app/models/ci/build_runner_session.rb b/app/models/ci/build_runner_session.rb
new file mode 100644
index 00000000000..6f3be31d8e1
--- /dev/null
+++ b/app/models/ci/build_runner_session.rb
@@ -0,0 +1,25 @@
+module Ci
+ # The purpose of this class is to store Build related runner session.
+ # Data will be removed after transitioning from running to any state.
+ class BuildRunnerSession < ActiveRecord::Base
+ extend Gitlab::Ci::Model
+
+ self.table_name = 'ci_builds_runner_session'
+
+ belongs_to :build, class_name: 'Ci::Build', inverse_of: :runner_session
+
+ validates :build, presence: true
+ validates :url, url: { protocols: %w(https) }
+
+ def terminal_specification
+ return {} unless url.present?
+
+ {
+ subprotocols: ['terminal.gitlab.com'].freeze,
+ url: "#{url}/exec".sub("https://", "wss://"),
+ headers: { Authorization: authorization.presence }.compact,
+ ca_pem: certificate.presence
+ }
+ end
+ end
+end
diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb
index 8c9aacca8de..bcd0c206bca 100644
--- a/app/models/ci/runner.rb
+++ b/app/models/ci/runner.rb
@@ -2,6 +2,7 @@ module Ci
class Runner < ActiveRecord::Base
extend Gitlab::Ci::Model
include Gitlab::SQL::Pattern
+ include IgnorableColumn
include RedisCacheable
include ChronicDurationAttribute
@@ -11,6 +12,8 @@ module Ci
AVAILABLE_SCOPES = %w[specific shared active paused online].freeze
FORM_EDITABLE = %i[description tag_list active run_untagged locked access_level maximum_timeout_human_readable].freeze
+ ignore_column :is_shared
+
has_many :builds
has_many :runner_projects, inverse_of: :runner, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_many :projects, through: :runner_projects
@@ -21,13 +24,16 @@ module Ci
before_validation :set_default_values
- scope :specific, -> { where(is_shared: false) }
- scope :shared, -> { where(is_shared: true) }
scope :active, -> { where(active: true) }
scope :paused, -> { where(active: false) }
scope :online, -> { where('contacted_at > ?', contact_time_deadline) }
scope :ordered, -> { order(id: :desc) }
+ # BACKWARD COMPATIBILITY: There are needed to maintain compatibility with `AVAILABLE_SCOPES` used by `lib/api/runners.rb`
+ scope :deprecated_shared, -> { instance_type }
+ # this should get replaced with `project_type.or(group_type)` once using Rails5
+ scope :deprecated_specific, -> { where(runner_type: [runner_types[:project_type], runner_types[:group_type]]) }
+
scope :belonging_to_project, -> (project_id) {
joins(:runner_projects).where(ci_runner_projects: { project_id: project_id })
}
@@ -39,9 +45,9 @@ module Ci
joins(:groups).where(namespaces: { id: hierarchy_groups })
}
- scope :owned_or_shared, -> (project_id) do
+ scope :owned_or_instance_wide, -> (project_id) do
union = Gitlab::SQL::Union.new(
- [belonging_to_project(project_id), belonging_to_parent_group_of_project(project_id), shared],
+ [belonging_to_project(project_id), belonging_to_parent_group_of_project(project_id), instance_type],
remove_duplicates: false
)
from("(#{union.to_sql}) ci_runners")
@@ -63,7 +69,6 @@ module Ci
validate :no_groups, unless: :group_type?
validate :any_project, if: :project_type?
validate :exactly_one_group, if: :group_type?
- validate :validate_is_shared
acts_as_taggable
@@ -113,8 +118,7 @@ module Ci
end
def assign_to(project, current_user = nil)
- if shared?
- self.is_shared = false if shared?
+ if instance_type?
self.runner_type = :project_type
elsif group_type?
raise ArgumentError, 'Transitioning a group runner to a project runner is not supported'
@@ -137,10 +141,6 @@ module Ci
description
end
- def shared?
- is_shared
- end
-
def online?
contacted_at && contacted_at > self.class.contact_time_deadline
end
@@ -159,10 +159,6 @@ module Ci
runner_projects.count == 1
end
- def specific?
- !shared?
- end
-
def assigned_to_group?
runner_namespaces.any?
end
@@ -260,7 +256,7 @@ module Ci
end
def assignable_for?(project_id)
- self.class.owned_or_shared(project_id).where(id: self.id).any?
+ self.class.owned_or_instance_wide(project_id).where(id: self.id).any?
end
def no_projects
@@ -287,12 +283,6 @@ module Ci
end
end
- def validate_is_shared
- unless is_shared? == instance_type?
- errors.add(:is_shared, 'is not equal to instance_type?')
- end
- end
-
def accepting_tags?(build)
(run_untagged? || build.has_tags?) && (build.tag_list - tag_list).empty?
end