2011-07-14 20:51:54 +00:00
|
|
|
# I have a penchant for setting up all my projects so they work the same.
|
|
|
|
|
|
|
|
I like to do these things in all my projects:
|
|
|
|
|
2012-07-05 13:52:02 +00:00
|
|
|
* Have all my tests run before committing. I don't like buying ice cream for the team on test failures, and setting up internal
|
|
|
|
CI for smaller projects is a pain.
|
2012-06-05 19:29:27 +00:00
|
|
|
* If I'm developing gems alongside this project, I use a `Gemfile.penchant` to get around the "one gem, one source" issue in
|
2011-07-14 20:51:54 +00:00
|
|
|
current versions of Bundler.
|
2012-06-21 19:15:19 +00:00
|
|
|
* I can also factor out and simplify a lot of my Gemfile settings.
|
2011-07-14 20:51:54 +00:00
|
|
|
* If I'm moving to different machines or (heaven forbid!) having other developers work on the project, I want to make
|
|
|
|
getting all those local gems as easy as possible.
|
|
|
|
|
|
|
|
This gem makes that easier!
|
|
|
|
|
|
|
|
## What's it do?
|
|
|
|
|
|
|
|
Installs a bunch of scripts into the `scripts` directory of your project:
|
|
|
|
|
2012-06-05 19:29:27 +00:00
|
|
|
* `gemfile` which switches between `Gemfile.penchant` environments
|
2011-07-14 20:51:54 +00:00
|
|
|
* `install-git-hooks` which will do just what it says
|
2012-04-20 15:12:56 +00:00
|
|
|
* `hooks`, several git hooks that the prior script symlinks into .git/hooks for you
|
2011-07-14 21:16:11 +00:00
|
|
|
* `initialize-environment`, which bootstraps your local environment so you can get up and running
|
|
|
|
|
2012-06-05 19:29:27 +00:00
|
|
|
## Gemfile.penchant?!
|
2011-07-14 20:51:54 +00:00
|
|
|
|
2012-06-05 19:29:27 +00:00
|
|
|
Yeah, it's a `Gemfile` with some extras:
|
2011-07-14 20:51:54 +00:00
|
|
|
|
2012-06-05 19:29:27 +00:00
|
|
|
``` ruby
|
2012-06-21 19:15:19 +00:00
|
|
|
# Gemfile.penchant
|
2012-06-05 19:29:27 +00:00
|
|
|
source :rubygems
|
|
|
|
|
|
|
|
gem 'rails', '3.2.3'
|
2012-06-06 15:28:55 +00:00
|
|
|
# expands to:
|
|
|
|
#
|
|
|
|
# gem 'rake'
|
|
|
|
# gem 'nokogiri'
|
|
|
|
# gem 'rack-rewrite'
|
2012-06-05 19:29:27 +00:00
|
|
|
gems 'rake', 'nokogiri', 'rack-rewrite'
|
|
|
|
|
|
|
|
no_deployment do
|
|
|
|
group :development, :test do
|
|
|
|
gem 'rspec', '~> 2.6.0'
|
2011-08-18 21:37:54 +00:00
|
|
|
|
2012-06-05 19:29:27 +00:00
|
|
|
dev_gems = %w{flowerbox guard-flowerbox}
|
2011-10-13 14:01:18 +00:00
|
|
|
|
2012-06-20 13:34:47 +00:00
|
|
|
# set up defaults for certain gems that are probably being used in envs
|
|
|
|
defaults_for dev_gems, :require => nil
|
|
|
|
|
2012-07-05 13:52:02 +00:00
|
|
|
# set up defaults for all gems in a particular environment
|
|
|
|
defaults_for env(:local), :path => '../%s' # the %s is the name of the gem
|
|
|
|
|
2012-06-05 19:29:27 +00:00
|
|
|
env :local do
|
2012-06-06 15:28:55 +00:00
|
|
|
# expands to:
|
|
|
|
#
|
2012-06-20 13:34:47 +00:00
|
|
|
# gem 'flowerbox', :path => '../flowerbox', :require => nil
|
|
|
|
# gem 'guard-flowerbox', :path => '../guard-flowerbox', :require => nil
|
2012-07-05 13:52:02 +00:00
|
|
|
gems dev_gems
|
2012-06-05 19:29:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
env :remote do
|
2012-06-06 15:28:55 +00:00
|
|
|
# expands to:
|
|
|
|
#
|
2012-06-20 13:34:47 +00:00
|
|
|
# gem 'flowerbox', :git => 'git://github.com/johnbintz/flowerbox.git', :require => nil
|
|
|
|
# gem 'guard-flowerbox', :git => 'git://github.com/johnbintz/guard-flowerbox.git', :require => nil
|
2012-06-05 19:29:27 +00:00
|
|
|
gems dev_gems, :git => 'git://github.com/johnbintz/%s.git'
|
|
|
|
end
|
2012-06-06 15:25:15 +00:00
|
|
|
|
2012-06-06 15:28:55 +00:00
|
|
|
# only expanded on Mac OS X
|
2012-06-06 15:25:15 +00:00
|
|
|
os :darwin do
|
|
|
|
gem 'rb-fsevent'
|
|
|
|
end
|
|
|
|
|
2012-06-06 15:28:55 +00:00
|
|
|
# only expanded on Linux
|
2012-06-06 15:25:15 +00:00
|
|
|
os :linux do
|
|
|
|
gems 'rb-inotify', 'ffi'
|
|
|
|
end
|
2012-06-05 19:29:27 +00:00
|
|
|
end
|
|
|
|
end
|
2011-07-14 20:54:38 +00:00
|
|
|
```
|
2011-07-14 20:51:54 +00:00
|
|
|
|
2011-08-18 21:39:59 +00:00
|
|
|
Use `script/gemfile local` to get at the local ones, and `script/gemfile remote` to get at the remote ones.
|
2011-07-14 20:51:54 +00:00
|
|
|
It then runs `bundle install`.
|
|
|
|
|
2012-07-05 13:52:02 +00:00
|
|
|
You can also run `penchant gemfile ENV`. Just straight `penchant gemfile` will rebuild the `Gemfile` from
|
|
|
|
`Gemfile.penchant` for whatever environment the `Gemfile` is currently using.
|
2011-08-18 21:37:54 +00:00
|
|
|
|
2011-10-13 14:01:18 +00:00
|
|
|
### Deployment mode
|
|
|
|
|
|
|
|
Use `no_deployment` blocks to indicate gems that shouldn't even appear in `Gemfiles` destined for
|
|
|
|
remote servers. *Very* helpful when you have OS-specific gems and are developing on one platform
|
2012-04-18 19:46:47 +00:00
|
|
|
and deploying on another, or if you don't want to deal with the dependencies for your testing
|
|
|
|
frameworks:
|
2011-10-13 14:01:18 +00:00
|
|
|
|
2012-06-05 19:29:27 +00:00
|
|
|
``` ruby
|
2012-07-05 13:52:02 +00:00
|
|
|
gem 'rails'
|
|
|
|
|
2012-06-05 19:29:27 +00:00
|
|
|
no_deployment do
|
2012-06-06 15:26:26 +00:00
|
|
|
os :darwin do
|
|
|
|
gems 'growl_notify', 'growl', 'rb-fsevent'
|
|
|
|
end
|
|
|
|
|
|
|
|
os :linux do
|
2011-10-13 14:01:18 +00:00
|
|
|
gem 'libnotify', :require => nil
|
|
|
|
end
|
2012-04-18 19:46:47 +00:00
|
|
|
|
|
|
|
group :test do
|
|
|
|
# ... all your testing libraries you won't need on the deployed end ...
|
|
|
|
end
|
2012-06-05 19:29:27 +00:00
|
|
|
end
|
2011-10-13 14:01:18 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Run `penchant gemfile ENV --deployment` to get this behavior. This is run by default when the
|
2012-04-18 19:46:47 +00:00
|
|
|
pre-commit git hook runs, but only after the default Rake task passes.
|
2011-10-13 14:01:18 +00:00
|
|
|
|
2012-06-21 19:15:19 +00:00
|
|
|
#### Won't this change the project dependencies?!
|
|
|
|
|
|
|
|
Probably not. You probably have the "main" gems in your project locked to a version of Rails or
|
|
|
|
Sinatra or something else, and all of the other gems for authentication, queue processing, etc. are
|
|
|
|
dependent on that framework. Ripping out your testing framework and deployment helpers really
|
|
|
|
shouldn't be changing the main versions of your application gems. It WORKSFORME and YMMV.
|
|
|
|
|
|
|
|
### Getting local gems all set up
|
|
|
|
|
|
|
|
`penchant bootstrap` will go through and find all git repo references in your `Gemfile.penchant` and
|
|
|
|
will download them to the specified directory (by default, '..'). This means blocks like this
|
|
|
|
will work as expected when you `penchant bootstrap` and then `penchant gemfile local`:
|
|
|
|
|
|
|
|
``` ruby
|
|
|
|
env :local do
|
|
|
|
gem 'my-gem', :path => '../%s'
|
|
|
|
end
|
|
|
|
|
|
|
|
env :remote do
|
|
|
|
gem 'my-gem', :git => 'git://github.com/johnbintz/%s.git'
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
2012-07-05 13:52:02 +00:00
|
|
|
Note that this just does a quick `git clone`, so if your project is already in there in a different state,
|
|
|
|
nothing "happens" except that git fails.
|
|
|
|
|
2011-09-09 18:41:16 +00:00
|
|
|
## initialize-environment
|
|
|
|
|
|
|
|
Get new developers up to speed fast! `script/initialize-environment` does the following when run:
|
|
|
|
|
2012-06-05 19:29:27 +00:00
|
|
|
* Check out any remote repos found in `Gemfile.penchant` to the same directory where your current project lives.
|
|
|
|
That way, you can have your `Gemfile.penchant` set up as above and everything works cleanly.
|
2011-09-09 18:41:16 +00:00
|
|
|
* Runs `script/gemfile remote` to set your project to using remote repositories.
|
|
|
|
* Runs `rake bootstrap` for the project if it exists.
|
|
|
|
|
2011-08-31 18:43:43 +00:00
|
|
|
### After-`gemfile` hooks?
|
|
|
|
|
|
|
|
Drop a file called `.penchant` in your project directory. It'll get executed every time you switch environments using
|
|
|
|
Penchant. I use it to tell my Hydra clients to sync and update their Gemfiles, too:
|
|
|
|
|
|
|
|
``` ruby
|
|
|
|
# rake knows if you need "bundle exec" or not.
|
|
|
|
|
|
|
|
rake "hydra:sync hydra:remote:bundle"
|
|
|
|
```
|
|
|
|
|
2011-08-18 21:37:54 +00:00
|
|
|
### What environment are you currently using in that Gemfile?
|
|
|
|
|
|
|
|
`head -n 1` that puppy, or `penchant gemfile-env`.
|
|
|
|
|
2011-07-14 20:51:54 +00:00
|
|
|
## git hook?!
|
|
|
|
|
2011-08-18 21:37:54 +00:00
|
|
|
It runs `penchant gemfile remote` then runs `bundle exec rake`. Make sure your default Rake task for the project runs your
|
|
|
|
tests and performs any other magic necessary before each commit. Your re-environmented Gemfile and Gemfile.lock will be added
|
|
|
|
to your commit if they've changed.
|
2011-07-14 20:51:54 +00:00
|
|
|
|
2012-04-20 15:12:56 +00:00
|
|
|
### Skipping all that Rake falderal?
|
|
|
|
|
2012-06-21 19:15:19 +00:00
|
|
|
Do it Travis CI style: stick `[ci skip]` in your commit message. That's why the meat of the git hooks resides in
|
2012-04-20 15:12:56 +00:00
|
|
|
`commit-msg` and not `pre-commit`: you need the commit message before you can determine if the tests should be run
|
|
|
|
based on the commit message. Weird, I know.
|
|
|
|
|
2011-07-14 20:51:54 +00:00
|
|
|
## How?!
|
|
|
|
|
2012-06-21 20:18:48 +00:00
|
|
|
* No RVM? `gem install penchant`
|
|
|
|
* RVM? `rvm gemset use global && gem install penchant && rvm gemset use default`
|
2011-07-14 20:51:54 +00:00
|
|
|
* `cd` to your project directory
|
2011-08-18 21:37:54 +00:00
|
|
|
|
|
|
|
And then one of the following:
|
|
|
|
|
|
|
|
* `penchant install` for a new project (`--dir=WHEREVER` will install the scripts to a directory other than `$PWD/scripts`)
|
2012-04-20 15:12:56 +00:00
|
|
|
* `penchant update` to update the installation (`--dir=WHEVEVER` works here, too)
|
2011-08-18 21:37:54 +00:00
|
|
|
* `penchant convert` for an existing project (`--dir=WHEVEVER` works here, too)
|
2011-07-14 20:51:54 +00:00
|
|
|
|