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:
Diffstat (limited to 'app/models/ci')
-rw-r--r--app/models/ci/artifact_blob.rb2
-rw-r--r--app/models/ci/bridge.rb31
-rw-r--r--app/models/ci/build.rb26
-rw-r--r--app/models/ci/build_metadata.rb2
-rw-r--r--app/models/ci/build_trace_chunk.rb2
-rw-r--r--app/models/ci/job_artifact.rb8
-rw-r--r--app/models/ci/pipeline.rb6
-rw-r--r--app/models/ci/runner.rb23
-rw-r--r--app/models/ci/runner_machine.rb33
9 files changed, 78 insertions, 55 deletions
diff --git a/app/models/ci/artifact_blob.rb b/app/models/ci/artifact_blob.rb
index 76d4b9d6206..f87b18d516f 100644
--- a/app/models/ci/artifact_blob.rb
+++ b/app/models/ci/artifact_blob.rb
@@ -46,7 +46,7 @@ module Ci
'artifacts', path
].join('/')
- "#{project.pages_group_url}/#{artifact_path}"
+ "#{project.pages_namespace_url}/#{artifact_path}"
end
def external_link?(job)
diff --git a/app/models/ci/bridge.rb b/app/models/ci/bridge.rb
index 662fb3cffa8..4af31fd37f2 100644
--- a/app/models/ci/bridge.rb
+++ b/app/models/ci/bridge.rb
@@ -19,11 +19,6 @@ module Ci
belongs_to :project
belongs_to :trigger_request
- # To be removed upon :ci_bridge_remove_sourced_pipelines feature flag removal
- has_many :sourced_pipelines, class_name: "::Ci::Sources::Pipeline",
- foreign_key: :source_job_id,
- inverse_of: :source_bridge
-
has_one :downstream_pipeline, through: :sourced_pipeline, source: :pipeline
validates :ref, presence: true
@@ -89,20 +84,8 @@ module Ci
end
end
- def sourced_pipelines
- if Feature.enabled?(:ci_bridge_remove_sourced_pipelines, project)
- raise 'Ci::Bridge does not have sourced_pipelines association'
- end
-
- super
- end
-
def has_downstream_pipeline?
- if Feature.enabled?(:ci_bridge_remove_sourced_pipelines, project)
- sourced_pipeline.present?
- else
- sourced_pipelines.exists?
- end
+ sourced_pipeline.present?
end
def downstream_pipeline_params
@@ -298,7 +281,7 @@ module Ci
return [] unless forward_yaml_variables?
yaml_variables.to_a.map do |hash|
- if hash[:raw] && ci_raw_variables_in_yaml_config_enabled?
+ if hash[:raw]
{ key: hash[:key], value: hash[:value], raw: true }
else
{ key: hash[:key], value: ::ExpandVariables.expand(hash[:value], expand_variables) }
@@ -310,7 +293,7 @@ module Ci
return [] unless forward_pipeline_variables?
pipeline.variables.to_a.map do |variable|
- if variable.raw? && ci_raw_variables_in_yaml_config_enabled?
+ if variable.raw?
{ key: variable.key, value: variable.value, raw: true }
else
{ key: variable.key, value: ::ExpandVariables.expand(variable.value, expand_variables) }
@@ -323,7 +306,7 @@ module Ci
return [] unless pipeline.pipeline_schedule
pipeline.pipeline_schedule.variables.to_a.map do |variable|
- if variable.raw? && ci_raw_variables_in_yaml_config_enabled?
+ if variable.raw?
{ key: variable.key, value: variable.value, raw: true }
else
{ key: variable.key, value: ::ExpandVariables.expand(variable.value, expand_variables) }
@@ -346,12 +329,6 @@ module Ci
result.nil? ? FORWARD_DEFAULTS[:pipeline_variables] : result
end
end
-
- def ci_raw_variables_in_yaml_config_enabled?
- strong_memoize(:ci_raw_variables_in_yaml_config_enabled) do
- ::Feature.enabled?(:ci_raw_variables_in_yaml_config, project)
- end
- end
end
end
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 7f42b21bc87..0139b025d98 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -68,6 +68,7 @@ module Ci
delegate :service_specification, to: :runner_session, allow_nil: true
delegate :gitlab_deploy_token, to: :project
delegate :harbor_integration, to: :project
+ delegate :apple_app_store_integration, to: :project
delegate :trigger_short_token, to: :trigger_request, allow_nil: true
delegate :ensure_persistent_ref, to: :pipeline
delegate :enable_debug_trace!, to: :metadata
@@ -587,6 +588,7 @@ module Ci
.append(key: 'CI_REPOSITORY_URL', value: repo_url.to_s, public: false)
.concat(deploy_token_variables)
.concat(harbor_variables)
+ .concat(apple_app_store_variables)
end
end
@@ -630,6 +632,13 @@ module Ci
Gitlab::Ci::Variables::Collection.new(harbor_integration.ci_variables)
end
+ def apple_app_store_variables
+ return [] unless apple_app_store_integration.try(:activated?)
+ return [] unless pipeline.protected_ref?
+
+ Gitlab::Ci::Variables::Collection.new(apple_app_store_integration.ci_variables)
+ end
+
def features
{
trace_sections: true,
@@ -736,6 +745,12 @@ module Ci
self.token && token.present? && ActiveSupport::SecurityUtils.secure_compare(token, self.token)
end
+ def remove_token!
+ if Feature.enabled?(:remove_job_token_on_completion, project)
+ update!(token_encrypted: nil)
+ end
+ end
+
# acts_as_taggable uses this method create/remove tags with contexts
# defined by taggings and to get those contexts it executes a query.
# We don't use any other contexts except `tags`, so we don't need it.
@@ -884,8 +899,9 @@ module Ci
return cache unless project.ci_separated_caches
- type_suffix = pipeline.protected_ref? ? 'protected' : 'non_protected'
cache.map do |entry|
+ type_suffix = !entry[:unprotect] && pipeline.protected_ref? ? 'protected' : 'non_protected'
+
entry.merge(key: "#{entry[:key]}-#{type_suffix}")
end
end
@@ -1135,15 +1151,9 @@ module Ci
end
end
- def partition_id_token_prefix
- partition_id.to_s(16) if Feature.enabled?(:ci_build_partition_id_token_prefix, project)
- end
-
override :format_token
def format_token(token)
- return token if partition_id_token_prefix.nil?
-
- "#{partition_id_token_prefix}_#{token}"
+ "#{partition_id.to_s(16)}_#{token}"
end
protected
diff --git a/app/models/ci/build_metadata.rb b/app/models/ci/build_metadata.rb
index 9b4794abb2e..1dcb9190f11 100644
--- a/app/models/ci/build_metadata.rb
+++ b/app/models/ci/build_metadata.rb
@@ -71,7 +71,7 @@ module Ci
end
def timeout_with_highest_precedence
- [(job_timeout || project_timeout), runner_timeout].compact.min_by { |timeout| timeout.value }
+ [(job_timeout || project_timeout), runner_timeout].compact.min_by(&:value)
end
def project_timeout
diff --git a/app/models/ci/build_trace_chunk.rb b/app/models/ci/build_trace_chunk.rb
index 57d8b9ba368..c5f6e54c336 100644
--- a/app/models/ci/build_trace_chunk.rb
+++ b/app/models/ci/build_trace_chunk.rb
@@ -166,7 +166,7 @@ module Ci
raise FailedToPersistDataError, 'Modifed build trace chunk detected' if has_changes_to_save?
self.class.with_read_consistency(build) do
- self.reset.then { |chunk| chunk.unsafe_persist_data! }
+ self.reset.then(&:unsafe_persist_data!)
end
end
rescue FailedToObtainLockError
diff --git a/app/models/ci/job_artifact.rb b/app/models/ci/job_artifact.rb
index 53c358f4eba..0dca5b18a24 100644
--- a/app/models/ci/job_artifact.rb
+++ b/app/models/ci/job_artifact.rb
@@ -14,6 +14,8 @@ module Ci
include EachBatch
include Gitlab::Utils::StrongMemoize
+ enum accessibility: { public: 0, private: 1 }, _suffix: true
+
NON_ERASABLE_FILE_TYPES = %w[trace].freeze
REPORT_FILE_TYPES = {
@@ -346,6 +348,12 @@ module Ci
end
end
+ def public_access?
+ return true unless Feature.enabled?(:non_public_artifacts, type: :development)
+
+ public_accessibility?
+ end
+
private
def store_file_in_transaction!
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 05207fb1ca0..eab2ab69e44 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -919,8 +919,12 @@ module Ci
Gitlab::Ci::Variables::Collection.new.tap do |variables|
next variables unless tag?
+ git_tag = project.repository.find_tag(ref)
+
+ next variables unless git_tag
+
variables.append(key: 'CI_COMMIT_TAG', value: ref)
- variables.append(key: 'CI_COMMIT_TAG_MESSAGE', value: project.repository.find_tag(ref).message)
+ variables.append(key: 'CI_COMMIT_TAG_MESSAGE', value: git_tag.message)
# legacy variable
variables.append(key: 'CI_BUILD_TAG', value: ref)
diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb
index a7f3ff938c3..bac85b6095e 100644
--- a/app/models/ci/runner.rb
+++ b/app/models/ci/runner.rb
@@ -13,6 +13,7 @@ module Ci
include TaggableQueries
include Presentable
include EachBatch
+ include Ci::HasRunnerExecutor
add_authentication_token_field :token, encrypted: :optional, expires_at: :compute_token_expiration
@@ -27,21 +28,6 @@ module Ci
project_type: 3
}
- enum executor_type: {
- unknown: 0,
- custom: 1,
- shell: 2,
- docker: 3,
- docker_windows: 4,
- docker_ssh: 5,
- ssh: 6,
- parallels: 7,
- virtualbox: 8,
- docker_machine: 9,
- docker_ssh_machine: 10,
- kubernetes: 11
- }, _suffix: true
-
# This `ONLINE_CONTACT_TIMEOUT` needs to be larger than
# `RUNNER_QUEUE_EXPIRY_TIME+UPDATE_CONTACT_COLUMN_EVERY`
#
@@ -68,6 +54,7 @@ module Ci
TAG_LIST_MAX_LENGTH = 50
+ has_many :runner_machines, inverse_of: :runner
has_many :builds
has_many :runner_projects, inverse_of: :runner, autosave: true, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_many :projects, through: :runner_projects, disable_joins: true
@@ -77,6 +64,8 @@ module Ci
has_one :last_build, -> { order('id DESC') }, class_name: 'Ci::Build'
has_one :runner_version, primary_key: :version, foreign_key: :version, class_name: 'Ci::RunnerVersion'
+ belongs_to :creator, class_name: 'User', optional: true
+
before_save :ensure_token
scope :active, -> (value = true) { where(active: value) }
@@ -440,7 +429,9 @@ module Ci
::Gitlab::Database::LoadBalancing::Session.without_sticky_writes do
values = values&.slice(:version, :revision, :platform, :architecture, :ip_address, :config, :executor) || {}
values[:contacted_at] = Time.current
- values[:executor_type] = EXECUTOR_NAME_TO_TYPES.fetch(values.delete(:executor), :unknown)
+ if values.include?(:executor)
+ values[:executor_type] = EXECUTOR_NAME_TO_TYPES.fetch(values.delete(:executor), :unknown)
+ end
cache_attributes(values)
diff --git a/app/models/ci/runner_machine.rb b/app/models/ci/runner_machine.rb
new file mode 100644
index 00000000000..1dd997a8ee1
--- /dev/null
+++ b/app/models/ci/runner_machine.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Ci
+ class RunnerMachine < Ci::ApplicationRecord
+ include FromUnion
+ include Ci::HasRunnerExecutor
+
+ belongs_to :runner
+
+ validates :runner, presence: true
+ validates :machine_xid, presence: true, length: { maximum: 64 }
+ validates :version, length: { maximum: 2048 }
+ validates :revision, length: { maximum: 255 }
+ validates :platform, length: { maximum: 255 }
+ validates :architecture, length: { maximum: 255 }
+ validates :ip_address, length: { maximum: 1024 }
+ validates :config, json_schema: { filename: 'ci_runner_config' }
+
+ # The `STALE_TIMEOUT` constant defines the how far past the last contact or creation date a runner machine
+ # will be considered stale
+ STALE_TIMEOUT = 7.days
+
+ scope :stale, -> do
+ created_some_time_ago = arel_table[:created_at].lteq(STALE_TIMEOUT.ago)
+ contacted_some_time_ago = arel_table[:contacted_at].lteq(STALE_TIMEOUT.ago)
+
+ from_union(
+ where(contacted_at: nil),
+ where(contacted_some_time_ago),
+ remove_duplicates: false).where(created_some_time_ago)
+ end
+ end
+end