Skip to content

Commit

Permalink
Add support for maintenance mode. Bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
josephleniston committed Nov 9, 2015
1 parent df342db commit dc3da50
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 11 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog for easy-deployment

## 0.6.2 (2015-11-10)

Enhancements:

* Add support for maintenance mode using the `turnout` gem.

## 0.6.1 (2014-05-23)

Minor changes:

* Update reference data load to use the new rake task from `easy-reference` gem

## 0.6.0 (2013-11-05)

Features:
Expand All @@ -9,7 +21,7 @@ Features:

Bugfixes:

* Using builting `easy-reference` gem support now works with a custom bundler path if set.
* Using built-in `easy-reference` gem support now works with a custom bundler path if set.

## 0.5.3 (2013-09-05)

Expand Down
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,20 @@ The created backup configuration will be scheduled on deploy to run nightly via
The default setup is to backup the capistrano system folder, the configured database, to store the backup in S3, and notify of failures via email.
All these settings are configurable, to read more see the documentation for the backup gem https://github.com/meskyanichi/backup and setup your configuration to suit yourself.

### Whenever
### Maintenance

If you use the whenever gem to manage application crontabs, automatically include the capistrano
hooks to run whenever each deploy via:
This includes a generator to create a maintenance mode configuration (generator is run by itself as `rails generate easy:maintenace`)

This will generate:

config/initializers/maintenace.rb
public/maintenance.html
public/maintenance.json

Customise the site configuration within `config/initializers/maintenace.rb` to change the maintenance message, response status etc.
Customise the maintenance page within `public/maintenance.html`
All these settings are configurable, to read more see the documentation for the turnout gem https://github.com/biola/turnout and setup your configuration to suit yourself.

require "easy/deployment/whenever"

## Contributing

Expand Down
6 changes: 3 additions & 3 deletions easy-deployment.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
require File.expand_path('../lib/easy-deployment/version', __FILE__)

Gem::Specification.new do |gem|
gem.authors = ["Jeremy Olliver", "Nigel Ramsay", "Shevaun Coker", "Cameron Fowler"]
gem.email = ["[email protected]", "[email protected]", "[email protected]", "[email protected]"]
gem.authors = ["Jeremy Olliver", "Nigel Ramsay", "Shevaun Coker", "Cameron Fowler", "Joseph Leniston"]
gem.email = ["[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]"]
gem.description = %q{Easy deployment: includes a generator, and capistrano configuration}
gem.summary = %q{Gem for encapsulating Abletech's deployment practices}
gem.homepage = "https://github.com/AbleTech/easy-deployment"
Expand All @@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
gem.license = "GPLv3"

gem.add_runtime_dependency 'rails', '>= 3.0.0'
gem.add_runtime_dependency 'capistrano', '~> 2.13.5'
gem.add_runtime_dependency 'capistrano', '>= 2.15'

gem.add_development_dependency 'bundler'
gem.add_development_dependency 'rspec', '~> 2.0'
Expand Down
5 changes: 3 additions & 2 deletions lib/easy-deployment.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "easy-deployment/version"
require "easy/generators/generator_helpers"
require 'easy/generators/backup_generator'
require 'easy/generators/deployment_generator'
require "easy/generators/generator_helpers"
require 'easy/generators/maintenance_generator'
require 'easy/generators/stage_generator'
require 'easy/generators/backup_generator'
2 changes: 1 addition & 1 deletion lib/easy-deployment/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Easy
module Deployment
VERSION = "0.6.1"
VERSION = "0.6.2"
end
end
19 changes: 19 additions & 0 deletions lib/easy/deployment/maintenance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Define a capistrano task for putting the site into maintenance mode using
# turnout rack middleware.
# To load this capistrano configuration, require 'easy/deployment/maintenance' from deploy.rb
#
Capistrano::Configuration.instance(:must_exist).load do

namespace :maintenance do
desc "Put the application into maintenance mode"
task :start, :roles => :app do
run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec rake maintenance:start"
end

desc "Take the application out of maintenance mode"
task :end, :roles => :app do
run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec rake maintenance:end"
end
end

end
1 change: 1 addition & 0 deletions lib/easy/generators/backup_generator.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'rails/generators'
require "easy/generators/generator_helpers"

module Easy
class BackupGenerator < Rails::Generators::Base
Expand Down
1 change: 1 addition & 0 deletions lib/easy/generators/deployment_generator.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'rails/generators'
require "easy/generators/generator_helpers"

module Easy
class DeploymentGenerator < Rails::Generators::Base
Expand Down
28 changes: 28 additions & 0 deletions lib/easy/generators/maintenance_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'rails/generators'

module Easy
class MaintenanceGenerator < Rails::Generators::Base
source_root File.join(File.dirname(__FILE__), "templates") # Where templates are copied from

desc %{Generates a maintenance config to allow you to put your application into maintenance mode}

def create_maintenance_files
gem_group(:development) do
gem 'turnout', '~> 2.2'
end

template("maintenance.rb.tt", "config/initializers/maintenance.rb")
template("maintenance.html.tt", "public/maintenance.html")
template("maintenance.json.tt", "public/maintenance.json")

run("bundle install")

say("Maintenance configuration generated", :green)
say(" - TODO: edit config/maintenance.rb setting default_maintenance_page, default_reason and other configuration options", :green)
say(" - TODO: edit public/maintenance.html to match site styles", :green)

true
end

end
end
69 changes: 69 additions & 0 deletions lib/easy/generators/templates/maintenance.html.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Down for Maintenance</title>

<style type="text/css">

*{
font-family: Arial, Helvetica, sans-serif;
}

body{
margin: 0;
background-color: #fff;
}

#page{
position: relative;
width: 550px;
margin: 200px auto;
padding: 75px 0;
text-align: center;
background-color: #eaeaea;
border: solid 1px #ccc;
border-top: solid 10px #666;
-moz-box-shadow: inset 0 2px 10px #ccc;
-webkit-box-shadow: inset 0 2px 10px #ccc;
box-shadow: inset 0 2px 10px #ccc;
}

header, #body{
width: 400px;
margin: 0 auto;
}

h1{
margin: 0;
color: #CC3601;
font-size: 26pt;
border-bottom: solid 4px #666;
}

#reason{
margin: 10px 0;
color: #333;
}

</style>

</head>
<body>

<section id="page">

<header>
<h1>Down for Maintenance</h1>
</header>

<section id="body">
<div>
{{ reason }}
</div>
</section>

</section>

</body>
</html>
1 change: 1 addition & 0 deletions lib/easy/generators/templates/maintenance.json.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"error":"Service Unavailable","message":{{ reason }}}
18 changes: 18 additions & 0 deletions lib/easy/generators/templates/maintenance.rb.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Use this file to easily configure your app in maintenance mode. e.g. Override
# the default maintenance.html file with your own.
#
# See: https://github.com/biola/turnout#configuration for details on customization

# This is the rails root location, given this file is located at in Rails.root/config/maintenance.rb
rails_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))


Turnout.configure do |config|
config.app_root = rails_root
config.named_maintenance_file_paths = {default: config.app_root.join('tmp', 'maintenance.yml').to_s}
config.default_maintenance_page = Turnout::MaintenancePage::HTML
config.default_reason = "The site is temporarily down for maintenance.\nPlease check back soon."
config.default_allowed_paths = ['/admin','/assets']
config.default_response_code = 503
config.default_retry_after = 3600
end

0 comments on commit dc3da50

Please sign in to comment.