Module: Ci::Deployable
- Extended by:
- ActiveSupport::Concern
- Includes:
- Gitlab::Utils::StrongMemoize
- Defined in:
- app/models/concerns/ci/deployable.rb
Instance Method Summary collapse
- #accesses_environment? ⇒ Boolean
-
#actual_persisted_environment ⇒ Object
If build.persisted_environment is a BatchLoader, we need to remove the method proxy in order to clone into new item here github.com/exAspArk/batch-loader/issues/31.
- #deployment_job? ⇒ Boolean (also: #starts_environment?)
-
#deployment_status ⇒ Object
Virtual deployment status depending on the environment status.
- #environment_action ⇒ Object
- #environment_auto_stop_in ⇒ Object
- #environment_options_for_permanent_storage ⇒ Object
- #environment_permanent_metadata ⇒ Object
- #environment_slug ⇒ Object
- #environment_status ⇒ Object
- #environment_tier ⇒ Object
- #environment_url ⇒ Object
- #expanded_auto_stop_in ⇒ Object
- #expanded_deployment_tier ⇒ Object
- #expanded_environment_name ⇒ Object
- #expanded_kubernetes_namespace ⇒ Object
- #has_environment_keyword? ⇒ Boolean
- #has_outdated_deployment? ⇒ Boolean
- #link_to_environment(environment) ⇒ Object
- #on_stop ⇒ Object
- #persisted_environment ⇒ Object
- #persisted_environment=(environment) ⇒ Object
- #prepares_environment? ⇒ Boolean
- #stop_action_successful? ⇒ Boolean
- #stops_environment? ⇒ Boolean
- #successful_deployment_status ⇒ Object
- #verifies_environment? ⇒ Boolean
Instance Method Details
#accesses_environment? ⇒ Boolean
171 172 173 |
# File 'app/models/concerns/ci/deployable.rb', line 171 def accesses_environment? has_environment_keyword? && environment_action == 'access' end |
#actual_persisted_environment ⇒ Object
If build.persisted_environment is a BatchLoader, we need to remove the method proxy in order to clone into new item here github.com/exAspArk/batch-loader/issues/31
100 101 102 |
# File 'app/models/concerns/ci/deployable.rb', line 100 def actual_persisted_environment persisted_environment.respond_to?(:__sync) ? persisted_environment.__sync : persisted_environment end |
#deployment_job? ⇒ Boolean Also known as: starts_environment?
166 167 168 |
# File 'app/models/concerns/ci/deployable.rb', line 166 def deployment_job? has_environment_keyword? && environment_action == 'start' end |
#deployment_status ⇒ Object
Virtual deployment status depending on the environment status.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/models/concerns/ci/deployable.rb', line 46 def deployment_status return unless deployment_job? if success? return successful_deployment_status elsif failed? return :failed end :creating end |
#environment_action ⇒ Object
187 188 189 |
# File 'app/models/concerns/ci/deployable.rb', line 187 def environment_action .fetch(:action, 'start') end |
#environment_auto_stop_in ⇒ Object
151 152 153 |
# File 'app/models/concerns/ci/deployable.rb', line 151 def environment_auto_stop_in [:auto_stop_in] end |
#environment_options_for_permanent_storage ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/models/concerns/ci/deployable.rb', line 104 def return {} unless && [:environment] = [:environment].slice(:action, :deployment_tier) # The Kubernetes namespace is required by the deprecated certificate-based # cluster integration. Once this functionality is removed, the namespace does # not need to be stored permanently and can be removed from this method. = .dig(:environment, :kubernetes)&.slice(:namespace) [:kubernetes] = if .present? end |
#environment_permanent_metadata ⇒ Object
226 227 228 229 230 231 232 233 234 |
# File 'app/models/concerns/ci/deployable.rb', line 226 def if job_environment.present? job_environment. else # TODO: This fallback can be removed when historical job environment # records have been backfilled. end end |
#environment_slug ⇒ Object
207 208 209 |
# File 'app/models/concerns/ci/deployable.rb', line 207 def environment_slug persisted_environment.try(:slug) end |
#environment_status ⇒ Object
211 212 213 214 215 |
# File 'app/models/concerns/ci/deployable.rb', line 211 def environment_status return unless has_environment_keyword? && merge_request EnvironmentStatus.new(project, persisted_environment, merge_request, pipeline.sha) end |
#environment_tier ⇒ Object
199 200 201 |
# File 'app/models/concerns/ci/deployable.rb', line 199 def environment_tier || persisted_environment.try(:tier) end |
#environment_url ⇒ Object
203 204 205 |
# File 'app/models/concerns/ci/deployable.rb', line 203 def environment_url [:url] || persisted_environment.try(:external_url) end |
#expanded_auto_stop_in ⇒ Object
155 156 157 158 159 |
# File 'app/models/concerns/ci/deployable.rb', line 155 def return unless environment_auto_stop_in ExpandVariables.(environment_auto_stop_in, -> { variables. }) end |
#expanded_deployment_tier ⇒ Object
191 192 193 194 195 196 |
# File 'app/models/concerns/ci/deployable.rb', line 191 def deployment_tier = [:deployment_tier] return unless deployment_tier.present? ExpandVariables.(deployment_tier, -> { simple_variables }) end |
#expanded_environment_name ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/models/concerns/ci/deployable.rb', line 118 def return unless has_environment_keyword? strong_memoize(:expanded_environment_name) do # We're using a persisted expanded environment name in order to avoid # variable expansion per request. if job_environment&..present? job_environment. elsif &..present? . else ExpandVariables.(environment, -> { simple_variables. }) end end end |
#expanded_kubernetes_namespace ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/models/concerns/ci/deployable.rb', line 134 def return unless has_environment_keyword? # `kubernetes.namespace` is used by both the Kubernetes dashboard and the # deprecated certificate-based cluster integration, and the latter relies # on the namespace being stored permanently. When the certificate-based # integration is removed, both of these will use #environment_processing_metadata. namespace = .dig(:kubernetes, :dashboard, :namespace) || .dig(:kubernetes, :namespace) return unless namespace.present? strong_memoize(:expanded_kubernetes_namespace) do ExpandVariables.(namespace, -> { simple_variables }) end end |
#has_environment_keyword? ⇒ Boolean
162 163 164 |
# File 'app/models/concerns/ci/deployable.rb', line 162 def has_environment_keyword? environment.present? end |
#has_outdated_deployment? ⇒ Boolean
36 37 38 39 40 41 42 |
# File 'app/models/concerns/ci/deployable.rb', line 36 def has_outdated_deployment? deployment_job? && project.ci_forward_deployment_enabled? && (!project.ci_forward_deployment_rollback_allowed? || incomplete?) && deployment&.persisted? && deployment.older_than_last_successful_deployment? end |
#link_to_environment(environment) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/models/concerns/ci/deployable.rb', line 66 def link_to_environment(environment) job_environment = build_job_environment( environment: environment, expanded_environment_name: environment.name, project: project, pipeline: pipeline, options: ) if persisted? && !job_environment.save Gitlab::ErrorTracking.track_and_raise_for_dev_exception( ActiveRecord::RecordInvalid.new(job_environment), job_id: id ) end job_environment end |
#on_stop ⇒ Object
218 219 220 |
# File 'app/models/concerns/ci/deployable.rb', line 218 def on_stop [:on_stop] end |
#persisted_environment ⇒ Object
85 86 87 88 89 90 91 |
# File 'app/models/concerns/ci/deployable.rb', line 85 def persisted_environment return unless has_environment_keyword? strong_memoize(:persisted_environment) do project.batch_loaded_environment_by_name() end end |
#persisted_environment=(environment) ⇒ Object
93 94 95 |
# File 'app/models/concerns/ci/deployable.rb', line 93 def persisted_environment=(environment) strong_memoize(:persisted_environment) { environment } end |
#prepares_environment? ⇒ Boolean
175 176 177 |
# File 'app/models/concerns/ci/deployable.rb', line 175 def prepares_environment? has_environment_keyword? && environment_action == 'prepare' end |
#stop_action_successful? ⇒ Boolean
222 223 224 |
# File 'app/models/concerns/ci/deployable.rb', line 222 def stop_action_successful? success? end |
#stops_environment? ⇒ Boolean
183 184 185 |
# File 'app/models/concerns/ci/deployable.rb', line 183 def stops_environment? has_environment_keyword? && environment_action == 'stop' end |
#successful_deployment_status ⇒ Object
58 59 60 61 62 63 64 |
# File 'app/models/concerns/ci/deployable.rb', line 58 def successful_deployment_status if deployment&.last? :last else :out_of_date end end |
#verifies_environment? ⇒ Boolean
179 180 181 |
# File 'app/models/concerns/ci/deployable.rb', line 179 def verifies_environment? has_environment_keyword? && environment_action == 'verify' end |