Awesome
RevisionPlate
Rack application and middleware that serves endpoint returns application's REVISION
.
Detail
The endpoint returns content of REVISION
Content of the endpoint wouldn't be changed even if REVISION
file has changed. But it'll return 404 when it has removed.
This can be used for health check + remove from service by hand.
This gem is used in Cookpad. And seems several companies runs similar thing (e.g. GitHub).
Usage
typical Rails app
# Gemfile
gem 'revision_plate', require: 'revision_plate/rails'
then your Rails application will handle /site/sha
.
rack application
# Gemfile
gem 'revision_plate'
# config.ru (middleware)
use RevisionPlate::Middleware, '/site/sha', "#{__dir__}/REVISION"
# config.ru (mount)
map '/site/sha' do
run RevisionPlate::App.new("#{__dir__}/REVISION")
end
Test
$ echo 'deadbeef' > REVISION
$ (... start your app ...)
$ curl localhost:3000/site/sha
deadbeef
$ rm REVISION
$ curl localhost:3000/site/sha
REVISION_FILE_REMOVED
Advanced
I want to customize (Rails app)
remove require: 'revision_plate/rails'
from Gemfile, then initialize RevisionPlate::App
on routes:
# routes.rb
get '/site/sha' => RevisionPlate::App.new
get '/site/sha' => RevisionPlate::App.new("/path/to/my/favorite/REVISION")
Development
Testing
$ rake test
License
MIT License