Module: Ci::Deployable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/ci/deployable.rb
Instance Method Summary collapse
-
#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
-
#deployment_status ⇒ Object
Virtual deployment status depending on the environment status.
- #environment_action ⇒ Object
- #environment_slug ⇒ Object
- #environment_status ⇒ Object
- #environment_tier ⇒ Object
- #environment_tier_from_options ⇒ Object
- #environment_url ⇒ Object
- #expanded_environment_name ⇒ Object
- #expanded_kubernetes_namespace ⇒ Object
- #has_environment_keyword? ⇒ Boolean
- #on_stop ⇒ Object
- #outdated_deployment? ⇒ Boolean
- #persisted_environment ⇒ Object
- #persisted_environment=(environment) ⇒ Object
- #stop_action_successful? ⇒ Boolean
- #stops_environment? ⇒ Boolean
- #successful_deployment_status ⇒ Object
Instance Method Details
#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
86 87 88 |
# File 'app/models/concerns/ci/deployable.rb', line 86 def actual_persisted_environment persisted_environment.respond_to?(:__sync) ? persisted_environment.__sync : persisted_environment end |
#deployment_job? ⇒ Boolean
120 121 122 |
# File 'app/models/concerns/ci/deployable.rb', line 120 def deployment_job? has_environment_keyword? && environment_action == 'start' end |
#deployment_status ⇒ Object
Virtual deployment status depending on the environment status.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/concerns/ci/deployable.rb', line 44 def deployment_status return unless deployment_job? if success? return successful_deployment_status elsif failed? return :failed end :creating end |
#environment_action ⇒ Object
128 129 130 |
# File 'app/models/concerns/ci/deployable.rb', line 128 def environment_action .fetch(:environment, {}).fetch(:action, 'start') if end |
#environment_slug ⇒ Object
144 145 146 |
# File 'app/models/concerns/ci/deployable.rb', line 144 def environment_slug persisted_environment.try(:slug) end |
#environment_status ⇒ Object
148 149 150 151 152 153 154 |
# File 'app/models/concerns/ci/deployable.rb', line 148 def environment_status strong_memoize(:environment_status) do if has_environment_keyword? && merge_request EnvironmentStatus.new(project, persisted_environment, merge_request, pipeline.sha) end end end |
#environment_tier ⇒ Object
136 137 138 |
# File 'app/models/concerns/ci/deployable.rb', line 136 def environment_tier || persisted_environment.try(:tier) end |
#environment_tier_from_options ⇒ Object
132 133 134 |
# File 'app/models/concerns/ci/deployable.rb', line 132 def .dig(:environment, :deployment_tier) if end |
#environment_url ⇒ Object
140 141 142 |
# File 'app/models/concerns/ci/deployable.rb', line 140 def environment_url &.dig(:environment, :url) || persisted_environment.try(:external_url) end |
#expanded_environment_name ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/models/concerns/ci/deployable.rb', line 90 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 &..present? . else ExpandVariables.(environment, -> { simple_variables. }) end end end |
#expanded_kubernetes_namespace ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/models/concerns/ci/deployable.rb', line 104 def return unless has_environment_keyword? namespace = .dig(:environment, :kubernetes, :namespace) if namespace.present? # rubocop:disable Style/GuardClause strong_memoize(:expanded_kubernetes_namespace) do ExpandVariables.(namespace, -> { simple_variables }) end end end |
#has_environment_keyword? ⇒ Boolean
116 117 118 |
# File 'app/models/concerns/ci/deployable.rb', line 116 def has_environment_keyword? environment.present? end |
#on_stop ⇒ Object
156 157 158 |
# File 'app/models/concerns/ci/deployable.rb', line 156 def on_stop &.dig(:environment, :on_stop) end |
#outdated_deployment? ⇒ Boolean
34 35 36 37 38 39 40 41 |
# File 'app/models/concerns/ci/deployable.rb', line 34 def outdated_deployment? strong_memoize(:outdated_deployment) do deployment_job? && project.ci_forward_deployment_enabled? && (!project.ci_forward_deployment_rollback_allowed? || incomplete?) && deployment&.older_than_last_successful_deployment? end end |
#persisted_environment ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/models/concerns/ci/deployable.rb', line 64 def persisted_environment return unless has_environment_keyword? strong_memoize(:persisted_environment) do # This code path has caused N+1s in the past, since environments are only indirectly # associated to builds and pipelines; see https://gitlab.com/gitlab-org/gitlab/-/issues/326445 # We therefore batch-load them to prevent dormant N+1s until we found a proper solution. BatchLoader.for().batch(key: project_id) do |names, loader, args| Environment.where(name: names, project: args[:key]).find_each do |environment| loader.call(environment.name, environment) end end end end |
#persisted_environment=(environment) ⇒ Object
79 80 81 |
# File 'app/models/concerns/ci/deployable.rb', line 79 def persisted_environment=(environment) strong_memoize(:persisted_environment) { environment } end |
#stop_action_successful? ⇒ Boolean
160 161 162 |
# File 'app/models/concerns/ci/deployable.rb', line 160 def stop_action_successful? success? end |
#stops_environment? ⇒ Boolean
124 125 126 |
# File 'app/models/concerns/ci/deployable.rb', line 124 def stops_environment? has_environment_keyword? && environment_action == 'stop' end |
#successful_deployment_status ⇒ Object
56 57 58 59 60 61 62 |
# File 'app/models/concerns/ci/deployable.rb', line 56 def successful_deployment_status if deployment&.last? :last else :out_of_date end end |