Monday, April 2, 2012

Rbenv, chef and bundler

What we aim

We're trying to use rbenv in our infrastructure in order to achieve the following multiple goals:
  • Use the latest REE ruby runtime
  • Switch to Ruby 1.9 for chef
  • Prepare the migration to rails 3 and Ruby 1.9 for the main web application
So far, I've managed to install rbenv system wide on the servers using Riot Games excellent cookbook. A simple:
require_recipe "rbenv"
# Setup the rubies
PICOR_RUBY="ree-1.8.7-2012.02"
CHEF_RUBY="1.9.2-p318"
OPINL_RUBY="1.9.2-p318"

rbenv_ruby PICOR_RUBY
rbenv_ruby CHEF_RUBY
in a chef cookbook, automatically download and install these versions of Ruby in the system wide rbenv. Because I'm not ready to switch, I'm not yet setting up automatic rbenv switching:
# File "/home/apps/.rbenv-version" do
#   owner "apps"
#   group "apps"
#   backup false
#   content PICOR_RUBY
# end

# File "/root/.rbenv-version" do
#   owner "root"
#   group "root"
#   backup false
#   content CHEF_RUBY
# end
But this should go in action as soon as things works ok.

Next step, Gems

Because Bundle has some kind of memory, you should not use it to deploy gems from a given user if you plan to deploy another gemset in another environement with the SAME user later. At fotopedia, we use GEM_HOME and GEM_PATH to change gemset because it works and it's really simple (for binaries, we use a combination of symlinks in /usr/local/binand alternative selection provided by our Debian OS). So we actually install several gemset with the same user. The workaround to have bundler work correctly is to change its HOME when running. Ugly, but efficient:
script "Bundle picor gems" do
  interpreter "bash"
  user "root"
  cwd  "/tmp/"
  environment rbenv_as_hash
  code <<-EOS
# Discard previous forced state
rm -rf .bundle
export HOME=$PWD
export RBENV_VERSION=ree-1.8.7-2012.02
rbenv exec gem list bundler | grep 'bundler' || gem install bundler
cd /etc/bundler
rbenv exec bundle install --shebang ruby-local-exec --binstubs /usr/local/picorstubs
EOS
  action :nothing
end
This script is run when the Gemfile changes in /etc/bundler (our current location for the Picor gems). the gems chefs are installed almost the same way:
script "Bundle chef gems" do
  interpreter "bash"
  user "root"
  cwd "/root/"
  environment rbenv_as_hash
  code <<-EOS
export RBENV_VERSION=ree-1.8.7-2012.02
rbenv execgem list bundler | grep 'bundler' || rbenv exec  gem install bundler
# Use this because bundle in path is 1.8 bundle
rbenv exec bundle install --deployment --shebang ruby-local-exec --binstubs /usr/local/chefstubs
EOS
  action :nothing
end
Once this has run, /usr/local/picotstubs contains the picor binary stubs ready to be used and the chefstubs the one for chef. Next Step. Rewiring daemons to use one gemset according to what I need. Once the stubs are there, this might be straighforward...

Thursday, March 29, 2012

Bundler, oh, I hate thou

Another merry joke from my bundler friend. If you ever switch to deployment mode (using the bundle install --deployment command), do not come and cry if bundler starts staying:
Could not find gemname-version in any of the sources
When you have :
gem list
*** LOCAL GEMS ***
gemname (version)
Instead remove the lock

bundle install --no-deployment

And voilà.

Short post, but this issue made me mad for half an hour.

Wednesday, March 28, 2012

Blog Styling

This article describes the way I style things in this blog.

Blockquotes

 I use the following CSS styles for my blockquotes. Final result is:

Example of styled blockquote


blockquote{
  background:#f9f9f9;
  border-left:1em solid #eee;
  margin:1.5em 1em;
  padding:.5em 1em;
  quotes:"\201C""\201D";
  font: italic normal 12pt/1.2em Georgia;
}

blockquote:before{
  color:#808080;
  content:open-quote;
  font-size:4em;
  line-height:.1em;
  margin-right:.25em;
  vertical-align:-.4em;
}

blockquote :first-child{display:inline;}
blockquote :last-child{margin-bottom:0;}

Code block

For code blocks, I use the following style:

pre {
        border:1px dashed #E1E1E1;
        color:#333344;
        background:#FAFAFA;
        font-family:monospace;
        overflow:auto;
        font-size:11px;
        padding:0.5em;
}

A pinterest spammer talks

Very interesting article that show that Pinterest has still some way to do and can definitely be bankable more or less quickly. People like this guy are really innovating. All the more so as this is almost useful spam in the Pinterest galaxy.

http://www.dailydot.com/news/pinterest-steve-amazon-spammer-tells-all/
First week of doing this I made around $2,000

Wednesday, March 21, 2012

Les espaces insécables sous OSX

Hej,

J'ai lu hier l'article de Bruno Michel qui parle des espaces insécables pour les développeurs et je me suis rappelé de l'horreur qu'il y a à taper sous OSX, avec un clavier français les commandes suivantes:


ps aux | grep toto

En général, on relache les touches alt+shift un tout petit peu trop tard et le clavier OSX nous colle alors un joli espace insécable à la place de l'espace classique juste après le pipe :


ps auxw | grep window
zsh: command not found:  grep

C'est vraiment très embêtant et rageant, surtout quand on est pressé...

Pour contourner le problème, j'ai téléchargé Ukelele et j'ai modifié la méthode de saisie française pour que cette séquence de frappe génère une espace classique.

Et voilà: http://people.zoy.org/~oct/public/blogger/2012-03-21-French-no-bsp.bundle.zip

Pour installer cette chose, dézippez la quelque part sur votre Mac et copiez le répertoire .bundle dans votre ~/Library.

L'icône de la méthode de saisie vient de http://www.fasticon.com/ (j'aime bien ces petits bonhommes un peu ridicules).


Happy Coding !


Monday, March 12, 2012

Open-uri preventing redirects from https to http

Because it assumes it's insecure. That's quite annoying and should be configurable.




def OpenURI.redirectable?(uri1, uri2)
  true
end
This monkey-patch fixes the issue and remove the check.

A bug exists for the stdlib http://bugs.ruby-lang.org/issues/859 but fixes just the other way round.

Ruby-io-tail at version 0.0.3

The new version of ruby-io-tail will start to tail files from the end, and not from the first line available. This is useful to ensure no lines is sent twice to the Tailing application.

As usual, the gem is available from: https://rubygems.org/gems/io-tail