easy-deployment 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in easy-deployment.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Able Technology
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Able Technology
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # Easy::Deployment
2
+
3
+ This gem is for encapsulating Abletech's common deployment patterns using capistrano.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'easy-deployment', :git => "git@github.com:AbleTech/easy-deployment.git"
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install easy-deployment
18
+
19
+ ## Usage
20
+
21
+ Run:
22
+
23
+ $ rails g easy:deployment
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new('spec')
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/easy-deployment/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Jeremy Olliver", "Nigel Ramsay", "Shevaun Coker"]
6
+ gem.email = ["jeremy.olliver@gmail.com", "nigel.ramsay@abletech.co.nz", "shevaun.coker@abletech.co.nz"]
7
+ gem.description = %q{Easy deployment: includes a generator, and capistrano configuration}
8
+ gem.summary = %q{Gem for encapsulating abletech's deployment practices}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "easy-deployment"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Easy::Deployment::VERSION
17
+
18
+
19
+ gem.add_runtime_dependency 'rails', '>= 3.0.0'
20
+ gem.add_runtime_dependency 'capistrano'
21
+ gem.add_runtime_dependency 'capistrano-ext'
22
+ gem.add_runtime_dependency 'capistrano_colors'
23
+
24
+ gem.add_development_dependency 'bundler'
25
+ gem.add_development_dependency 'rspec', '~> 2.8'
26
+ end
@@ -0,0 +1,3 @@
1
+ require "easy-deployment/version"
2
+ require 'easy/generators/deployment_generator'
3
+ require 'easy/generators/stage_generator'
@@ -0,0 +1,5 @@
1
+ module Easy
2
+ module Deployment
3
+ VERSION = "0.0.8"
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ # To load this capistrano configuration, require 'easy/deployment/backup' from deploy.rb
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+ namespace :easy do
4
+ namespace :backup do
5
+ desc "Creates the shared folders that backup requires"
6
+ task :setup, :except => { :no_release => true } do
7
+ run "mkdir -p #{shared_path}/backup/data"
8
+ end
9
+
10
+ desc "Adds a symbolic link from the s3.yml file in the shared/backup into the current/config folder"
11
+ task :symlink_s3_config do
12
+ run "ln -sf #{shared_path}/backup/s3.yml #{current_path}/config/s3.yml"
13
+ end
14
+ end
15
+ end
16
+
17
+ after 'deploy:setup', 'easy:backup:setup'
18
+ after 'deploy:symlink', 'easy:backup:symlink_s3_config'
19
+ end
@@ -0,0 +1,39 @@
1
+ # Define some defaults for capistrano deploys.
2
+ # To load this capistrano configuraiton, require 'easy/deployment/capistrano' from deploy.rb
3
+
4
+ Capistrano::Configuration.instance(:must_exist).load do
5
+
6
+ # ssh options
7
+ set :use_sudo, false
8
+ ssh_options[:forward_agent] = true # run `ssh-add ;` to ensure your identity file is added
9
+ default_run_options[:pty] = true
10
+
11
+ namespace :deploy do
12
+ # By default, we deploy using passenger as an app server
13
+ task :start do ; end
14
+ task :stop do ; end
15
+ task :restart, :roles => :app, :except => { :no_release => true } do
16
+ run "touch #{File.join(current_path,'tmp','restart.txt')}"
17
+ end
18
+
19
+ desc "[internal] Copies the application configuration files for this environment"
20
+ task :configure do
21
+ if File.exists?("./config/deploy/#{stage}/database.yml")
22
+ run "cp #{release_path}/config/deploy/#{stage}/database.yml #{release_path}/config/database.yml"
23
+ else
24
+ puts "Skipping copying of config/deploy/#{stage}/database.yml as the file is not present"
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ namespace :web do
31
+ desc "Configure this site & Reload the apache configuration"
32
+ task :configure do
33
+ run "cp -f #{current_path}/config/deploy/#{stage}/apache/* /etc/apache2/sites-enabled/"
34
+ run "sudo apache2ctl -k graceful"
35
+ end
36
+ end
37
+
38
+ after "deploy:update_code", "deploy:configure"
39
+ end
@@ -0,0 +1,11 @@
1
+ # To load this capistrano configuration, require 'easy/deployment/logrotate' from deploy.rb
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+ namespace :easy do
4
+ namespace :logrotate do
5
+ desc "Copies the application logrotate file into /etc/logrotate.d"
6
+ task :setup, :except => { :no_release => true } do
7
+ run "cp #{current_path}/config/deploy/#{stage}/logrotate.conf /etc/logrotate.d/#{application}.conf"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ # To load this capistrano configuration, require 'easy/deployment/whenever' from deploy.rb
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+ namespace :easy do
4
+ namespace :whenever do
5
+ desc "Removes this application's entries from the user's crontab file"
6
+ task :clear_crontab do
7
+ run "cd #{release_path} && #{bundle_cmd} exec whenever -f #{release_path}/config/deploy/#{rails_env}/whenever.rb --clear-crontab #{application}"
8
+ end
9
+
10
+ desc "Updates this application's crontab file entries"
11
+ task :update_crontab do
12
+ 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}\""
13
+ end
14
+ end
15
+ end
16
+
17
+ after "deploy:update_code", "easy:whenever:clear_crontab"
18
+ after "deploy:symlink", "easy:whenever:update_crontab"
19
+ after "deploy:rollback", "easy:whenever:update_crontab"
20
+ end
@@ -0,0 +1,57 @@
1
+ require 'rails/generators'
2
+ require 'optparse'
3
+
4
+ module Easy
5
+ class DeploymentGenerator < Rails::Generators::Base
6
+ source_root File.join(File.dirname(__FILE__), "templates") # Where templates are copied from
7
+
8
+ def application_name
9
+ Rails.application.class.name.split("::").first.underscore # surely there's a better way than this
10
+ end
11
+
12
+ desc %{Generates standard able technology deployment script using capistrano}
13
+
14
+ def create_deployment_files
15
+ options = parse_options(ARGV)
16
+
17
+ # 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
18
+ deploy_file_already_existed = File.exist?(File.join(destination_root, "config", "deploy.rb"))
19
+ capify!
20
+ 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
21
+ # Write our default deploy.rb
22
+ copy_file("deploy.rb.tt", "config/deploy.rb")
23
+
24
+ # Generate all stages specified
25
+ options[:stages] ||= %w(staging production)
26
+ options[:stages].each do |stage|
27
+ generate("easy:stage", stage)
28
+ end
29
+
30
+ info = %{
31
+ Easy Deployment Config now setup!
32
+
33
+ TODO:
34
+ * Set the correct git repository in config/deploy.rb
35
+ }
36
+ options[:stages].each do |stage|
37
+ info += " * Set the ip address for staging in config/deploy/#{stage}.rb && the apache config in config/deploy/#{stage}/apache/#{application_name}"
38
+ end
39
+ puts info
40
+ true
41
+ end
42
+
43
+ private
44
+
45
+ # TODO: surely there's a better option parser built into thor, or the generators themselves?
46
+ def parse_options(args)
47
+ opts = {}
48
+ OptionParser.new do |opt|
49
+ opt.on("-s", "--stages" "Stages to generate") do |s|
50
+ opts[:stages] = s.split(",") if s.present?
51
+ end
52
+ end.parse(args)
53
+ opts
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,21 @@
1
+ require 'rails/generators'
2
+
3
+ module Easy
4
+ class LogrotateGenerator < Rails::Generators::NamedBase
5
+ source_root File.join(File.dirname(__FILE__), "templates") # Where templates are copied from
6
+
7
+ desc %{Generate a new logrotate.conf file for the given environment name\ne.g. rails g easy:logrotate workshop}
8
+
9
+ def generate_stage
10
+ # directory("stage", "config/#{name}")
11
+
12
+ # Ensure we have a config/deploy/<env-name>/logrotate.rb
13
+ # dest = "config/deploy/#{name}/logrotate.conf"
14
+ # in_root do
15
+ # unless File.exist?(dest)
16
+ # run("cp config/environments/production.rb #{dest}")
17
+ # end
18
+ # end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ require 'rails/generators'
2
+
3
+ module Easy
4
+ class StageGenerator < Rails::Generators::NamedBase
5
+ source_root File.join(File.dirname(__FILE__), "templates") # Where templates are copied from
6
+
7
+ desc %{Generate a new deployment script for the given environment name\ne.g. rails g easy:stage workshop}
8
+
9
+ def generate_stage
10
+ directory("stage", "config/deploy/#{name}")
11
+ copy_file("stage.rb.tt", "config/deploy/#{name}.rb")
12
+
13
+ # Ensure we have a config/environments/<env-name>.rb
14
+ dest = "config/environments/#{name}.rb"
15
+ in_root do
16
+ unless File.exist?(dest)
17
+ run("cp config/environments/production.rb #{dest}")
18
+ end
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ require "capistrano/ext/multistage"
2
+ require "capistrano_colors"
3
+ require "bundler/capistrano"
4
+ begin
5
+ require "easy/deployment/capistrano"
6
+ rescue LoadError
7
+ $stderr.puts "couldn't load easy-deployment gem, try `bundle install` and running again with `bundle exec cap <stage> deploy`"
8
+ exit(1)
9
+ end
10
+
11
+ set :stages, %w(staging production)
12
+ set :default_stage, "staging"
13
+
14
+ set :application, "<%= application_name %>" # TODO: edit application name
15
+ set :deploy_to, "/var/apps/#{application}"
16
+
17
+ # TODO: fill in git repo
18
+ # set :repository, "git@github.com:AbleTech/easy-deployment.git"
19
+ set :scm, :git
20
+ set :deploy_via, :remote_cache
21
+ set :git_shallow_clone, 1
22
+
23
+
24
+ # If deploying with RVM:
25
+ # Add gem 'rvm' to the development group in Gemfile, and uncomment following lines
26
+ # require "rvm/capistrano"
27
+ # set :rvm_type, :system
28
+ # set :rvm_ruby_string, '1.9.2-p290'
@@ -0,0 +1,6 @@
1
+ # role :web, "<<%= name %>-ip-address>" # Your HTTP server, Apache/etc
2
+ # role :app, "<<%= name %>-ip-address>" # This may be the same as your `Web` server
3
+ # role :db, "<<%= name %>-ip-address>", :primary => true # This is where Rails migrations will run
4
+
5
+ set :branch, "master"
6
+ set :rails_env, "<%= name %>"
@@ -0,0 +1,10 @@
1
+ <VirtualHost <<%= name %>-ip-address>:80>
2
+ ServerName <%= name %>.<%= application_name %>.co.nz
3
+
4
+ DocumentRoot /var/apps/<%= application_name %>/current/public
5
+ RailsEnv <%= name %>
6
+ <Directory /var/apps/<%= application_name %>/current/public>
7
+ AllowOverride all
8
+ Options -MultiViews
9
+ </Directory>
10
+ </VirtualHost>
@@ -0,0 +1,7 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Easy::Deployment do
4
+ it "has a version number" do
5
+ Easy::Deployment::VERSION.should be_present
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require 'rubygems'
9
+ require 'bundler'
10
+
11
+ require 'easy-deployment'
12
+
13
+ RSpec.configure do |config|
14
+ config.mock_with :rspec
15
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easy-deployment
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeremy Olliver
9
+ - Nigel Ramsay
10
+ - Shevaun Coker
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-04-29 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rails
18
+ requirement: &70127454527720 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: 3.0.0
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *70127454527720
27
+ - !ruby/object:Gem::Dependency
28
+ name: capistrano
29
+ requirement: &70127454526800 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *70127454526800
38
+ - !ruby/object:Gem::Dependency
39
+ name: capistrano-ext
40
+ requirement: &70127454525720 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *70127454525720
49
+ - !ruby/object:Gem::Dependency
50
+ name: capistrano_colors
51
+ requirement: &70127458468000 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: *70127458468000
60
+ - !ruby/object:Gem::Dependency
61
+ name: bundler
62
+ requirement: &70127458494460 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *70127458494460
71
+ - !ruby/object:Gem::Dependency
72
+ name: rspec
73
+ requirement: &70127458520500 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: '2.8'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *70127458520500
82
+ description: ! 'Easy deployment: includes a generator, and capistrano configuration'
83
+ email:
84
+ - jeremy.olliver@gmail.com
85
+ - nigel.ramsay@abletech.co.nz
86
+ - shevaun.coker@abletech.co.nz
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .rspec
93
+ - Gemfile
94
+ - LICENSE
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - easy-deployment.gemspec
99
+ - lib/easy-deployment.rb
100
+ - lib/easy-deployment/version.rb
101
+ - lib/easy/deployment/backup.rb
102
+ - lib/easy/deployment/capistrano.rb
103
+ - lib/easy/deployment/logrotate.rb
104
+ - lib/easy/deployment/whenever.rb
105
+ - lib/easy/generators/deployment_generator.rb
106
+ - lib/easy/generators/logrotate_generator.rb
107
+ - lib/easy/generators/stage_generator.rb
108
+ - lib/easy/generators/templates/deploy.rb.tt
109
+ - lib/easy/generators/templates/stage.rb.tt
110
+ - lib/easy/generators/templates/stage/apache/%application_name%.tt
111
+ - spec/easy_deployment_spec.rb
112
+ - spec/spec_helper.rb
113
+ homepage: ''
114
+ licenses: []
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ segments:
126
+ - 0
127
+ hash: 2386324280416784437
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ segments:
135
+ - 0
136
+ hash: 2386324280416784437
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 1.8.16
140
+ signing_key:
141
+ specification_version: 3
142
+ summary: Gem for encapsulating abletech's deployment practices
143
+ test_files:
144
+ - spec/easy_deployment_spec.rb
145
+ - spec/spec_helper.rb