How can I continue to use Accurev with Capistrano 3? - ruby-on-rails

We use AccuRev (and I cannot change that) and have been deploying with Capistrano 2. I need to upgrade to Capistrano 3, but it seems that the Accurev SCM module has been removed. Is there a way I can continue to use AccuRev and deploy with Capistrano 3?
deploy.rb piece
set :scm, :accurev
Deployment error
cap aborted!
LoadError: cannot load such file -- capistrano/accurev.rb

As Capistrano3 documentation says - there is only git, hg and svn support.
But it should not be so hard to port old accurev module from Capistrano 2 to Capistrano 3. Some classes changed but core is same - functions have to return proper commands with proper parameters.
You can start from git implementation from master and replace it with AccuRev.

The workaround I am using since one year is the following:
1- Edit the file capistrano-3.3.5/lib/capistrano/setup.rb and replace
load "capistrano/#{fetch(:scm)}.rb"
by
load "#{fetch(:scm_path, 'capistrano')}/#{fetch(:scm)}.rb"
2- Add in your config/deploy.rb file
set :scm_path, 'path/to/accurev/directory'
That will give to capistrano a chance to open the configuration schema of accurev. Note that capistrano v3 changed its syntax, and you may have to modify accurev files (I suggest then to duplicate them in your lib folder).
It's ugly to edit the gem file content directly, but there is no other way here. You can also fork their git and do the modification on your fork if you like.
I have a similar problem because I am using custom-made scm in capistrano. Tried to get them to accept a pull request to add this scm_path configuration option since last year but they refuse, saying that they will migrate to something better soon ...

Related

Capistrano 3 not updating the releases

I am using Capistrano 3 to deploy my app to the production server.
My server has system wide install of rvm. There is nothing extra ordinary about the deploy script.
However when i run cap production deploy The deploy script gives out successful messages and seems that deploy went without a problem.
However when I check the latest release folder is not updated and only the repo folder is updated.
This was supposed to be much easier while using Capistrano 2. But the respective commands to create symlinks etc all are shown to be passed in the console log while depoying while in the server nothing is being done.
Am I missing something about the capistrano 3 changes.
Ask if you need more information.
Capistrano 3 changed the symlink task, if you overrode it or called it specifically like deploy:create_symlink, you may want to audit your code.

Conditionally disable asset precompile in Capistrano

I've seen various convoluted and generally ineffective solutions to performing lazy asset precompile in Rails. As a backend developer I don't particularly want to recompile assets I never touch every time the program deploys, but because assets are loaded in Capfile via load 'deploy/assets', and not by defining a task in deploy.rb, I can't think of a way to conditionally disable it.
The behaviour I'm after is to use cap deploy for regular with-precompile deployment, and to use cap deploy:no_assets to skip asset deployment.
Both turbo-sporocket-rails and the that auto-skip scripts have some pitfalls (I will mention later). So I use the following hack, so I can pass a parameter to skip asset pre-compile at my will:
callback = callbacks[:after].find{|c| c.source == "deploy:assets:precompile" }
callbacks[:after].delete(callback)
after 'deploy:update_code', 'deploy:assets:precompile' unless fetch(:skip_assets, false)
This script will change the built-in asset-precompile hook, so it will be hooked based on the skip_assets parameter. I can call cap deploy -S skip_assets=true to skip asset precompile as a whole.
For me, turbo-sporocket-rails still takes minutes to do the checking when nothing has changed. This can be crucial when I need to push a fix to the server asap. Therefore I need my force-skipping method.
rails4 addresses this issue with it's new version of sprockets, by only precompiling assets that have changed. In the mean time, for your rails3 apps I recommend the turbo-sprockets-rails3 gem.
This gem started out as a set of patches for sprockets-rails by Nathan Broadbent, which were not merged into master because the problem was already addressed in rails4. From the README:
Speeds up your Rails 3 rake assets:precompile by only recompiling changed assets, based on a hash of their source files
Only compiles once to generate both fingerprinted and non-fingerprinted assets
And:
turbo-sprockets-rails3 should work out of the box with the latest version of Capistrano.
I can confirm that it works well for me on rails-3.2.x apps deploying with Capistrano.
As a side note for GitHubbers, the original pull request is an excellent example of how to submit code to an open source project, even if it wasn't merged.
This gist looks very promising https://gist.github.com/3072362
It checks your git log from the last deploy to now to see if there are any changes in %w(app/assets lib/assets vendor/assets Gemfile.lock config/routes.rb) and if so, only precompiles then.

How do I send a variable between Capistrano and Rails?

I have a Rails app deployed with Capistrano and in our Acceptance environment I want to set the page title to include the branch that is currently deployed.
The branch is set on deploy via Capistrano and I'd like to migrate that info from Cap to Rails somehow.
Obviously I can get Cap to write the branch name out to a file and read it back in Rails, but I'm hoping there's a better solution.
I've tried a couple experiments with setting default_environment but that hasn't seemed to work I'm assuming because those environment variables are only present in the shells that Capistrano creates.
Any suggestions?
Obviously I can get Cap to write the
branch name out to a file and read it
back in Rails
That's the best way, IMO
Here's a way that doesn't even need Capistrano, though it does need git. Read the branch name by capturing the output from running a git command in a Rails initializer:
# config/initializers/set_title.rb
module MyConfig
TITLE = `git symbolic-ref HEAD`.chomp.split("/").last
end
Then just refer to the constant in your template:
<title><%= MyConfig::TITLE %></title>

Subversion gem to track commit history in Ruby on rails app

Currently I'm doing research for a custom build deployment application on a unix system. I've also looked at Capistrano so don't worry ;). I'm looking for a gem that can give me the (subversion) commit stream of several projects. I'd like to run some tests with it to determine if it's possible/necessary to build a custom made deployment application.
Thanks
Take a look at the following URL :
http://www.oneofthewolves.com/2007/03/06/ruby-subversion-bindings-finally-some-documentation/

Rails 3 generator's git option?

In rails 2.x I could pass on a --git option to ./script/generate to add files to git automatically after creation. However I have been unable to find such an option (or configuration) in Rails 3.0.
Has this been removed or am I missing something? I tried researching this for a while but I am unable to find any reference.
Thanks,
Prateek
It doesn't have an option like that, although the standard 'rails new' command does generate the .gitignore and .gitkeep files for you.
Otherwise, I think you need to set up the git project yourself.

Resources