Simple Rack middleware to expose the app revision via an HTTP header.
Add infinum_app_revision to your gemfile:
# Gemfile
gem 'infinum_app_revision'or run
bundle add infinum_app_revisionBy default the middleware sets the X-App-Revision header on every HTTP response. You can plug it into any Rack app (including Rails) and choose how the revision is determined via a version provider.
require 'rack'
require 'infinum_app_revision'
# Choose a version provider (see options below)
version_provider = InfinumAppRevision::VersionProvider::Docker.new
use InfinumAppRevision::Middleware, version_provider: version_provider
run ->(_env) { [200, { 'Content-Type' => 'text/plain' }, ['OK']] }Add to your middleware stack (e.g., in config/application.rb or an environment file):
# config/application.rb
require 'infinum_app_revision'
module YourApp
class Application < Rails::Application
# ...
config.middleware.use InfinumAppRevision::Middleware,
version_provider: InfinumAppRevision::VersionProvider::Docker.new
end
end-
Docker (default example): reads a JSON file (defaults to
private/version.json) containing the revision and optional metadata.Default path can be overridden:
InfinumAppRevision::VersionProvider::Docker.new( version_file_path: 'path/to/version.json' )
Expected file format:
{ "revision": "abc1234", "build_time": "2025-11-09T12:34:56Z", "branch": "main" }Write this file during the container image build.
-
Mina: reads the revision from a
.mina_git_revisionfile at the project root.InfinumAppRevision::VersionProvider::Mina.new
Write the file during deploy, for example:
git rev-parse --short HEAD > .mina_git_revisionIf you're using mina to deploy your app then it should already create this file automatically.
-
Base (fallback): if you don’t pass a provider, the base provider will yield
"undefined"as the revision.
Change the response header name if needed:
use InfinumAppRevision::Middleware,
header: 'X-Revision',
version_provider: InfinumAppRevision::VersionProvider::Docker.newWe believe that the community can help us improve and build better a product. Please refer to our contributing guide to learn about the types of contributions we accept and the process for submitting them.
To ensure that our community remains respectful and professional, we defined a code of conduct that we expect all contributors to follow.
We appreciate your interest and look forward to your contributions.
After checking out the repo, run bin/setup to install dependencies. Then, run bundle exec rspec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.
Copyright 2024 Infinum
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Maintained and sponsored by Infinum.