jump to navigation

Run a single cookbook recipe with chef-solo November 25, 2009

Posted by John Dewey in Chef, Code, Example, Rake.
1 comment so far

I generally build my systems with chef-solo cookbooks. I do not want to maintain a central server for recipes. However, I’m getting to the point where I’d like to share my cookbooks from one solo project to another. Anyways, I
wanted to run an individual recipe of a given cookbook. The following gist allows for this. Although, it may not be necessary, since cookbooks are generally idempotent. Seemed like a good idea earlier in the evening, meh.

http://gist.github.com/242526

Syncing bundle_fu assets to s3 for Cloudfront April 2, 2009

Posted by John Dewey in Amazon, CDN, Rake, Vlad.
1 comment so far

I wanted to automatically upload my bundle_fu assets to Amazon’s s3, and use their Cloudfront CDN for SnGs. I came up with the following rake task, which can be hooked into Vlad.

It’s as simple as adding the following to production.rb, and running the rake task ‘cloud:upload’.

ActionController::Base.asset_host = "cloudfront_url"

Find missing RSpec view tests March 16, 2009

Posted by John Dewey in Code, Rake, RSpec.
2 comments

I created a quick little rake task which finds missing RSpec view tests. It assumes the extension is .haml, however, this can be overridden with the EXTENSION environment variable.

rake spec:missing_view_templates
or
EXTENSION=erb rake spec:missing_view_templates 

using geminstaller with vlad the deployer February 28, 2009

Posted by John Dewey in Configuration, Deployment, Example, Rake, Vlad.
1 comment so far

I really really really like vlad the deployer. I recently switched my apps over to geminstaller vs Rails’ config.gem.

This gist adds in geminstaller functionality to vlad’s update task.

Simple_admin met a Pieman November 7, 2008

Posted by dougmcinnes in Code, Plugins & Gems, Rails, Rake, Ruby.
Tags: , , , , ,
3 comments

Simple_admin is a Ruby on Rails plugin I created at the Los Angeles Times that morphed into a collabrative effort between Dewey, Reid and myself as it traveled between projects and functionality was added.  I’ve just released it to our latimes github account: http://github.com/latimes/simple_admin/tree/master

The basic premise is to give a simple way of managing login usernames and passwords without a database.  The data is stored in a YAML file in the application with the passwords encrypted by String’s crypt() method.

To add users to the file there’s an included rake task: admin:add_user.  The username and password are passed as parameters:

rake admin:add_user username=mrwalrus password=mahbukkit

Rake will append the user to the login.yaml file or create a new one.  The default location for this file is config/admin/login.yml but can be overridden by setting the LOGIN_FILE environment variable in your application.  If you set the LOGIN_FILE differently in your different rails environment files you can have different usernames and passwords for development and production.

There’s also a rake task for adding multiple users at the same time from a text file list, giving them all random passwords.

To get the plugin to actually use Basic HTTP authentication to ask for usernames and passwords add this to your application controller:

include SimpleAdmin
before_filter :check_basic_http_credentials

Like all filters you can add conditions:

before_filter :check_basic_http_credentials, :only => :login

When including SimpleAdmin in your controller you also get access to the authenticate(username, password) method which can be used for custom login pages.  For example:

def login
  if authenticate(params[:username], params[:password])
    session[:admin] = true
    redirect_to main_page
  end
end

Also included in the plugin is some code for marking different servers as “admin” servers and a way for a rails application to check to see if he’s an admin or not and change its behavior.  We used this on one application running on multiple boxes so we could turn off page caching on the admin-marked boxes so the administration WYSIWYG pages wouldn’t be cached and sent to non-admin users (that would be a big oops).

memcache ruby 1.8.5 problems August 14, 2008

Posted by John Dewey in Memcached, Rails, Rake, Ruby, Solaris.
1 comment so far

We have some boxes at Joyent and for one reason or another, they are still on 1.8.5. We memcached an expensive Solr query, but ran into intermittent 500 errors.

Look at the odd stacktrace, with references to rake. Anyways, long story short – an upgrade to 1.8.6 fixed the problem. Yeah Yeah Yeah, I know — bad us — we should have upgraded long ago.

ActionView::TemplateError (wrong number of arguments (1 for 2))
on line #15 of topics/_search_result.html.erb:

View the pastie

Rails Cron — Craken July 18, 2008

Posted by John Dewey in Capistrano, Code, Command Line, Configuration, Rails, Rake, Ruby.
Tags:
1 comment so far

My good buddy Doug Mciness wrote a rake task to manage and install cronjobs. We have it hooked into our Capistrano deployments, which allows for uber simple cron management. I added a few modifications such as, erb’ed raketab templates, and global/system specific crontabs.

It’s up on GitHubhttp://github.com/latimes/craken/tree/master

In the process of determining if these rakefiles should be yaml instead, would probably be the “more railsy rails way” of doing it.

Giles Bowkett gets props for the groovy name, and improved SEO of this post!

Run Rake Tasks with Delayed Job February 25, 2008

Posted by John Dewey in Code, Delayed::Job, Example, Rails, Rake.
1 comment so far

We needed to execute a Rake Task in the background, when a particular event occurred in Rails.  We decided to give Delayed::Job aka DJ a shot.  This “decorator” will execute a Rake task, while optionally passing ENV variables to the task.

Execute a Rake task from another task February 18, 2008

Posted by John Dewey in Example, Rake, Ruby.
3 comments

Executing a Rake task from inside another Rake task is a nice addition to your toolshed.  Passing parameters to the Rake task is even cooler.  ‘Rake::Task[“TaskName”].execute’ and ‘Rake::Task[“TaskName”].invoke‘ to the rescue.  A Rakefile that demonstrates the execution of a task with parameter passing.

Rake tasks :through Capistrano January 27, 2008

Posted by John Dewey in Capistrano, Example, Rake.
1 comment so far

Executing Rake tasks on host(s) through Capistrano is nothing new, and there are quite a few ways to do it. Some of the configurations out there, use a common Capistrano task to execute all Rake tasks. This works quite well, but you run into problems when scoping tasks to specific roles. The common Rake exec task is not scoped to a specific role (because it could run any task on any given role), so if you call it from a Cap task scoped to :db, it will still execute across all roles.

This was corrected by creating a Rake exec method instead of a Cap task. The method can pass any arbitrary variables and/or Rakefile to Rake.An example Capistrano task, displays it’s usage. There are a few Cap variables already set, such as rake and rails_env. Using the rakefile variable allows the execution of a specific Rakefile, which comes in handy when wanting to ignore the Rails Rakefile.

Why ignore the Rails Rakefile? In our configuration the Rakefile loads environment.rb, which sets the load_paths to our custom rubygems path – that means loading Rails! What happens when Rails is not installed, and you need a bootstrap task. The ability to pass in a Rakefile all of the sudden becomes useful.