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.
{ :rails2 => Frameworks::Rails2, :rails3 => Frameworks::Rails3 }
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.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/deployml/environment.rb', line 45 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.
273 274 275 |
# File 'lib/deployml/environment.rb', line 273 def config(shell) server_config(shell) end |
#config! ⇒ true
Configures the Web server to be ran on the destination server.
440 441 442 |
# File 'lib/deployml/environment.rb', line 440 def config! invoke [:config] end |
#deploy! ⇒ true
Deploys a new project.
488 489 490 |
# File 'lib/deployml/environment.rb', line 488 def deploy! invoke [:setup, :install, :migrate, :config, :start] end |
#exec(command) ⇒ true
Runs a command on the destination server, in the destination directory.
115 116 117 118 119 120 121 122 |
# File 'lib/deployml/environment.rb', line 115 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.
200 201 202 203 204 205 206 207 208 |
# File 'lib/deployml/environment.rb', line 200 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.
416 417 418 |
# File 'lib/deployml/environment.rb', line 416 def install! invoke [:install] end |
#invoke(tasks) ⇒ true
Deploys the project.
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 382 |
# File 'lib/deployml/environment.rb', line 354 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.
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/deployml/environment.rb', line 327 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.
511 512 513 514 515 516 517 518 519 520 521 |
# File 'lib/deployml/environment.rb', line 511 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.
530 531 532 533 534 535 536 537 538 539 540 |
# File 'lib/deployml/environment.rb', line 530 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.
76 77 78 |
# File 'lib/deployml/environment.rb', line 76 def local_shell(&block) each_dest.map { |dest| LocalShell.new(dest,&block) } end |
#migrate(shell) ⇒ Object
Place-holder method.
218 219 |
# File 'lib/deployml/environment.rb', line 218 def migrate(shell) end |
#migrate! ⇒ true
Migrates the database used by the project.
428 429 430 |
# File 'lib/deployml/environment.rb', line 428 def migrate! invoke [:migrate] end |
#rake(task, *arguments) ⇒ true
Executes a Rake task on the destination server, in the destination directory.
132 133 134 135 136 137 138 139 |
# File 'lib/deployml/environment.rb', line 132 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.
500 501 502 |
# File 'lib/deployml/environment.rb', line 500 def redeploy! invoke [:update, :install, :migrate, :restart] end |
#remote_shell {|shell| ... } ⇒ Array<RemoteShell, LocalShell>
Creates a remote shell with the destination server.
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/deployml/environment.rb', line 95 def remote_shell(&block) each_dest.map do |dest| shell = if dest.scheme == 'file' LocalShell else RemoteShell end shell.new(dest,&block) end end |
#restart(shell) ⇒ Object
Place-holder method.
309 310 311 |
# File 'lib/deployml/environment.rb', line 309 def restart(shell) server_restart(shell) end |
#restart! ⇒ true
Restarts the Web server for the project.
476 477 478 |
# File 'lib/deployml/environment.rb', line 476 def restart! invoke [:restart] end |
#server_config(shell) ⇒ Object
Place-holder method.
229 230 |
# File 'lib/deployml/environment.rb', line 229 def server_config(shell) end |
#server_restart(shell) ⇒ Object
Place-holder method.
262 263 |
# File 'lib/deployml/environment.rb', line 262 def server_restart(shell) end |
#server_start(shell) ⇒ Object
Place-holder method.
240 241 |
# File 'lib/deployml/environment.rb', line 240 def server_start(shell) end |
#server_stop(shell) ⇒ Object
Place-holder method.
251 252 |
# File 'lib/deployml/environment.rb', line 251 def server_stop(shell) end |
#setup(shell) ⇒ Object
Sets up the deployment repository for the project.
167 168 169 170 171 172 173 |
# File 'lib/deployml/environment.rb', line 167 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.
392 393 394 |
# File 'lib/deployml/environment.rb', line 392 def setup! invoke [:setup] end |
#ssh(*arguments) ⇒ true
Starts an SSH session with the destination server.
151 152 153 154 155 156 157 |
# File 'lib/deployml/environment.rb', line 151 def ssh(*arguments) each_dest do |dest| RemoteShell.new(dest).ssh(*arguments) end return true end |
#start(shell) ⇒ Object
Place-holder method.
285 286 287 |
# File 'lib/deployml/environment.rb', line 285 def start(shell) server_start(shell) end |
#start! ⇒ true
Starts the Web server for the project.
452 453 454 |
# File 'lib/deployml/environment.rb', line 452 def start! invoke [:start] end |
#stop(shell) ⇒ Object
Place-holder method.
297 298 299 |
# File 'lib/deployml/environment.rb', line 297 def stop(shell) server_stop(shell) end |
#stop! ⇒ true
Stops the Web server for the project.
464 465 466 |
# File 'lib/deployml/environment.rb', line 464 def stop! invoke [:stop] end |
#update(shell) ⇒ Object
Updates the deployed repository for the project.
183 184 185 186 187 188 189 190 |
# File 'lib/deployml/environment.rb', line 183 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.
404 405 406 |
# File 'lib/deployml/environment.rb', line 404 def update! invoke [:update] end |