Class: Gitlab::Ci::Config::External::Context
- Inherits:
-
Object
- Object
- Gitlab::Ci::Config::External::Context
- Includes:
- Utils::StrongMemoize
- Defined in:
- lib/gitlab/ci/config/external/context.rb
Constant Summary collapse
- TimeoutError =
Class.new(StandardError)
- MAX_PARALLEL_REMOTE_REQUESTS =
We try to keep the number of parallel HTTP requests to a minimum to avoid overloading IO.
4
Instance Attribute Summary collapse
-
#execution_deadline ⇒ Object
readonly
Returns the value of attribute execution_deadline.
-
#expandset ⇒ Object
readonly
Returns the value of attribute expandset.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#max_includes ⇒ Object
readonly
Returns the value of attribute max_includes.
-
#max_total_yaml_size_bytes ⇒ Object
readonly
Returns the value of attribute max_total_yaml_size_bytes.
-
#parallel_requests ⇒ Object
readonly
Returns the value of attribute parallel_requests.
-
#parent_pipeline ⇒ Object
readonly
Returns the value of attribute parent_pipeline.
-
#pipeline ⇒ Object
readonly
Returns the value of attribute pipeline.
-
#pipeline_config ⇒ Object
readonly
Returns the value of attribute pipeline_config.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#sha ⇒ Object
readonly
Returns the value of attribute sha.
-
#total_file_size_in_bytes ⇒ Object
Returns the value of attribute total_file_size_in_bytes.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Instance Method Summary collapse
- #all_worktree_paths ⇒ Object
- #check_execution_time! ⇒ Object
- #execute_remote_parallel_request(lazy_response) ⇒ Object
- #includes ⇒ Object
-
#initialize(project: nil, pipeline: nil, sha: nil, user: nil, parent_pipeline: nil, variables: nil, pipeline_config: nil, logger: nil) {|_self| ... } ⇒ Context
constructor
A new instance of Context.
-
#internal_include? ⇒ Boolean
Some Ci::ProjectConfig sources prepend the config content with an “internal” ‘include`, which becomes the first included file.
- #mask_variables_from(string) ⇒ Object
- #mutate(attrs = {}) ⇒ Object
- #sentry_payload ⇒ Object
- #set_deadline(timeout_seconds) ⇒ Object
- #top_level_worktree_paths ⇒ Object
- #variables_hash ⇒ Object
- #variables_hash_expanded ⇒ Object
- #variables_sorted_and_expanded ⇒ Object
Constructor Details
#initialize(project: nil, pipeline: nil, sha: nil, user: nil, parent_pipeline: nil, variables: nil, pipeline_config: nil, logger: nil) {|_self| ... } ⇒ Context
Returns a new instance of Context.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gitlab/ci/config/external/context.rb', line 24 def initialize( project: nil, pipeline: nil, sha: nil, user: nil, parent_pipeline: nil, variables: nil, pipeline_config: nil, logger: nil ) @project = project @pipeline = pipeline @sha = sha @user = user @parent_pipeline = parent_pipeline @variables = variables || Ci::Variables::Collection.new @pipeline_config = pipeline_config @expandset = [] @parallel_requests = [] @execution_deadline = 0 @logger = logger || Gitlab::Ci::Pipeline::Logger.new(project: project) @max_includes = Gitlab::CurrentSettings.current_application_settings.ci_max_includes @max_total_yaml_size_bytes = Gitlab::CurrentSettings.current_application_settings.ci_max_total_yaml_size_bytes @total_file_size_in_bytes = 0 yield self if block_given? end |
Instance Attribute Details
#execution_deadline ⇒ Object
Returns the value of attribute execution_deadline.
14 15 16 |
# File 'lib/gitlab/ci/config/external/context.rb', line 14 def execution_deadline @execution_deadline end |
#expandset ⇒ Object
Returns the value of attribute expandset.
14 15 16 |
# File 'lib/gitlab/ci/config/external/context.rb', line 14 def @expandset end |
#logger ⇒ Object
Returns the value of attribute logger.
14 15 16 |
# File 'lib/gitlab/ci/config/external/context.rb', line 14 def logger @logger end |
#max_includes ⇒ Object
Returns the value of attribute max_includes.
14 15 16 |
# File 'lib/gitlab/ci/config/external/context.rb', line 14 def max_includes @max_includes end |
#max_total_yaml_size_bytes ⇒ Object
Returns the value of attribute max_total_yaml_size_bytes.
14 15 16 |
# File 'lib/gitlab/ci/config/external/context.rb', line 14 def max_total_yaml_size_bytes @max_total_yaml_size_bytes end |
#parallel_requests ⇒ Object
Returns the value of attribute parallel_requests.
14 15 16 |
# File 'lib/gitlab/ci/config/external/context.rb', line 14 def parallel_requests @parallel_requests end |
#parent_pipeline ⇒ Object (readonly)
Returns the value of attribute parent_pipeline.
14 15 16 |
# File 'lib/gitlab/ci/config/external/context.rb', line 14 def parent_pipeline @parent_pipeline end |
#pipeline ⇒ Object
Returns the value of attribute pipeline.
14 15 16 |
# File 'lib/gitlab/ci/config/external/context.rb', line 14 def pipeline @pipeline end |
#pipeline_config ⇒ Object (readonly)
Returns the value of attribute pipeline_config.
14 15 16 |
# File 'lib/gitlab/ci/config/external/context.rb', line 14 def pipeline_config @pipeline_config end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
14 15 16 |
# File 'lib/gitlab/ci/config/external/context.rb', line 14 def project @project end |
#sha ⇒ Object (readonly)
Returns the value of attribute sha.
14 15 16 |
# File 'lib/gitlab/ci/config/external/context.rb', line 14 def sha @sha end |
#total_file_size_in_bytes ⇒ Object
Returns the value of attribute total_file_size_in_bytes.
17 18 19 |
# File 'lib/gitlab/ci/config/external/context.rb', line 17 def total_file_size_in_bytes @total_file_size_in_bytes end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
14 15 16 |
# File 'lib/gitlab/ci/config/external/context.rb', line 14 def user @user end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
14 15 16 |
# File 'lib/gitlab/ci/config/external/context.rb', line 14 def variables @variables end |
Instance Method Details
#all_worktree_paths ⇒ Object
52 53 54 55 56 |
# File 'lib/gitlab/ci/config/external/context.rb', line 52 def all_worktree_paths strong_memoize(:all_worktree_paths) do project.repository.ls_files(sha) end end |
#check_execution_time! ⇒ Object
100 101 102 |
# File 'lib/gitlab/ci/config/external/context.rb', line 100 def check_execution_time! raise TimeoutError if execution_expired? end |
#execute_remote_parallel_request(lazy_response) ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/gitlab/ci/config/external/context.rb', line 104 def execute_remote_parallel_request(lazy_response) parallel_requests.delete_if(&:complete?) # We are "assuming" that the first request in the queue is the first one to complete. # This is good enough approximation. parallel_requests.first&.wait unless parallel_requests.size < MAX_PARALLEL_REMOTE_REQUESTS parallel_requests << lazy_response.execute end |
#includes ⇒ Object
131 132 133 |
# File 'lib/gitlab/ci/config/external/context.rb', line 131 def includes .map(&:metadata) end |
#internal_include? ⇒ Boolean
Some Ci::ProjectConfig sources prepend the config content with an “internal” ‘include`, which becomes the first included file. When running a pipeline, we pass pipeline_config into the context of the first included file, which we use in this method to determine if the file is an “internal” one.
138 139 140 |
# File 'lib/gitlab/ci/config/external/context.rb', line 138 def internal_include? !!pipeline_config&.internal_include_prepended? end |
#mask_variables_from(string) ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/gitlab/ci/config/external/context.rb', line 121 def mask_variables_from(string) variables.reduce(string.dup) do |str, variable| if variable[:masked] Gitlab::Ci::MaskSecret.mask!(str, variable[:value]) else str end end end |
#mutate(attrs = {}) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/gitlab/ci/config/external/context.rb', line 84 def mutate(attrs = {}) self.class.new(**attrs) do |ctx| ctx.pipeline = pipeline ctx. = ctx.execution_deadline = execution_deadline ctx.logger = logger ctx.max_includes = max_includes ctx.max_total_yaml_size_bytes = max_total_yaml_size_bytes ctx.parallel_requests = parallel_requests end end |
#sentry_payload ⇒ Object
114 115 116 117 118 119 |
# File 'lib/gitlab/ci/config/external/context.rb', line 114 def sentry_payload { user: user.inspect, project: project.inspect } end |
#set_deadline(timeout_seconds) ⇒ Object
96 97 98 |
# File 'lib/gitlab/ci/config/external/context.rb', line 96 def set_deadline(timeout_seconds) @execution_deadline = current_monotonic_time + timeout_seconds.to_f end |
#top_level_worktree_paths ⇒ Object
46 47 48 49 50 |
# File 'lib/gitlab/ci/config/external/context.rb', line 46 def top_level_worktree_paths strong_memoize(:top_level_worktree_paths) do project.repository.tree(sha).blobs.map(&:path) end end |
#variables_hash ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/gitlab/ci/config/external/context.rb', line 58 def variables_hash strong_memoize(:variables_hash) do if ci_optimize_memory_for_variables_enabled? variables.to_hash else variables.to_hash_legacy end end end |
#variables_hash_expanded ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/gitlab/ci/config/external/context.rb', line 68 def strong_memoize(:variables_hash_expanded) do if ci_optimize_memory_for_variables_enabled? .to_hash else .to_hash_legacy end end end |
#variables_sorted_and_expanded ⇒ Object
78 79 80 81 82 |
# File 'lib/gitlab/ci/config/external/context.rb', line 78 def strong_memoize(:variables_sorted_and_expanded) do variables. end end |