Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Intermediate Capistrano

2,788 views

Published on

A talk I gave at North West Ruby User's Group (http://nwrug.org/) August 20th 2009

Published in: Technology
  • Be the first to comment

Intermediate Capistrano

  1. 1. Capistrano at your command Tips and tricks, from wimp to winner Lee Hambley - August 20th 2009 1
  2. 2. What’s on the menu? ✤ Capistrano’s Structure ✤ Net::SSH ✤ The Scope of Execution ✤ Task chaining; your own multi-stage ✤ Streams ✤ Prompts 2
  3. 3. Simply put, Capistrano is a tool for automating tasks on one or more remote servers. It executes commands in parallel on all targeted machines, and provides a mechanism for rolling back Capistrano changes across multiple machines. It is ideal for anyone doing any kind of system administration, either professionally or incidentally. What’s in the Box? Net::SSH Net::SFTP Net::SCP Net::SSH::Gateway $ gem dependency capistrano Gem capistrano-2.5.8 Capistrano’s Structure net-ssh (>= 2.0.10, runtime) net-sftp (>= 2.0.0, runtime) net-scp (>= 1.0.0, runtime) net-ssh-gateway (>= 1.0.0, runtime) 3
  4. 4. Simply put, Capistrano is a tool for automating tasks on one or more remote servers. It executes commands in parallel on all targeted machines, and provides a mechanism for rolling back Capistrano changes across multiple machines. It is ideal for anyone doing any kind of system administration, either professionally or incidentally. What’s in the Box? ✤ Consistent support for different source control software. Net::SSH Net::SFTP Net::SCP Net::SSH::Gateway $ gem dependency capistrano Gem capistrano-2.5.8 Capistrano’s Structure net-ssh (>= 2.0.10, runtime) net-sftp (>= 2.0.0, runtime) net-scp (>= 1.0.0, runtime) net-ssh-gateway (>= 1.0.0, runtime) 3
  5. 5. Simply put, Capistrano is a tool for automating tasks on one or more remote servers. It executes commands in parallel on all targeted machines, and provides a mechanism for rolling back Capistrano changes across multiple machines. It is ideal for anyone doing any kind of system administration, either professionally or incidentally. What’s in the Box? ✤ Consistent support for different source control software. Net::SSH Net::SFTP Net::SCP ✤ Rake-esque task definitions, including before/after callbacks for method chaining. Net::SSH::Gateway $ gem dependency capistrano Gem capistrano-2.5.8 Capistrano’s Structure net-ssh (>= 2.0.10, runtime) net-sftp (>= 2.0.0, runtime) net-scp (>= 1.0.0, runtime) net-ssh-gateway (>= 1.0.0, runtime) 3
  6. 6. Simply put, Capistrano is a tool for automating tasks on one or more remote servers. It executes commands in parallel on all targeted machines, and provides a mechanism for rolling back Capistrano changes across multiple machines. It is ideal for anyone doing any kind of system administration, either professionally or incidentally. What’s in the Box? ✤ Consistent support for different source control software. Net::SSH Net::SFTP Net::SCP ✤ Rake-esque task definitions, including before/after callbacks for method chaining. Net::SSH::Gateway ✤ Ability to detect and rollback broken jobs using transactions $ gem dependency capistrano Gem capistrano-2.5.8 Capistrano’s Structure net-ssh (>= 2.0.10, runtime) net-sftp (>= 2.0.0, runtime) net-scp (>= 1.0.0, runtime) net-ssh-gateway (>= 1.0.0, runtime) 3
  7. 7. Simply put, Capistrano is a tool for automating tasks on one or more remote servers. It executes commands in parallel on all targeted machines, and provides a mechanism for rolling back Capistrano changes across multiple machines. It is ideal for anyone doing any kind of system administration, either professionally or incidentally. What’s in the Box? ✤ Consistent support for different source control software. Net::SSH Net::SFTP Net::SCP ✤ Rake-esque task definitions, including before/after callbacks for method chaining. Net::SSH::Gateway ✤ Ability to detect and rollback broken jobs using transactions ✤ Roles, :app, :web, :db & :define-your-own $ gem dependency capistrano Gem capistrano-2.5.8 Capistrano’s Structure net-ssh (>= 2.0.10, runtime) net-sftp (>= 2.0.0, runtime) net-scp (>= 1.0.0, runtime) net-ssh-gateway (>= 1.0.0, runtime) 3
  8. 8. Net::SSH ✤ Magical pure-Ruby implementation of the SSH protocol. ✤ Honours your ~/ssh/config settings. ✤ Supports (creating and using) Tunnels, Gateways, Agent Forwarding and more... ✤ Super clean syntax...
  9. 9. Net::SSH ✤ Magical pure-Ruby implementation of the SSH protocol. ✤ Honours your ~/ssh/config settings. ✤ Supports (creating and using) Tunnels, Gateways, Agent Forwarding and more... ✤ Super clean syntax...
  10. 10. Net::SSH ✤ Magical pure-Ruby implementation of the SSH protocol. ✤ Honours your ~/ssh/config settings. ✤ Supports (creating and using) Tunnels, Gateways, Agent Forwarding and more... ✤ Super clean syntax...
  11. 11. The Scope of Execution ✤ What runs where? ✤ What permissions will I need? ✤ Obscure errors about permissions? ✤ .. lots of different things happening
  12. 12. The Scope of Execution $ → cap deploy Calling another Capistrano task. * executing `deploy' * executing `deploy:update' Transactions, you can define what to do for your own transactions if a task within it fails. ** transaction: start { * executing `deploy:update_code' A shell command run on your workstation. executing locally: "git ls-remote git@github.com:leehambley/ capistrano-website.git HEAD" A shell command run remotely. * executing "git clone -q git@github.com:leehambley/capistrano- website.git /u/apps/capistrano-website/releases/20090820114515 && ...... " { * executing `deploy:finalize_update' A shell command run remotely, connecting to your repository server. † * executing "chmod -R g+w /u/apps/capistrano-website/releases/ 20090820114515" { * executing `deploy:symlink' * executing "rm -f /u/apps/capistrano-website/current && ln -s /u/apps/ capistrano-website/releases/20090820114515 /u/apps/capistrano-website/ current" ** transaction: commit † Requires passwordless access to your repository server from your servers; this can be either keys (GitHub deploy keys feature) or SSH agent forwarding to provide your own key by proxy
  13. 13. Task Chaining ➊ ➋ ➌ $ rake db:migrate spec features
  14. 14. Task Chaining ➊ ➋ ➌ $ rake db:migrate spec features ➊ ➋ $ cap check-ruby-version deploy
  15. 15. Task Chaining ➊ ➋ ➌ $ rake db:migrate spec features ----------------- ➊ ➋ $ cap check-ruby-version deploy
  16. 16. Task Chaining ➊ ➋ ➌ $ rake db:migrate spec features ----------------- ➊ ➋ $ cap check-ruby-version deploy capture Executes a command on a single host and returns ("captures") the output as a string. stream Very similar to run, but optimised for displaying live streams of text (like tailed log files) from multiple hosts. run Execute commands on one or more servers
  17. 17. Task Chaining ➊ ➋ ➌ $ rake db:migrate spec features ----------------- ➊ ➋ $ cap check-ruby-version deploy ➊ ➋ ➌ $ cap staging check-ruby-version deploy capture Executes a command on a single host and returns ("captures") the output as a string. stream Very similar to run, but optimised for displaying live streams of text (like tailed log files) from multiple hosts. run Execute commands on one or more servers
  18. 18. Task Chaining ➊ ➋ ➌ $ rake db:migrate spec features ----------------- ➊ ➋ $ cap check-ruby-version deploy ➊ ➋ ➌ $ cap staging check-ruby-version deploy capture Executes a command on a single host and returns ("captures") the output as a string. stream Very similar to run, but optimised for displaying live streams of text (like tailed log files) from multiple hosts. run Execute commands on one or more servers
  19. 19. Streams? In Unix and Unix-like operating systems, as well as certain programming language interfaces, the standard streams are pre-connected input and output channels between a computer program and its environment (typically a text terminal) when it begins execution. The three I/O connections are called standard input, standard output and standard error.
  20. 20. Streams? In Unix and Unix-like operating systems, as well as certain programming language interfaces, the standard streams are pre-connected input and output channels between a computer program and its environment (typically a text terminal) when it begins execution. The three I/O connections are called standard input, standard output and standard error.
  21. 21. Streams? In Unix and Unix-like operating systems, as well as certain programming language interfaces, the standard streams are pre-connected input and output channels between a computer program and its environment (typically a text terminal) when it begins execution. The three I/O connections are called standard input, standard output and standard error.
  22. 22. Prompts Implementation
  23. 23. Prompts Implementation
  24. 24. Prompts Implementation
  25. 25. Resources ✤ Capistrano Wiki: - http://www.capify.org/ ✤ Bash Hackers Wiki: - http://bash-hackers.org/wiki/ ✤ Questions: - lee.hambley@gmail.com ✤ Support: - irc://freenode.org/capistrano ✤ Mailing List: - http://groups.google.com/group/capistrano 10
  26. 26. Questions?

×