diff --git a/.gitignore b/.gitignore index 0c2dc74..d87d4be 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,17 @@ *.gem +*.rbc .bundle -.DS_Store +.config +.yardoc Gemfile.lock -pkg/* +InstalledFiles +_yardoc coverage +doc/ +lib/bundler/man +pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..5f16476 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--format progress diff --git a/Gemfile b/Gemfile index 5c5f2b5..5422f8d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source "http://rubygems.org" +source 'https://rubygems.org' -# Specify your gem's dependencies in the .gemspec +# Specify your gem's dependencies in easy-deployment.gemspec gemspec diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f377084 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2012 Able Technology + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..9c44e86 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# Easy::Deployment + +This gem is for encapsulating Abletech's common deployment patterns using capistrano. + +## Installation + +Add this line to your application's Gemfile: + + gem 'easy-deployment', :git => "git@github.com:AbleTech/easy-deployment.git" + +And then execute: + + $ bundle + +Or install it yourself as: + + $ gem install easy-deployment + +## Usage + +Run: + + $ rails g easy:deployment + +## Contributing + +1. Fork it +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Added some feature'`) +4. Push to the branch (`git push origin my-new-feature`) +5. Create new Pull Request diff --git a/README.rdoc b/README.rdoc deleted file mode 100644 index 3ebdb61..0000000 --- a/README.rdoc +++ /dev/null @@ -1,14 +0,0 @@ -= Abletech/Deployment - -This gem is for encapsulating Abletech's common deployment patterns using capistrano. - -== Installation - -# Gemfile - - gem 'abletech-deployment', :git => "git@git.abletech.co.nz:/var/git/abletech/abletech-deployment.git" - -Then run: - - $ bundle install - $ rails g abletech:deployment diff --git a/Rakefile b/Rakefile index 858d4cc..1e00cec 100644 --- a/Rakefile +++ b/Rakefile @@ -1,19 +1,5 @@ -require 'bundler' -Bundler::GemHelper.install_tasks +#!/usr/bin/env rake +require "bundler/gem_tasks" -require 'rake/testtask' -Rake::TestTask.new(:test) do |test| - test.libs << 'lib' << 'test' - test.pattern = 'test/**/test_*.rb' - test.verbose = true -end - -require 'rcov/rcovtask' -Rcov::RcovTask.new do |test| - test.rcov_opts << '--exclude /gems/,/Library/,/usr/,spec,lib/tasks' # exclude external gems/libraries - test.libs << 'test' - test.pattern = 'test/**/test_*.rb' - test.verbose = true -end - -task :default => :test +require 'rspec/core/rake_task' +RSpec::Core::RakeTask.new('spec') diff --git a/abletech-deployment.gemspec b/abletech-deployment.gemspec deleted file mode 100644 index 779062e..0000000 --- a/abletech-deployment.gemspec +++ /dev/null @@ -1,27 +0,0 @@ -# -*- encoding: utf-8 -*- -$:.push File.expand_path("../lib", __FILE__) -require "abletech/deployment/version" - -Gem::Specification.new do |s| - s.name = "abletech-deployment" - s.version = Abletech::Deployment::VERSION - s.platform = Gem::Platform::RUBY - s.authors = ["Jeremy Olliver", "Nigel Ramsay"] - s.email = ["jeremy.olliver@gmail.com", "nigel.ramsay@abletech.co.nz"] - s.summary = %q{Gem for encapsulating abletech's deployment practices} - s.description = %q{Abletech deployment: includes a generator, and capistrano configuration} - - s.files = `git ls-files`.split("\n") - s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } - s.require_paths = ["lib"] - - s.add_runtime_dependency 'rails', '>= 3.0.0' - s.add_runtime_dependency 'capistrano' - s.add_runtime_dependency 'capistrano-ext' - s.add_runtime_dependency 'capistrano_colors' - - s.add_development_dependency 'bundler' - s.add_development_dependency 'minitest' - s.add_development_dependency 'rcov' -end diff --git a/easy-deployment.gemspec b/easy-deployment.gemspec new file mode 100644 index 0000000..869bcbd --- /dev/null +++ b/easy-deployment.gemspec @@ -0,0 +1,26 @@ +# -*- encoding: utf-8 -*- +require File.expand_path('../lib/easy-deployment/version', __FILE__) + +Gem::Specification.new do |gem| + gem.authors = ["Jeremy Olliver", "Nigel Ramsay", "Shevaun Coker"] + gem.email = ["jeremy.olliver@gmail.com", "nigel.ramsay@abletech.co.nz", "shevaun.coker@abletech.co.nz"] + gem.description = %q{Easy deployment: includes a generator, and capistrano configuration} + gem.summary = %q{Gem for encapsulating abletech's deployment practices} + gem.homepage = "" + + gem.files = `git ls-files`.split($\) + gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } + gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) + gem.name = "easy-deployment" + gem.require_paths = ["lib"] + gem.version = Easy::Deployment::VERSION + + + gem.add_runtime_dependency 'rails', '>= 3.0.0' + gem.add_runtime_dependency 'capistrano' + gem.add_runtime_dependency 'capistrano-ext' + gem.add_runtime_dependency 'capistrano_colors' + + gem.add_development_dependency 'bundler' + gem.add_development_dependency 'rspec', '~> 2.8' +end diff --git a/lib/abletech-deployment.rb b/lib/abletech-deployment.rb deleted file mode 100644 index fe36cea..0000000 --- a/lib/abletech-deployment.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'abletech/deployment/version' -require 'abletech/generators/deployment_generator' -require 'abletech/generators/stage_generator' diff --git a/lib/easy-deployment.rb b/lib/easy-deployment.rb new file mode 100644 index 0000000..b4282e4 --- /dev/null +++ b/lib/easy-deployment.rb @@ -0,0 +1,3 @@ +require "easy-deployment/version" +require 'easy/generators/deployment_generator' +require 'easy/generators/stage_generator' diff --git a/lib/abletech/deployment/version.rb b/lib/easy-deployment/version.rb similarity index 76% rename from lib/abletech/deployment/version.rb rename to lib/easy-deployment/version.rb index da4fe08..f42e008 100644 --- a/lib/abletech/deployment/version.rb +++ b/lib/easy-deployment/version.rb @@ -1,4 +1,4 @@ -module Abletech +module Easy module Deployment VERSION = "0.0.7" end diff --git a/lib/abletech/deployment/backup.rb b/lib/easy/deployment/backup.rb similarity index 67% rename from lib/abletech/deployment/backup.rb rename to lib/easy/deployment/backup.rb index 80c3810..1d3bb04 100644 --- a/lib/abletech/deployment/backup.rb +++ b/lib/easy/deployment/backup.rb @@ -1,19 +1,19 @@ -# To load this capistrano configuration, require 'abletech/deployment/backup' from deploy.rb +# To load this capistrano configuration, require 'easy/deployment/backup' from deploy.rb Capistrano::Configuration.instance(:must_exist).load do - namespace :abletech do + namespace :easy do namespace :backup do desc "Creates the shared folders that backup requires" task :setup, :except => { :no_release => true } do run "mkdir -p #{shared_path}/backup/data" end - + desc "Adds a symbolic link from the s3.yml file in the shared/backup into the current/config folder" task :symlink_s3_config do run "ln -sf #{shared_path}/backup/s3.yml #{current_path}/config/s3.yml" end end end - - after 'deploy:setup', 'abletech:backup:setup' - after 'deploy:symlink', 'abletech:backup:symlink_s3_config' + + after 'deploy:setup', 'easy:backup:setup' + after 'deploy:symlink', 'easy:backup:symlink_s3_config' end diff --git a/lib/abletech/deployment/capistrano.rb b/lib/easy/deployment/capistrano.rb similarity index 92% rename from lib/abletech/deployment/capistrano.rb rename to lib/easy/deployment/capistrano.rb index f5f5467..f88bd58 100644 --- a/lib/abletech/deployment/capistrano.rb +++ b/lib/easy/deployment/capistrano.rb @@ -1,5 +1,5 @@ # Define some defaults for capistrano deploys. -# To load this capistrano configuraiton, require 'abletech/deployment/capistrano' from deploy.rb +# To load this capistrano configuraiton, require 'easy/deployment/capistrano' from deploy.rb Capistrano::Configuration.instance(:must_exist).load do diff --git a/lib/abletech/deployment/logrotate.rb b/lib/easy/deployment/logrotate.rb similarity index 74% rename from lib/abletech/deployment/logrotate.rb rename to lib/easy/deployment/logrotate.rb index 77d5887..c36ead0 100644 --- a/lib/abletech/deployment/logrotate.rb +++ b/lib/easy/deployment/logrotate.rb @@ -1,6 +1,6 @@ -# To load this capistrano configuration, require 'abletech/deployment/logrotate' from deploy.rb +# To load this capistrano configuration, require 'easy/deployment/logrotate' from deploy.rb Capistrano::Configuration.instance(:must_exist).load do - namespace :abletech do + namespace :easy do namespace :logrotate do desc "Copies the application logrotate file into /etc/logrotate.d" task :setup, :except => { :no_release => true } do diff --git a/lib/abletech/deployment/whenever.rb b/lib/easy/deployment/whenever.rb similarity index 70% rename from lib/abletech/deployment/whenever.rb rename to lib/easy/deployment/whenever.rb index a0f8d19..2656a0e 100644 --- a/lib/abletech/deployment/whenever.rb +++ b/lib/easy/deployment/whenever.rb @@ -1,20 +1,20 @@ -# To load this capistrano configuration, require 'abletech/deployment/whenever' from deploy.rb +# To load this capistrano configuration, require 'easy/deployment/whenever' from deploy.rb Capistrano::Configuration.instance(:must_exist).load do - namespace :abletech do + namespace :easy do namespace :whenever do desc "Removes this application's entries from the user's crontab file" task :clear_crontab do run "cd #{release_path} && #{bundle_cmd} exec whenever -f #{release_path}/config/deploy/#{rails_env}/whenever.rb --clear-crontab #{application}" end - + desc "Updates this application's crontab file entries" task :update_crontab do run "cd #{current_path} && #{bundle_cmd} exec whenever -f #{current_path}/config/deploy/#{rails_env}/whenever.rb --update-crontab #{application} --set \"current_path=#{current_path}&bundle_cmd=#{fetch(:bundle_cmd, 'bundle')}&rails_env=#{rails_env}&application=#{application}\"" end - end + end end - after "deploy:update_code", "abletech:whenever:clear_crontab" - after "deploy:symlink", "abletech:whenever:update_crontab" - after "deploy:rollback", "abletech:whenever:update_crontab" + after "deploy:update_code", "easy:whenever:clear_crontab" + after "deploy:symlink", "easy:whenever:update_crontab" + after "deploy:rollback", "easy:whenever:update_crontab" end diff --git a/lib/abletech/generators/deployment_generator.rb b/lib/easy/generators/deployment_generator.rb similarity index 93% rename from lib/abletech/generators/deployment_generator.rb rename to lib/easy/generators/deployment_generator.rb index d449858..d8b8403 100644 --- a/lib/abletech/generators/deployment_generator.rb +++ b/lib/easy/generators/deployment_generator.rb @@ -1,7 +1,7 @@ require 'rails/generators' require 'optparse' -module Abletech +module Easy class DeploymentGenerator < Rails::Generators::Base source_root File.join(File.dirname(__FILE__), "templates") # Where templates are copied from @@ -14,7 +14,7 @@ def application_name def create_deployment_files options = parse_options(ARGV) - # If there was a deploy.rb initially, let the generator prompt to handle conflicts. Otherwise remove the default capistrano one, so we can override it silently with our template without being prompted + # If there was a deploy.rb initially, let the generator prompt to handle conflicts. Otherwise remove the default capistrano one, so we can override it silently with our template without being prompted deploy_file_already_existed = File.exist?(File.join(destination_root, "config", "deploy.rb")) capify! remove_file("config/deploy.rb") unless deploy_file_already_existed # Removing this means we aren't prompted to overwrite if we only have the default capistrano deploy.rb @@ -24,15 +24,15 @@ def create_deployment_files # Generate all stages specified options[:stages] ||= %w(staging production) options[:stages].each do |stage| - generate("abletech:stage", stage) + generate("easy:stage", stage) end info = %{ -Abletech Deployment Config now setup! +Easy Deployment Config now setup! TODO: * Set the correct git repository in config/deploy.rb -} +} options[:stages].each do |stage| info += " * Set the ip address for staging in config/deploy/#{stage}.rb && the apache config in config/deploy/#{stage}/apache/#{application_name}" end diff --git a/lib/abletech/generators/logrotate_generator.rb b/lib/easy/generators/logrotate_generator.rb similarity index 89% rename from lib/abletech/generators/logrotate_generator.rb rename to lib/easy/generators/logrotate_generator.rb index aa3ff87..3554383 100644 --- a/lib/abletech/generators/logrotate_generator.rb +++ b/lib/easy/generators/logrotate_generator.rb @@ -1,10 +1,10 @@ require 'rails/generators' -module Abletech +module Easy class LogrotateGenerator < Rails::Generators::NamedBase source_root File.join(File.dirname(__FILE__), "templates") # Where templates are copied from - desc %{Generate a new logrotate.conf file for the given environment name\ne.g. rails g abletech:logrotate workshop} + desc %{Generate a new logrotate.conf file for the given environment name\ne.g. rails g easy:logrotate workshop} def generate_stage # directory("stage", "config/#{name}") diff --git a/lib/abletech/generators/stage_generator.rb b/lib/easy/generators/stage_generator.rb similarity index 90% rename from lib/abletech/generators/stage_generator.rb rename to lib/easy/generators/stage_generator.rb index 0e63c50..febf1b5 100644 --- a/lib/abletech/generators/stage_generator.rb +++ b/lib/easy/generators/stage_generator.rb @@ -1,10 +1,10 @@ require 'rails/generators' -module Abletech +module Easy class StageGenerator < Rails::Generators::NamedBase source_root File.join(File.dirname(__FILE__), "templates") # Where templates are copied from - desc %{Generate a new deployment script for the given environment name\ne.g. rails g abletech:stage workshop} + desc %{Generate a new deployment script for the given environment name\ne.g. rails g easy:stage workshop} def generate_stage directory("stage", "config/deploy/#{name}") diff --git a/lib/abletech/generators/templates/deploy.rb.tt b/lib/easy/generators/templates/deploy.rb.tt similarity index 71% rename from lib/abletech/generators/templates/deploy.rb.tt rename to lib/easy/generators/templates/deploy.rb.tt index feb42e8..9af1b46 100644 --- a/lib/abletech/generators/templates/deploy.rb.tt +++ b/lib/easy/generators/templates/deploy.rb.tt @@ -2,9 +2,9 @@ require "capistrano/ext/multistage" require "capistrano_colors" require "bundler/capistrano" begin - require "abletech/deployment/capistrano" + require "easy/deployment/capistrano" rescue LoadError - $stderr.puts "couldn't load abletech-deployment gem, try `bundle install` and running again with `bundle exec cap deploy`" + $stderr.puts "couldn't load easy-deployment gem, try `bundle install` and running again with `bundle exec cap deploy`" exit(1) end @@ -15,7 +15,7 @@ set :application, "<%= application_name %>" # TODO: edit application name set :deploy_to, "/var/apps/#{application}" # TODO: fill in git repo -# set :repository, "git@github.com:AbleTech/abletech-deployment.git" +# set :repository, "git@github.com:AbleTech/easy-deployment.git" set :scm, :git set :deploy_via, :remote_cache set :git_shallow_clone, 1 diff --git a/lib/abletech/generators/templates/stage.rb.tt b/lib/easy/generators/templates/stage.rb.tt similarity index 100% rename from lib/abletech/generators/templates/stage.rb.tt rename to lib/easy/generators/templates/stage.rb.tt diff --git a/lib/abletech/generators/templates/stage/apache/%application_name%.tt b/lib/easy/generators/templates/stage/apache/%application_name%.tt similarity index 100% rename from lib/abletech/generators/templates/stage/apache/%application_name%.tt rename to lib/easy/generators/templates/stage/apache/%application_name%.tt diff --git a/spec/easy_deployment_spec.rb b/spec/easy_deployment_spec.rb new file mode 100644 index 0000000..7f8fa0e --- /dev/null +++ b/spec/easy_deployment_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper.rb' + +describe Easy::Deployment do + it "has a version number" do + Easy::Deployment::VERSION.should be_present + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..3ee85fc --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,15 @@ +# This file was generated by the `rspec --init` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# Require this file using `require "spec_helper.rb"` to ensure that it is only +# loaded once. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration + +require 'rubygems' +require 'bundler' + +require 'easy-deployment' + +RSpec.configure do |config| + config.mock_with :rspec +end diff --git a/test/helper.rb b/test/helper.rb deleted file mode 100644 index 28ff755..0000000 --- a/test/helper.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'rubygems' -require 'bundler' -begin - Bundler.setup(:default, :development) -rescue Bundler::BundlerError => e - $stderr.puts e.message - $stderr.puts "Run `bundle install` to install missing gems" - exit e.status_code -end -require 'minitest/unit' - -$LOAD_PATH.unshift(File.dirname(__FILE__)) -$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) -require 'abletech-deployment' - -class MiniTest::Unit::TestCase -end - -MiniTest::Unit.autorun diff --git a/test/test_abletech_deployment.rb b/test/test_abletech_deployment.rb deleted file mode 100644 index e4745a6..0000000 --- a/test/test_abletech_deployment.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'helper' - -class Abletech::TestDeployment < MiniTest::Unit::TestCase - def test_something_for_real - flunk "hey buddy, you should probably rename this file and start testing for real" - end -end