Skip to content

Rails engine to manage front end builds and deployments

License

Notifications You must be signed in to change notification settings

htdc/front_end_builds

 
 

Repository files navigation

Build Status Code Climate Gem Version

FrontEndBuilds

Front-End Builds lets you easily serve remotely-hosted static (JS) applications from your Rails apps.

Benefits:

Features:

  • Admin interface lets you easily view, rollback and activate different app versions

The motivation for this gem came from Luke Melia's RailsConf2014 talk.

Installation

Add this line to your application's Gemfile:

gem 'front_end_builds'

And then execute:

$ bundle

Front-End Builds brings some migrations along with it. To run, execute

rake front_end_builds:install:migrations

Usage

First, mount the admin interface in routes.rb:

Rails.application.routes.draw do

  mount FrontEndBuilds::Engine, at: '/frontends'

end

You should mount this under an authenticated route using your application's auth strategy, as anyone with access to the admin will be able to affect the production builds of your front end apps.a

If you don't want to set up an HTML auth strategy, you can do something like this:

# routes.rb
protected_app = Rack::Auth::Basic.new(FrontEndBuilds::Engine) do |username, password|
  username == 'admin' && password == (Rails.env.production? ? ENV['FEB_ADMIN_PASSWORD'] : '')
end
mount protected_app, at: '/frontends'

This will use basic HTTP auth to secure access to your admin ui. Just set the ENV variable, and use it to gain access.

Now, to create a new app, first add a front_end route pointing to your app in routes.rb:

Rails.application.routes.draw do

  front_end 'app-name', '/app-route'

end

Visit the admin (at whatever URL you mounted the engine above), create a new app named app-name, and you'll receive instructions on how to start pushing builds.

Note: If you're using this engine to serve an ember app at the Root, be sure to put all other Rails routes above the front_end route - as this take priority over all routes below it!

Rails.application.routes.draw do
  # All other Rails routes here

  front_end 'app-name', '/'
end

Configurations Options

Should you wish to allow deploys from an approved branch only, you may set the following environment variables

FRONT_END_BUILDS_RESTRICT_DEPLOYS=TRUE and set the approved branch FRONT_END_BUILDS_PRODUCTION_BRANCH=the_name_of_your_approved_branch

This can be troublesome if you're deploying from TravisCI as builds are always tagged HEAD, you can resolve this by adjusting your .travis.yml.

install:
- git checkout ${TRAVIS_BRANCH}

This basically just ensures that the branch name is available to ember-cli-front-end-builds to tag the deploy.

Development

Admin

The Admin interface is an Ember CLI app within feb. A distribution is kept within the gem, and must be updated whenever admin code is updated.

After changing the admin app, run

rake admin:build

to store a fresh distribution.

Running tests

# Rails tests
rspec

# Admin tests, from /admin dir
ember test

TODO

  • Create docs site
  • Auto live setting
  • make posts idempotent (i think they are), but dont insert a new row if it already exists.

About

Rails engine to manage front end builds and deployments

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 55.7%
  • JavaScript 26.1%
  • Handlebars 9.7%
  • HTML 5.8%
  • SCSS 2.2%
  • CSS 0.5%