Class: DeploYML::Environment
- Inherits:
-
Configuration
- Object
- Configuration
- DeploYML::Environment
- Defined in:
- lib/deployml/environment.rb
Overview
Contains environment specific configuration loaded by Project
from YAML files within config/deploy/
.
Constant Summary collapse
- SERVERS =
Mapping of possible 'server' names to their mixins.
{ :apache => Servers::Apache, :mongrel => Servers::Mongrel, :thin => Servers::Thin }
- FRAMEWORKS =
Mapping of possible 'framework' names to their mixins.
{ :rails => Frameworks::Rails }
Constants inherited from Configuration
Configuration::DEFAULT_SCM, Configuration::TASKS
Instance Attribute Summary
Attributes inherited from Configuration
#after, #before, #bundler, #debug, #dest, #environment, #framework, #orm, #server_name, #server_options, #source
Instance Method Summary collapse
-
#config(shell) ⇒ Object
Place-holder method.
-
#config! ⇒ true
Configures the Web server to be ran on the destination server.
-
#deploy! ⇒ true
Deploys a new project.
-
#exec(command) ⇒ true
Runs a command on the destination server, in the destination directory.
-
#initialize(name, config = {}) ⇒ Environment
constructor
Creates a new deployment environment.
-
#install(shell) ⇒ Object
Installs any additional dependencies.
-
#install! ⇒ true
Installs the project on the destination server.
-
#invoke(tasks) ⇒ true
Deploys the project.
-
#invoke_task(task, shell) ⇒ Object
Invokes a task.
-
#load_framework! ⇒ Object
protected
Loads the framework configuration.
-
#load_server! ⇒ Object
protected
Loads the server configuration.
-
#local_shell {|shell| ... } ⇒ Array<LocalShell>
Creates a local shell.
-
#migrate(shell) ⇒ Object
Place-holder method.
-
#migrate! ⇒ true
Migrates the database used by the project.
-
#rake(task, *arguments) ⇒ true
Executes a Rake task on the destination server, in the destination directory.
-
#redeploy! ⇒ true
Redeploys a project.
-
#remote_shell {|shell| ... } ⇒ Array<RemoteShell, LocalShell>
Creates a remote shell with the destination server.
-
#restart(shell) ⇒ Object
Place-holder method.
-
#restart! ⇒ true
Restarts the Web server for the project.
-
#server_config(shell) ⇒ Object
Place-holder method.
-
#server_restart(shell) ⇒ Object
Place-holder method.
-
#server_start(shell) ⇒ Object
Place-holder method.
-
#server_stop(shell) ⇒ Object
Place-holder method.
-
#setup(shell) ⇒ Object
Sets up the deployment repository for the project.
-
#setup! ⇒ true
Sets up the deployment repository for the project.
-
#ssh(*arguments) ⇒ true
Starts an SSH session with the destination server.
-
#start(shell) ⇒ Object
Place-holder method.
-
#start! ⇒ true
Starts the Web server for the project.
-
#stop(shell) ⇒ Object
Place-holder method.
-
#stop! ⇒ true
Stops the Web server for the project.
-
#update(shell) ⇒ Object
Updates the deployed repository for the project.
-
#update! ⇒ true
Updates the deployed repository of the project.
Methods inherited from Configuration
#each_dest, #normalize, #normalize_array, #normalize_hash, #parse_address, #parse_commands, #parse_dest, #parse_server
Constructor Details
#initialize(name, config = {}) ⇒ Environment
Creates a new deployment environment.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/deployml/environment.rb', line 44 def initialize(name,config={}) super(config) unless @source raise(MissingOption,":source option is missing for the #{@name} environment",caller) end unless @dest raise(MissingOption,":dest option is missing for the #{@name} environment",caller) end @environment ||= name.to_sym load_framework! load_server! end |
Instance Method Details
#config(shell) ⇒ Object
Place-holder method.
272 273 274 |
# File 'lib/deployml/environment.rb', line 272 def config(shell) server_config(shell) end |
#config! ⇒ true
Configures the Web server to be ran on the destination server.
439 440 441 |
# File 'lib/deployml/environment.rb', line 439 def config! invoke [:config] end |
#deploy! ⇒ true
Deploys a new project.
487 488 489 |
# File 'lib/deployml/environment.rb', line 487 def deploy! invoke [:setup, :install, :migrate, :config, :start] end |
#exec(command) ⇒ true
Runs a command on the destination server, in the destination directory.
114 115 116 117 118 119 120 121 |
# File 'lib/deployml/environment.rb', line 114 def exec(command) remote_shell do |shell| shell.cd(shell.uri.path) shell.exec(command) end return true end |
#install(shell) ⇒ Object
Installs any additional dependencies.
199 200 201 202 203 204 205 206 207 |
# File 'lib/deployml/environment.rb', line 199 def install(shell) if @bundler shell.status "Bundling dependencies ..." shell.run 'bundle', 'install', '--deployment' shell.status "Dependencies bundled." end end |
#install! ⇒ true
Installs the project on the destination server.
415 416 417 |
# File 'lib/deployml/environment.rb', line 415 def install! invoke [:install] end |
#invoke(tasks) ⇒ true
Deploys the project.
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/deployml/environment.rb', line 353 def invoke(tasks) remote_shell do |shell| # setup the deployment repository invoke_task(:setup,shell) if tasks.include?(:setup) # cd into the deployment repository shell.cd(shell.uri.path) # update the deployment repository invoke_task(:update,shell) if tasks.include?(:update) # framework tasks invoke_task(:install,shell) if tasks.include?(:install) invoke_task(:migrate,shell) if tasks.include?(:migrate) # server tasks if tasks.include?(:config) invoke_task(:config,shell) elsif tasks.include?(:start) invoke_task(:start,shell) elsif tasks.include?(:stop) invoke_task(:stop,shell) elsif tasks.include?(:restart) invoke_task(:restart,shell) end end return true end |
#invoke_task(task, shell) ⇒ Object
Invokes a task.
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/deployml/environment.rb', line 326 def invoke_task(task,shell) unless TASKS.include?(task) raise("invalid task: #{task}") end if @before.has_key?(task) @before[task].each { |command| shell.exec(command) } end send(task,shell) if respond_to?(task) if @after.has_key?(task) @after[task].each { |command| shell.exec(command) } end end |
#load_framework! ⇒ Object (protected)
Loads the framework configuration.
510 511 512 513 514 515 516 517 518 519 520 |
# File 'lib/deployml/environment.rb', line 510 def load_framework! if @orm unless FRAMEWORKS.has_key?(@framework) raise(UnknownFramework,"Unknown framework #{@framework}",caller) end extend FRAMEWORKS[@framework] initialize_framework if respond_to?(:initialize_framework) end end |
#load_server! ⇒ Object (protected)
Loads the server configuration.
529 530 531 532 533 534 535 536 537 538 539 |
# File 'lib/deployml/environment.rb', line 529 def load_server! if @server_name unless SERVERS.has_key?(@server_name) raise(UnknownServer,"Unknown server name #{@server_name}",caller) end extend SERVERS[@server_name] initialize_server if respond_to?(:initialize_server) end end |
#local_shell {|shell| ... } ⇒ Array<LocalShell>
Creates a local shell.
75 76 77 |
# File 'lib/deployml/environment.rb', line 75 def local_shell(&block) each_dest.map { |dest| LocalShell.new(dest,self,&block) } end |
#migrate(shell) ⇒ Object
Place-holder method.
217 218 |
# File 'lib/deployml/environment.rb', line 217 def migrate(shell) end |
#migrate! ⇒ true
Migrates the database used by the project.
427 428 429 |
# File 'lib/deployml/environment.rb', line 427 def migrate! invoke [:migrate] end |
#rake(task, *arguments) ⇒ true
Executes a Rake task on the destination server, in the destination directory.
131 132 133 134 135 136 137 138 |
# File 'lib/deployml/environment.rb', line 131 def rake(task,*arguments) remote_shell do |shell| shell.cd(shell.uri.path) shell.rake(task,*arguments) end return true end |
#redeploy! ⇒ true
Redeploys a project.
499 500 501 |
# File 'lib/deployml/environment.rb', line 499 def redeploy! invoke [:update, :install, :migrate, :restart] end |
#remote_shell {|shell| ... } ⇒ Array<RemoteShell, LocalShell>
Creates a remote shell with the destination server.
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/deployml/environment.rb', line 94 def remote_shell(&block) each_dest.map do |dest| shell = if dest.scheme == 'file' LocalShell else RemoteShell end shell.new(dest,self,&block) end end |
#restart(shell) ⇒ Object
Place-holder method.
308 309 310 |
# File 'lib/deployml/environment.rb', line 308 def restart(shell) server_restart(shell) end |
#restart! ⇒ true
Restarts the Web server for the project.
475 476 477 |
# File 'lib/deployml/environment.rb', line 475 def restart! invoke [:restart] end |
#server_config(shell) ⇒ Object
Place-holder method.
228 229 |
# File 'lib/deployml/environment.rb', line 228 def server_config(shell) end |
#server_restart(shell) ⇒ Object
Place-holder method.
261 262 |
# File 'lib/deployml/environment.rb', line 261 def server_restart(shell) end |
#server_start(shell) ⇒ Object
Place-holder method.
239 240 |
# File 'lib/deployml/environment.rb', line 239 def server_start(shell) end |
#server_stop(shell) ⇒ Object
Place-holder method.
250 251 |
# File 'lib/deployml/environment.rb', line 250 def server_stop(shell) end |
#setup(shell) ⇒ Object
Sets up the deployment repository for the project.
166 167 168 169 170 171 172 |
# File 'lib/deployml/environment.rb', line 166 def setup(shell) shell.status "Cloning #{@source} ..." shell.run 'git', 'clone', '--depth', 1, @source, shell.uri.path shell.status "Cloned #{@source}." end |
#setup! ⇒ true
Sets up the deployment repository for the project.
391 392 393 |
# File 'lib/deployml/environment.rb', line 391 def setup! invoke [:setup] end |
#ssh(*arguments) ⇒ true
Starts an SSH session with the destination server.
150 151 152 153 154 155 156 |
# File 'lib/deployml/environment.rb', line 150 def ssh(*arguments) each_dest do |dest| RemoteShell.new(dest).ssh(*arguments) end return true end |
#start(shell) ⇒ Object
Place-holder method.
284 285 286 |
# File 'lib/deployml/environment.rb', line 284 def start(shell) server_start(shell) end |
#start! ⇒ true
Starts the Web server for the project.
451 452 453 |
# File 'lib/deployml/environment.rb', line 451 def start! invoke [:start] end |
#stop(shell) ⇒ Object
Place-holder method.
296 297 298 |
# File 'lib/deployml/environment.rb', line 296 def stop(shell) server_stop(shell) end |
#stop! ⇒ true
Stops the Web server for the project.
463 464 465 |
# File 'lib/deployml/environment.rb', line 463 def stop! invoke [:stop] end |
#update(shell) ⇒ Object
Updates the deployed repository for the project.
182 183 184 185 186 187 188 189 |
# File 'lib/deployml/environment.rb', line 182 def update(shell) shell.status "Updating ..." shell.run 'git', 'reset', '--hard', 'HEAD' shell.run 'git', 'pull', '-f' shell.status "Updated." end |
#update! ⇒ true
Updates the deployed repository of the project.
403 404 405 |
# File 'lib/deployml/environment.rb', line 403 def update! invoke [:update] end |