Version 3?
Hey @leehambley, I was just wondering how we were looking for a version 3.0 release. I thought there used to be a version 3 branch but I no longer see it. Do you need any help?
@jfelchner I'd love some help, but the plans I had in mind are a little too infant, as v3, for me means a rewrite. Here's some of the ideas I had in mind:
Proper execution of your task independently on multiple hosts.
role :web, %w{10.0.1.1 10.0.1.2}
task :something, [:web] do |role, host|
log "Running #{roles} #{host}: something task"
end
Which would output:
Running web / 10.0.1.1
Running web / 10.0.1.2
(currently not possible due to the way cap handles forking)
And, moreover something like this:
role :web, %w{10.0.1.1 10.0.1.2}
task :something, [:web] do |role, host|
in current_working_directory
if Capistrano::Remote::File.exists? ( 'tmp/unicorn.pid' )
run "service unicorn start", as: 'root'
else
run 'service unicorn restart' as: 'root'
end
end
end
(I would assume that the tasks would be namespaced something like Capistrano::Remote::, so one can simply use File, and refer to a remote file, example above for clarity.)
The important thing to note now is that this is possible, but only with shell script, and the task block can't switch per-host, so conditional logic doesn't work for us.
To avoid reimplementing the whole standard library as ::Remote, I would imagine that just the stuff in the ::File class would be more than enough to do almost everything useful.
Something to set the environmental variables for the channel
A single SSH connection can contain multiple channels, any of these channels can have their environmental variables set:
set :default_environment, { path: '/usr/local/bin', rbenv_version: '1.9.3-p125' }
task :something, [:web] do |role, host|
puts capture('echo $PATH')
end
The important thing would be to notice with that, that we already have a similar feature in 2.x, but the generated command would look like: PATH=/usr/local/bin RBENV_VERSION=1.9.3-p125 echo $PATH, which is ugly. Setting this on the channel would be cleaner, however introduces a slight complication, for more see the underlying Net::SSH implementation documentation.
Some API for changing directory/env variables:*
task :something, [:web] do |role, host|
in current_working_dir
as :root do
run "kill -USR2 $(cat tmp/unicorn.pid)"
end
end
end
I see two major bonuses from this, one is that it's very expressive, and the other is that when it fails the error message could easily read: "The attempt to run kill -USR2 $(cat tmp/unicorn.pid) as root failed. (Exit status 1)", I imagine there's a bunch of these that could be done.
Prompt responders
This comes up time and time again, I'd love to be albe to do something like this:
prompt_for_sudo__password = Proc.new do
# Something here that responds to
# the request, asking the user, reading
# a file, or similar
end
task :restart, [:web] do |role, host|
respond_to /Password/, with: prompt_for_sudo_password
run "service unicorn restart", as: :root
end
end
Streaming IO logging/output.
I haven't properly thought this through yet, but MiniTest does this beautifully, they allow an output formatter to register for hooks when a suite, or test starts or finishes. This TestResult object is then passed to a handler, with a load of information about the test, the response status, etc, etc, etc.
This mechanism allows them to have progress output from dots, verbose output, no output, Growl output, etc, etc, etc. I imagine a world where there's capistrano/pride
Better encapsulation for being embeddable
There's a class, undocuemented mostly called Capistrano::CLI, which can be used to run Capistrano from within another program without shelling out, I'd like to build on this. (Then we could, for example allow rake deploy, and avoid filling people's PATH with junk), as well as better facilitating
Better callbacks, and hooks
This speaks to the Streaming IO above, but it would be perfectly possible to have the campfire/irc/email/growl/etc/etc hooks implemented as loggers, which pass everything through that they are not interested in, but record/log the things they are interested in.
No more top-level DSL
Until now in this (rather long) reply, I've been sticking with the existing DSL, but I'd like to throw that away and just use classes, and methods. A significant portion of the Capistrano codebase is dedicated to our DSL, which is Rake-ish, but confusingly incompatible. for example opening a task in Rake to redefine it actually augments the existing implementation in Capistrano that redefines it.
Thor springs to mind, first for this, but there's a couple of outstanding issues with the current release that preclude me betting on it just yet.
My hope would be to do something like this:
module Capistrano
module Remote
class DeploySuite
attr_reader :configuration
def initialize(configuration)
configuration = configuration
end
def deploy
check
start
update
finish
test
end
private
def check
on web_servers do |role, host|
Dir.create releases_directory unless File.exists? releases_directory
end
end
end
module Servers
class Unicorn
def finish
super
start_or_restart_unicorn
end
private
def start_or_restart_unicorn
# Notice method `on` maps almost to `task`
on web_servers, in: :sequence, wait: 5.seconds do |role, host|
File.exists?('tmp/unicorn.pid') ? restart_unicorn : start_unicorn
end
end
end
end
end
end
class MyDeploy < Capistrano::Remote::DeploySuite
include Capistrano::Remote::Servers::Unicorn
end
MyDeploy.new(config).deploy
There's a lot to take in there, but that's what I had in mind, and it would be a very convenient and comfortable DSL, and would make the way things work much cleaner, then capistrano would be reduced to a set of very helpful tasks for performing remote operations on groups of machines, plus a logging/streaming API that makes it perfectly suited to actually distribute a bunch of defaults that really make sense.
You'll notice the use of on, that's something I'd be quite excited about, because on _______, in: :sequence, wait: 5.seconds would make a whole range of probles go away, one can imagine a few run-modes that could be useful here.
This alternative API also speaks to me because conditionally one would be able to include a DryRun mixin, which would nullify the other tasks (perhaps by changing the namespace, so that dry-run implementations are actually found.
Take dry-run, and testing seriously
I mentioned it briefly in the previous section, but I'd really like to encourage that people start and test their deployments, and by switching to a pure ruby API, and making things much easier to undersatnd for the average rubyist, we should be able to get to a really, really nice position where you can stub/mock/test-for expectations on your tasks.
The dry-run feature is about as good as it gets right now, but it has it's flaws, it doesn't know what to do with capture, it wouldn't be able to support the conditional statements, and it's a bit of a ghetto.
As for testing, when they would be simple Ruby methods, using Ruby inheritance, etc - they would be much easier to test, and much more robust.
tl;dr
I have some really, really grand plans, and I'd like to start soon, but honestly I simply don't know where to start. I've patched libssh, to make it easier to write a better underlying SSH driver, when the time comes for that, if it comes to it, I believe that our TaskDefinition object in the current code base is almost good enough, and otherwise, I think most things have to be thrown away. (But, it is a major rewrite-right!)
My only pre-conditions are:
- Build for the best, target 1.9, and don't spare any effort to support 1.8 (I extend that to using the new syntaxes, etc (I'm open to negotiation if someone helps me build))
- Build with the best, MRI, with Minitest, and Bundler, and co - these tools are what people really expect to see, know how to use, and they're awesome.
- Integrate with Rails. I'm not a huge rails advocate, but a Railtie so you can do
rails g install capistranowould be really, really nice. - Have awesome integration tests. (I've spiked a test implementation using DaemonController of something that boots a chrooted
sshdin order to test against a real (chrooted) environment, this would allow for some really, really accurate integration tests, and would be a real asset to the project.)
@leehambley I'd love to get involved with this, I've got a lot of ideas that in a similar vein to what you've outlined above. I'll try to assemble them into something coherent and post back here
Same here Lee, I'm in the middle of some stuff right now but I definitely want to put a lot of effort into this.
@jfelchner, @seenmyfate and I have started discussing a significantly different API (but with the same project goals) - as the API is so, so different you can follow (and are welcome to join us) working at https://www.github.com/deployrb/deploy.
Capistrano as it stands right now is fairly well routed in Rails books, and Tutorials, whilst a v3 would be a clean break, I think the API is so significantly different that we're starting a new project. It might be that Capistrano v3 is a compatibility layer on top of that, or it might be that eventually deploy feels polished enoguh to be renamed back to Capistrano.
@leehambley I agree however I'd hate to see Capistrano (which has a good reputation) be relegated to an unmaintained project. :(
I've joined the conversation on deployrb and will close this issue. Can you migrate your initial reply here to Issue #1 on that project?
Looking forward to fleshing this out.
Done. ( https://github.com/deployrb/deploy/issues/1 )
On Thursday, March 15, 2012 at 8:13 AM, Jeff Felchner wrote:
@leehambley I agree however I'd hate to see Capistrano (which has a good reputation) be relegated to an unmaintained project. :(
I've joined the conversation on deployrb and will close this issue. Can you migrate your initial reply here to Issue #1 on that project?
Looking forward to fleshing this out.
Reply to this email directly or view it on GitHub: https://github.com/capistrano/capistrano/issues/171#issuecomment-4514909