capistrano-devops 0.0.1

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.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +35 -0
  6. data/Rakefile +1 -0
  7. data/capistrano-devops.gemspec +22 -0
  8. data/lib/capistrano-devops.rb +0 -0
  9. data/lib/capistrano/devops.rb +7 -0
  10. data/lib/capistrano/devops/base.rb +6 -0
  11. data/lib/capistrano/devops/papertrail.rb +1 -0
  12. data/lib/capistrano/devops/postgresql.rb +1 -0
  13. data/lib/capistrano/devops/rainbows.rb +1 -0
  14. data/lib/capistrano/devops/ssh.rb +1 -0
  15. data/lib/capistrano/devops/templates/rainbows.erb +14 -0
  16. data/lib/capistrano/devops/templates/rainbows_init.erb +84 -0
  17. data/lib/capistrano/devops/utilities.rb +1 -0
  18. data/lib/capistrano/devops/version.rb +5 -0
  19. data/lib/capistrano/tasks/papertrail.rake +50 -0
  20. data/lib/capistrano/tasks/postgresql.rake +9 -0
  21. data/lib/capistrano/tasks/rainbows.rake +33 -0
  22. data/lib/capistrano/tasks/set_rails_env.rake +5 -0
  23. data/lib/capistrano/tasks/ssh.rake +17 -0
  24. data/lib/capistrano/tasks/utilities.rake +31 -0
  25. data/sample_app/.gitignore +16 -0
  26. data/sample_app/Capfile +30 -0
  27. data/sample_app/Gemfile +54 -0
  28. data/sample_app/Gemfile.lock +185 -0
  29. data/sample_app/README.rdoc +28 -0
  30. data/sample_app/Rakefile +6 -0
  31. data/sample_app/Vagrantfile +59 -0
  32. data/sample_app/app/assets/images/.keep +0 -0
  33. data/sample_app/app/assets/javascripts/application.js +16 -0
  34. data/sample_app/app/assets/stylesheets/application.css +13 -0
  35. data/sample_app/app/controllers/application_controller.rb +5 -0
  36. data/sample_app/app/controllers/concerns/.keep +0 -0
  37. data/sample_app/app/helpers/application_helper.rb +2 -0
  38. data/sample_app/app/mailers/.keep +0 -0
  39. data/sample_app/app/models/.keep +0 -0
  40. data/sample_app/app/models/concerns/.keep +0 -0
  41. data/sample_app/app/views/layouts/application.html.erb +14 -0
  42. data/sample_app/bin/bundle +3 -0
  43. data/sample_app/bin/rails +4 -0
  44. data/sample_app/bin/rake +4 -0
  45. data/sample_app/config.ru +4 -0
  46. data/sample_app/config/application.rb +23 -0
  47. data/sample_app/config/boot.rb +4 -0
  48. data/sample_app/config/database.yml +25 -0
  49. data/sample_app/config/deploy.rb +60 -0
  50. data/sample_app/config/deploy/production.rb +49 -0
  51. data/sample_app/config/environment.rb +5 -0
  52. data/sample_app/config/environments/development.rb +29 -0
  53. data/sample_app/config/environments/production.rb +80 -0
  54. data/sample_app/config/environments/test.rb +36 -0
  55. data/sample_app/config/initializers/backtrace_silencers.rb +7 -0
  56. data/sample_app/config/initializers/filter_parameter_logging.rb +4 -0
  57. data/sample_app/config/initializers/inflections.rb +16 -0
  58. data/sample_app/config/initializers/mime_types.rb +5 -0
  59. data/sample_app/config/initializers/secret_token.rb +12 -0
  60. data/sample_app/config/initializers/session_store.rb +3 -0
  61. data/sample_app/config/initializers/wrap_parameters.rb +14 -0
  62. data/sample_app/config/locales/en.yml +23 -0
  63. data/sample_app/config/routes.rb +56 -0
  64. data/sample_app/db/seeds.rb +7 -0
  65. data/sample_app/lib/assets/.keep +0 -0
  66. data/sample_app/lib/tasks/.keep +0 -0
  67. data/sample_app/log/.keep +0 -0
  68. data/sample_app/public/404.html +58 -0
  69. data/sample_app/public/422.html +58 -0
  70. data/sample_app/public/500.html +57 -0
  71. data/sample_app/public/favicon.ico +0 -0
  72. data/sample_app/public/robots.txt +5 -0
  73. data/sample_app/test/controllers/.keep +0 -0
  74. data/sample_app/test/fixtures/.keep +0 -0
  75. data/sample_app/test/helpers/.keep +0 -0
  76. data/sample_app/test/integration/.keep +0 -0
  77. data/sample_app/test/mailers/.keep +0 -0
  78. data/sample_app/test/models/.keep +0 -0
  79. data/sample_app/test/test_helper.rb +15 -0
  80. data/sample_app/vendor/assets/javascripts/.keep +0 -0
  81. data/sample_app/vendor/assets/stylesheets/.keep +0 -0
  82. metadata +152 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 796e319fadbfaf5d6b53b0b221bb027669c71a5c
