Geordi now has a script that runs capistrano with all known deploy targets (i.e. staging, production...).
Use with
geordi capistrano deploy:migrations
or
geordi capistrano deploy
The abbrevation geordi cap ...
works as well.
The way MySQL's FULLTEXT tokenizer splits text into word tokens might not always be what you need. E.g. it splits a word at period characters.
Since the tokenizer has near-zero configuration options (minimum word length and stopwords list), you need to hack it. There are three options available.
Write a Full-Text parser plugin in C.
Normaliz...
Our old solution for cronjobs, the "craken" plugin, is no longer maintained and does not work on Rails 3.2+.
We will instead use the whenever gem.
"Whenever" works just like "craken", by putting your rake tasks into the server's cron table. Everything seems to work just like we need it.
Add "whenever" to your Gemfile
:
group :deploy do
gem 'whenever', require: false
end
Add it to your config/deploy.rb
:
...
When deploying, Capistrano puts a REVISION
file into your application's release directory. It contains the hash of the commit which was deployed.
If you want to know the currently deployed release, simply SSH to a server and view that file.
$ cat /var/www/my-project/current/REVISION
cf8734ece3938fc67262ad5e0d4336f820689307
When your application is deployed to multiple servers, you probably want to see a result for all of them.
Here is a Capistrano task that checks all servers with the :app
role.
If you upgrade to the mysql2 gem, you will run into the problem that the server's database.yml (which is usually not under version control) needs to change exactly on deploy.
You can however make your database.yml work for mysql and mysql2 at the same time. Simpy do this
production:
adapter: <%= defined?(Mysql2) ? 'mysql2' : 'mysql' %>
#...
When using the asset pipeline your assets (images, javascripts, stylesheets, fonts) live in folders inside app
:
app/assets/fonts
app/assets/images
app/assets/javascripts
app/assets/stylesheets
With the asset pipeline, you can use the full power of Ruby to generate assets. E.g. you can have ERB tags in your Javascript. Or you can have an ERB template which generates Haml which generates HTML. You can chain as many preprocessors as you want.
When you deploy, Rails runs assets:precompile
...
deploy-to-production
now calls Capistrano with bundle exec
since we started to bundle Capistrano in all projects.
There is a conflict between current capistrano versions and the 2.5.1 net-ssh gem. Make sure you upgrade to 2.5.2, then it should work again.
Capistrano recently had some API changes that can results in deploys not working when running with old deploy.rb
files.
So let's bundle it. Put capistrano into your Gemfile, like this:
# Gemfile
group :deploy do
gem 'capistrano'
gem 'capistrano_colors'
end
It's possible you need to do a bundle update net-ssh
to get things running.
Now double check that all your custom hooks are actually still called. One candidate might be an after deploy:symlink
hook that has been renamed into `after deploy:creat...
I got these warnings while deploying a Rails 3.2 app with asset pipeline enabled:
*** [err :: host.tld] find: `/opt/www/hollyapp.com/releases/20120503115342/public/images': No such file or directory
*** [err :: host.tld] find: `/opt/www/hollyapp.com/releases/20120503115342/public/stylesheets': No such file or directory
*** [err :: host.tld] find: `/opt/www/hollyapp.com/releases/20120503115342/public/javascripts': No such file or directory
Folders like public/javascripts
might not exist if you're using the asset pipeline (...
Geordi, our collection of command line tools, has been extended by another command deploy-to-production
. This script encapsulates the following workflow:
bundle exec cap production deploy:migrations
The script will ask you for the names of your master branch, production branch an...
When trying to install the gherkin gem, you might encounter an error with the following lines:
ERROR: Error installing gherkin:
ERROR: Failed to build gem native extension.
...
checking for main() in -lc... yes
creating Makefile
...
cc1: all warnings being treated as errors
Makefile:150: recipe for target 'gherkin_lexer_ar.o' failed
make: *** [gherkin_lexer_ar.o] Error 1
...
If upgrading is not an option, configure build options for gherkin
:
bundle config --local build.gherkin --with-cflags=-w
Your .bundle/config
fi...
Note: This process is tailored to our specific needs and tools at makandra. While it will certainly not apply to all (especially larger teams), we think it is a helpful starting point. Compare also the Gatekeeping: Guide for gatekeeper card.
In order to reduce the number of rejects we get from clients, we want to review all code written before it goes to the staging server.
If your project manager wants to do gatekeeping o...
Note: This process is tailored to our specific needs and tools at makandra. While it will certainly not apply to all (especially larger teams), we think it is a helpful starting point.
In order to reduce the number of rejects we get from clients, we want to review all code written before it goes to the staging server.
If you're responsible for gatekeeping in a projects, this is what to do:
First, read the [Gatekeeping for developers](https://makandracards.com/makandra/6579-gatekeeping-guide-for-develope...
When deploying code with Capistrano (depending on your configuration) at some point Capistrano tries to check out code from your repository. In order to do so, Capistrano connects to your repository server from the application server you're deploying to with SSH. For this connection you can use two SSH keys:
~/.ssh/id_rsa
[default]If you prefer the second way, add this to deploy.rb:
ssh_options[:forwar...
Removing features and merging those changes back can be painful. Here is how it worked for me.\
tl;dr: Before merging back: reinstate reverted features in a temporary branch, then merge that branch.
Consider your team has been working on several features in a branch, made many changes over time and thus several commits for each feature.\
Now your client wants you to deploy while there are still stories that were rejected previously and can't be deployed.
...
Note: capistrano_colors
was merged into Capistrano starting from v2.13.5. However, this requires Ruby 1.9+.
If you cannot upgrade Capistrano to 2.13.5+ (e.g. because you're still running on Ruby 1.8), simply put capistrano_colors
into your Gemfile and require 'capistrano_colors'
in your config/deploy.rb
file.
If you get this error while deploy and you are sure the Gemfile.lock is in the version control check your releases directory.
This error can occur if someone/something copy a file or directory into your releases directory.
When you have a complex recipe setup with multistage deployment you may run into this error:
`role_list_from': unknown role `something' (ArgumentError)
Consider this task definition:
namespace :foo do
task :bar, :roles => :something do
# do crazy stuff
end
end
Whenever we call foo.bar
in our recipe, Capistrano will fail if you deploy to a stage where none of the servers has the role the error complains about, "something
" in this case.
However, you can [hack around it](http://groups.google.com/group/ca...
We forked craken today and fixed one of the issues we had with new (>0.8.7) rake versions.
The craken:install
rake task raised a "can't convert Hash into String" error e.g. while deploying with Capistrano.
If you have different users for different servers, don't use set :user
. Encode the username into the server definition instead:
server "username@servername.tld", :app, :web, :cron, :db, :primary => true
Whenever you deploy using Capistrano, a new folder is created within the releases directory on the remote server containing the application code.
By default Capistrano 3 keeps the last 5 releases in case you need to rollback to an older release. You can overwrite this setting by using
set :keep_releases, 3
Attached is a working config to deploy an application with Capistrano that needs to monitor Resque workers with God.
God will run as the deployment user, no need to register it as a system service.
Put this into your config/deploy.rb
:
namespace :god do
def god_is_running
!capture("#{god_command} status >/dev/null 2>/dev/null || echo 'not running'").start_with?('not running')
end
def god_command
...
This post is not about devops, it's not about lean startups, it's not about web scale, it's not about the cloud, and it's not about continuous deployment. This post is about you, the developer who's main purpose in life has always been to build great web applications. In a pretty traditional world you write code, you write tests for it, you deploy, and you go home. Until now.