Class: Gjallarhorn::Deployer
- Inherits:
-
Object
- Object
- Gjallarhorn::Deployer
- Defined in:
- lib/gjallarhorn/deployer.rb
Overview
Main deployment orchestrator class
Constant Summary collapse
- DEFAULT_CONFIG_FILE =
Default configuration file path
"config/deploy.yml"- ADAPTERS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Mapping of provider names to their corresponding adapter classes
{ "aws" => Adapter::AWSAdapter, "gcp" => nil, # TODO: Implement in Phase 2 "azure" => nil, # TODO: Implement in Phase 2 "docker" => nil, # TODO: Implement in Phase 2 "kubernetes" => nil # TODO: Implement in Phase 3 }.freeze
Instance Attribute Summary collapse
-
#configuration ⇒ Configuration
readonly
The loaded deployment configuration.
-
#logger ⇒ Logger
readonly
Logger instance for deployment operations.
Instance Method Summary collapse
-
#create_adapter(environment) ⇒ Adapter::Base
private
private
Create an adapter instance for the specified environment.
-
#create_deployment_strategy(strategy_name, adapter, environment) ⇒ Deployment::Strategy
private
private
Create a deployment strategy instance.
-
#create_proxy_manager(environment) ⇒ Proxy::Manager?
private
private
Create a proxy manager instance for zero-downtime deployments.
-
#deploy(environment, image, strategy: "zero_downtime") ⇒ void
Deploy a container image to the specified environment.
-
#deploy_with_strategy(environment, image, strategy) ⇒ void
Deploy with specific strategy (convenience method).
-
#initialize(config_file = DEFAULT_CONFIG_FILE) ⇒ Deployer
constructor
Initialize a new Deployer instance.
-
#rollback(environment, version) ⇒ void
Rollback services in the environment to a previous version.
-
#status(environment) ⇒ Hash
Get the current status of services in the specified environment.
Constructor Details
#initialize(config_file = DEFAULT_CONFIG_FILE) ⇒ Deployer
Initialize a new Deployer instance
61 62 63 64 65 |
# File 'lib/gjallarhorn/deployer.rb', line 61 def initialize(config_file = DEFAULT_CONFIG_FILE) @configuration = Configuration.new(config_file) @logger = Logger.new($stdout) @history = History.new end |
Instance Attribute Details
#configuration ⇒ Configuration (readonly)
Returns The loaded deployment configuration.
52 53 54 |
# File 'lib/gjallarhorn/deployer.rb', line 52 def configuration @configuration end |
#logger ⇒ Logger (readonly)
Returns Logger instance for deployment operations.
55 56 57 |
# File 'lib/gjallarhorn/deployer.rb', line 55 def logger @logger end |
Instance Method Details
#create_adapter(environment) ⇒ Adapter::Base (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create an adapter instance for the specified environment
180 181 182 183 184 185 186 187 188 |
# File 'lib/gjallarhorn/deployer.rb', line 180 def create_adapter(environment) env_config = @configuration.environment(environment) provider = env_config["provider"] adapter_class = ADAPTERS[provider] raise DeploymentError, "Provider '#{provider}' not yet implemented" unless adapter_class adapter_class.new(env_config) end |
#create_deployment_strategy(strategy_name, adapter, environment) ⇒ Deployment::Strategy (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a deployment strategy instance
198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/gjallarhorn/deployer.rb', line 198 def create_deployment_strategy(strategy_name, adapter, environment) proxy_manager = create_proxy_manager(environment) if strategy_name == "zero_downtime" case strategy_name when "zero_downtime" Deployment::ZeroDowntime.new(adapter, proxy_manager, @logger) when "basic" Deployment::Basic.new(adapter, proxy_manager, @logger) when "legacy" Deployment::Legacy.new(adapter, proxy_manager, @logger) else raise DeploymentError, "Deployment strategy '#{strategy_name}' not yet implemented" end end |
#create_proxy_manager(environment) ⇒ Proxy::Manager? (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a proxy manager instance for zero-downtime deployments
218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/gjallarhorn/deployer.rb', line 218 def create_proxy_manager(environment) env_config = @configuration.environment(environment) proxy_config = env_config["proxy"] return nil unless proxy_config Proxy::Manager.create(proxy_config.transform_keys(&:to_sym), @logger) rescue StandardError => e @logger.warn "Failed to create proxy manager: #{e.}" nil end |
#deploy(environment, image, strategy: "zero_downtime") ⇒ void
This method returns an undefined value.
Deploy a container image to the specified environment
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/gjallarhorn/deployer.rb', line 74 def deploy(environment, image, strategy: "zero_downtime") # Record deployment start @history.record_deployment( environment: environment, image: image, status: "started", strategy: strategy ) adapter = create_adapter(environment) deployment_strategy = create_deployment_strategy(strategy, adapter, environment) @logger.info "Deploying #{image} to #{environment} using #{adapter.class.name} with #{strategy} strategy" deployment_strategy.deploy( image: image, environment: environment, services: @configuration.services_for(environment) ) @logger.info "Deployment completed successfully" # Record successful deployment @history.record_deployment( environment: environment, image: image, status: "success", strategy: strategy ) rescue StandardError => e # Record failed deployment @history.record_deployment( environment: environment, image: image, status: "failed", strategy: strategy, error: e. ) raise end |
#deploy_with_strategy(environment, image, strategy) ⇒ void
This method returns an undefined value.
Deploy with specific strategy (convenience method)
121 122 123 |
# File 'lib/gjallarhorn/deployer.rb', line 121 def deploy_with_strategy(environment, image, strategy) deploy(environment, image, strategy: strategy) end |
#rollback(environment, version) ⇒ void
This method returns an undefined value.
Rollback services in the environment to a previous version
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/gjallarhorn/deployer.rb', line 141 def rollback(environment, version) # Record rollback start @history.record_deployment( environment: environment, image: version, status: "started", strategy: "rollback" ) adapter = create_adapter(environment) adapter.rollback(version: version) # Record successful rollback @history.record_deployment( environment: environment, image: version, status: "success", strategy: "rollback" ) rescue StandardError => e # Record failed rollback @history.record_deployment( environment: environment, image: version, status: "failed", strategy: "rollback", error: e. ) raise end |
#status(environment) ⇒ Hash
Get the current status of services in the specified environment
130 131 132 133 |
# File 'lib/gjallarhorn/deployer.rb', line 130 def status(environment) adapter = create_adapter(environment) adapter.status end |