4
+ data.tar.gz: 1209a1ac9b6f6b7cc40c0eaa5191da3271d835b2
5
+ SHA512:
6
+ metadata.gz: 35c3f0ff34f8407f98df56bece0b2654aae5fcd308469ef152cc91ac49a0b41822ac1182481197fd14fdbaffb054a28cc7b36f24a3ce3f55d00dcc42e4d2ad86
7
+ data.tar.gz: 496b4363a88a8c298f53377890512828fef20137c337eb603d01ff7337d540ebf8c5d448d0fd369b582205ddd1e4fd5262f281c12e829d724e8b2b159d065432
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
18
+ *.vagrant
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-devops.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 tristan
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.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Capistrano::Devops
2
+
3
+ Capistrano::Devops gathers together some capistrano recipes to help in configuring and deploying applications
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capistrano-devops', group: development
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install capistrano-devops
18
+
19
+ ## Usage
20
+
21
+ require 'capistrano/devops' in Capfile
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
30
+
31
+ ## Development
32
+
33
+ There is a sample app in /sample_app that you can use to play around with the recipes. I personally use Vagrant and sandbox mode available at https://github.com/jedi4ever/sahara to create the VM for deployment.
34
+
35
+ Right now the Vagrantfile still needs a bit of work (mostly the post-install script that will provision the server with ruby, bundler, and nginx)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/devops/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capistrano-devops"
8
+ spec.version = Capistrano::Devops::VERSION
9
+ spec.authors = ["tristan"]
10
+ spec.email = ["tristan.gomez@gmail.com"]
11
+ spec.description = %q{yay}
12
+ spec.summary = %q{yay}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'capistrano', '~> 3'
21
+ spec.add_dependency 'capistrano-bundler'
22
+ end
File without changes
@@ -0,0 +1,7 @@
1
+ require "capistrano/devops/version"
2
+ require 'capistrano/devops/base'
3
+ require 'capistrano/devops/papertrail'
4
+ require 'capistrano/devops/rainbows'
5
+ require 'capistrano/devops/postgresql'
6
+ require 'capistrano/devops/ssh'
7
+ require 'capistrano/devops/utilities'
@@ -0,0 +1,6 @@
1
+ def template(from, to)
2
+ tmpl = File.read(File.expand_path("../templates/#{from}", __FILE__))
3
+ erb = ERB.new(tmpl).result(binding)
4
+ execute :touch, "#{to}"
5
+ upload! StringIO.new(erb), to
6
+ end
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/papertrail.rake", __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/postgresql.rake", __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/rainbows.rake", __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/ssh.rake", __FILE__)
@@ -0,0 +1,14 @@
1
+ working_directory "<%= current_path %>"
2
+ pid "<%= fetch(:rainbows_pid) %>"
3
+ stderr_path "<%= fetch(:rainbows_log) %>"
4
+ stdout_path "<%= fetch(:rainbows_log) %>"
5
+
6
+ listen "/tmp/rainbows.<%= fetch(:application) %>.sock"
7
+ worker_processes <%= fetch(:rainbows_workers) %>
8
+ timeout 30
9
+
10
+ Rainbows! do
11
+ worker_connections 400
12
+ keepalive_timeout 0
13
+ use :EventMachine
14
+ end
@@ -0,0 +1,84 @@
1
+ #!/bin/sh
2
+ ### BEGIN INIT INFO
3
+ # Provides: rainbows
4
+ # Required-Start: $remote_fs $syslog
5
+ # Required-Stop: $remote_fs $syslog
6
+ # Default-Start: 2 3 4 5
7
+ # Default-Stop: 0 1 6
8
+ # Short-Description: Manage rainbows server
9
+ # Description: Start, stop, restart rainbows server for a specific application.
10
+ ### END INIT INFO
11
+ set -e
12
+
13
+ # Feel free to change any of the following variables for your app:
14
+ TIMEOUT=${TIMEOUT-60}
15
+ APP_ROOT=<%= current_path %>
16
+ PID=<%= fetch(:rainbows_pid) %>
17
+ CMD="cd <%= current_path %>; bundle exec rainbows -D -c <%= fetch(:rainbows_config) %> -E <%= fetch(:rails_env) %>"
18
+ AS_USER=<%= fetch(:rainbows_user) %>
19
+ set -u
20
+
21
+ OLD_PIN="$PID.oldbin"
22
+
23
+ sig () {
24
+ test -s "$PID" && kill -$1 `cat $PID`
25
+ }
26
+
27
+ oldsig () {
28
+ test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
29
+ }
30
+
31
+ run () {
32
+ if [ "$(id -un)" = "$AS_USER" ]; then
33
+ eval $1
34
+ else
35
+ su -c "$1" - $AS_USER
36
+ fi
37
+ }
38
+
39
+ case "$1" in
40
+ start)
41
+ sig 0 && echo >&2 "Already running" && exit 0
42
+ run "$CMD"
43
+ ;;
44
+ stop)
45
+ sig QUIT && exit 0
46
+ echo >&2 "Not running"
47
+ ;;
48
+ force-stop)
49
+ sig TERM && exit 0
50
+ echo >&2 "Not running"
51
+ ;;
52
+ restart|reload)
53
+ sig USR2 && echo reloaded OK && exit 0
54
+ echo >&2 "Couldn't reload, starting '$CMD' instead"
55
+ run "$CMD"
56
+ ;;
57
+ upgrade)
58
+ if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
59
+ then
60
+ n=$TIMEOUT
61
+ while test -s $OLD_PIN && test $n -ge 0
62
+ do
63
+ printf '.' && sleep 1 && n=$(( $n - 1 ))
64
+ done
65
+ echo
66
+
67
+ if test $n -lt 0 && test -s $OLD_PIN
68
+ then
69
+ echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
70
+ exit 1
71
+ fi
72
+ exit 0
73
+ fi
74
+ echo >&2 "Couldn't upgrade, starting '$CMD' instead"
75
+ run "$CMD"
76
+ ;;
77
+ reopen-logs)
78
+ sig USR1
79
+ ;;
80
+ *)
81
+ echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
82
+ exit 1
83
+ ;;
84
+ esac
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/utilities.rake", __FILE__)
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Devops
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,50 @@
1
+ load File.expand_path("../set_rails_env.rake", __FILE__)
2
+
3
+ namespace :papertrail do
4
+ # desc 'Adds papertrail to rsyslog as an output channel'
5
+ task :add_to_rsyslog do
6
+ # as root add
7
+ # *.* @logs.papertrailapp.com:31378
8
+ # to the end of /etc/rsyslog.conf
9
+
10
+ # restart rsyslog
11
+ # sudo /etc/init.d/rsyslog restart
12
+ end
13
+
14
+ # desc 'Install remote_syslog'
15
+ task :remote_syslog do
16
+ # sudo gem install remote_syslog
17
+ # Paths to log file(s) can be specified on the command-line, or save log_files.yml.example (typically as /etc/log_files.yml). Edit it to define:
18
+ # - path to this app's log file, and any other log file(s) to watch.
19
+ # - destination host and port (provided by Papertrail). You can find the settings by clicking Add System from the dashboard.
20
+
21
+ # /etc/log_files.yml
22
+ # files:
23
+ # - /var/log/httpd/access_log
24
+ # - /var/log/httpd/error_log
25
+ # - /opt/misc/*.log
26
+ # - /var/log/mysqld.log
27
+ # - /var/run/mysqld/mysqld-slow.log
28
+ # destination:
29
+ # host: logs.papertrailapp.com
30
+ # port: 12345 # NOTE: change to your Papertrail port
31
+
32
+ # While remote_syslog does not need to run as root, it does need permission to write its PID file (by default to /var/run/remote_syslog.pid) and read permission on the log files it is monitoring.
33
+
34
+ # remote_syslog.upstart.conf
35
+ # description "Monitor files and send to remote syslog"
36
+ # start on runlevel [2345]
37
+ # stop on runlevel [!2345]
38
+
39
+ # respawn
40
+
41
+ # pre-start exec /usr/bin/test -e /etc/log_files.yml
42
+
43
+ # exec /var/lib/gems/1.8/bin/remote_syslog -D --tls
44
+ end
45
+
46
+ desc 'Installs papertrail and adds remote_syslog'
47
+ task :install do
48
+ end
49
+
50
+ end
@@ -0,0 +1,9 @@
1
+ namespace :postgresql do
2
+ desc "Install required libraries"
3
+ task :install_libraries do
4
+ on roles(:app) do |host|
5
+ execute :sudo, "apt-get -y update"
6
+ execute :sudo, "apt-get -y install libpq-dev"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,33 @@
1
+ set :rainbows_user, ->{ fetch(:user) }
2
+ set :rainbows_pid, ->{ "#{current_path}/tmp/pids/rainbows.pid" }
3
+ set :rainbows_config, ->{ "#{shared_path}/config/rainbows.rb" }
4
+ set :rainbows_log, ->{ "#{shared_path}/log/rainbows.log" }
5
+ set :rainbows_workers, 2
6
+
7
+ namespace :rainbows do
8
+ desc "Setup Rainbows initializer and app configuration"
9
+ task :setup do
10
+ on roles :app do
11
+ execute :mkdir, "-p #{shared_path}/config"
12
+
13
+ template "rainbows_init.erb", "/tmp/rainbows_init"
14
+ template 'rainbows.erb', "#{fetch(:rainbows_config)}"
15
+
16
+ execute :chmod, "+x /tmp/rainbows_init"
17
+ as(:root) do
18
+ execute :mv, "/tmp/rainbows_init /etc/init.d/rainbows_#{fetch(:application)}"
19
+ execute :'update-rc.d', "-f rainbows_#{fetch(:application)} defaults"
20
+ end
21
+ end
22
+ end
23
+
24
+ %w[start stop restart].each do |command|
25
+ desc "#{command} rainbows"
26
+ task command do
27
+ on roles :app do
28
+ command_string = "rainbows_#{fetch(:application)} #{command}"
29
+ execute :service, command_string
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ namespace :deploy do
2
+ task :set_rails_env do
3
+ set :rails_env, (fetch(:rails_env) || fetch(:stage))
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ namespace :ssh do
2
+ desc 'Adds public key to the authorized_keys file (to enable passwordless login)'
3
+ task :add_key do
4
+ ask(:key, 'SSH public key')
5
+ on roles(:all) do |host|
6
+ # this script depends on the HOME environment variable to be set
7
+ home = capture("env | grep HOME").split('=').last
8
+ within home do
9
+ remote_keys = capture(:cat, '.ssh/authorized_keys')
10
+ keys = remote_keys.split("\n")
11
+ keys << fetch(:key) + "\n"
12
+ new_keys = StringIO.new(keys.join("\n"))
13
+ upload! new_keys, '.ssh/authorized_keys'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ namespace :utilities do
2
+ desc "Report Uptimes"
3
+ task :uptime do
4
+ on roles(:all) do |host|
5
+ info "Host #{host} (#{host.roles.to_a.join(', ')}):\t#{capture(:uptime)}"
6
+ end
7
+ end
8
+
9
+ desc "Install common pacakges"
10
+ task :common_packages do
11
+ on roles(:app) do |host|
12
+ execute :sudo, "apt-get -y update"
13
+ execute :sudo, "apt-get -y install python-software-properties htop iftop iotop mytop sysstat screen curl subversion git-core rsync"
14
+ end
15
+ end
16
+
17
+ desc 'Install Ruby'
18
+ task :install_ruby do
19
+ invoke :'utilities:common_packages'
20
+ on roles(:app) do |host|
21
+ execute :curl, "-Lo- https://gist.github.com/parasquid/5624732/raw/install-ruby-2-ubuntu.sh | bash"
22
+ end
23
+ end
24
+
25
+ desc 'Install the Bundler gem (server-wide)'
26
+ task :install_bundler do
27
+ on roles(:app) do |host|
28
+ execute :sudo, 'gem install bundler'
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,16 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+ /db/*.sqlite3-journal
13
+
14
+ # Ignore all logfiles and tempfiles.
15
+ /log/*.log
16
+ /tmp
@@ -0,0 +1,30 @@
1
+ # Load DSL and Setup Up Stages
2
+ require 'capistrano/setup'
3
+
4
+ # Includes default deployment tasks
5
+ require 'capistrano/deploy'
6
+
7
+ require 'capistrano/devops'
8
+ require 'capistrano/rails'
9
+ require 'capistrano/bundler'
10
+
11
+ # Includes tasks from other gems included in your Gemfile
12
+ #
13
+ # For documentation on these, see for example:
14
+ #
15
+ # https://github.com/capistrano/rvm
16
+ # https://github.com/capistrano/rbenv
17
+ # https://github.com/capistrano/chruby
18
+ # https://github.com/capistrano/bundler
19
+ # https://github.com/capistrano/rails/tree/master/assets
20
+ # https://github.com/capistrano/rails/tree/master/migrations
21
+ #
22
+ # require 'capistrano/rvm'
23
+ # require 'capistrano/rbenv'
24
+ # require 'capistrano/chruby'
25
+ # require 'capistrano/bundler'
26
+ # require 'capistrano/rails/assets'
27
+ # require 'capistrano/rails/migrations'
28
+
29
+ # Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
30
+ Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }