cl-mina 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 21b53b9be3b987c3f5ff7264269ae175f4bbf25c
4
+ data.tar.gz: dd14f9e89be9ba339f7c18ca948f0b9314b145fa
5
+ SHA512:
6
+ metadata.gz: 10ebd7443264b8873976e063674813105482fb1a5e949133730cb26e4c2d5fab6fe7412315c46eb9aaec1a7c3eb9a2180eaef54710dfb0853c81090de7bf43fb
7
+ data.tar.gz: 272c46249ac198e1f8d3d7cb7bfd87440aef7cf849e312341d160c2f4ba2b0fff05db99140f87d6fdb37a751529a31d94d94d0f66f16a9eee9ca7d7a47f37779
data/.gitignore ADDED
@@ -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
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cl_mina.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Nathan Sharpe
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,8 @@
1
+ # How to use
2
+
3
+ 1. Add to Gemfile: `gem "cl-mina"`
4
+ 2. Generate deploy configuration: `rails g cl-mina:install`
5
+ 3. ???
6
+ 4. Profit
7
+
8
+ Hint: `mina tasks` will get you a long way toward understanding what ??? is.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/cl-mina.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cl_mina/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cl-mina"
8
+ spec.version = ClMina::VERSION
9
+ spec.authors = ["Nathan Sharpe"]
10
+ spec.email = ["nathan@cliftonlabs.com"]
11
+ spec.summary = "Common deploy tasks and settings."
12
+ spec.description = "Designed for use in a fairly specific context, so probably not that versatile."
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "generator_spec"
25
+
26
+ spec.add_runtime_dependency "mina"
27
+ spec.add_runtime_dependency "pg"
28
+ spec.add_runtime_dependency "unicorn"
29
+ spec.add_runtime_dependency "carrier-pigeon"
30
+ spec.add_runtime_dependency "highline"
31
+ end
@@ -0,0 +1,9 @@
1
+ require 'cl_mina/tasks/check'
2
+ require 'cl_mina/tasks/db'
3
+ require 'cl_mina/tasks/irc'
4
+ require 'cl_mina/tasks/log'
5
+ require 'cl_mina/tasks/logrotate'
6
+ require 'cl_mina/tasks/nginx'
7
+ require 'cl_mina/tasks/postgresql'
8
+ require 'cl_mina/tasks/unicorn'
9
+ require 'cl_mina/tasks/utility'
@@ -0,0 +1,11 @@
1
+ namespace :check do
2
+ desc "Make sure local git is in sync with remote."
3
+ task :revision do
4
+ current_repository = "origin"
5
+ unless (`git rev-parse HEAD` == `git rev-parse #{current_repository}/#{branch}`)
6
+ puts "WARNING: HEAD is not the same as #{current_repository}/#{branch}"
7
+ puts "Run `git push` to sync changes."
8
+ exit
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ namespace :db do
2
+ desc "Run db:seed"
3
+ task :seed do
4
+ queue %{cd #{deploy_to}/#{current_path}}
5
+ queue %{bundle exec rake RAILS_ENV=#{rails_env} db:seed}
6
+ invoke :'irc:announce_seed'
7
+ end
8
+
9
+ desc "Run apartment:migrate"
10
+ task :apartment_migrate do
11
+ queue %{cd #{deploy_to}/#{current_path}}
12
+ queue %{bundle exec rake RAILS_ENV=#{rails_env} apartment:migrate}
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ require "carrier-pigeon"
2
+
3
+ namespace :irc do
4
+ desc "Announce deploy to irc"
5
+ task :announce_deploy do
6
+ CarrierPigeon.send(
7
+ :uri => irc_uri,
8
+ :message => "#{ENV['USER'].capitalize} is deploying #{application_name || application} to #{server}",
9
+ :ssl => irc_ssl
10
+ )
11
+ end
12
+
13
+ task :announce_seed do
14
+ CarrierPigeon.send(
15
+ :uri => irc_uri,
16
+ :message => "#{ENV['USER'].capitalize} is seeding the database for #{application_name || application} #{server}",
17
+ :ssl => irc_ssl
18
+ )
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ namespace :log do
2
+ desc "View tail of rails log"
3
+ task :rails do
4
+ queue "tail #{logs_path}/#{rails_env}.log -n 50"
5
+ end
6
+
7
+ desc "View tail of unicorn log"
8
+ task :unicorn do
9
+ queue "tail #{unicorn_log} -n 50"
10
+ end
11
+
12
+ desc "View tail of sidekiq log"
13
+ task :sidekiq do
14
+ queue "tail #{sidekiq} -n 50"
15
+ end
16
+
17
+ desc "View tail of nginx error log"
18
+ task :nginx do
19
+ queue "tail /var/log/nginx/error.log -n 50"
20
+ end
21
+
22
+ desc "View tail of nginx access log"
23
+ task :nginx_access do
24
+ queue "tail /var/log/nginx/access.log -n 50"
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ namespace :logrotate do
2
+ desc "Setup logrotate for all log files in log directory"
3
+ task :setup do
4
+ template "logrotate.erb", "/tmp/logrotate"
5
+ queue echo_cmd "sudo mv /tmp/logrotate /etc/logrotate.d/#{application}_#{stage}"
6
+ end
7
+ after "deploy:setup", "logrotate:setup"
8
+ end
@@ -0,0 +1,23 @@
1
+ namespace :nginx do
2
+ desc "Setup nginx configuration for this application"
3
+ task :setup do
4
+ queue 'echo "-----> Creating nginx config"'
5
+ template "nginx_unicorn.erb", "/etc/nginx/sites-enabled/#{application}_#{deploy_server}", :tee, :sudo
6
+ queue 'echo "-----> Deleting nginx default site"' if verbose_mode?
7
+ queue echo_cmd "sudo rm -f /etc/nginx/sites-enabled/default"
8
+ invoke :'nginx:restart'
9
+ end
10
+
11
+ task :remove do
12
+ queue 'echo "-----> Deleting nginx config"'
13
+ queue "sudo rm -f /etc/nginx/sites-enabled/#{application}_#{deploy_server}"
14
+ invoke :'nginx:restart'
15
+ end
16
+
17
+ %w[start stop restart].each do |command|
18
+ desc "#{command} nginx"
19
+ task command do
20
+ queue echo_cmd "sudo service nginx #{command}"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,37 @@
1
+ require "highline/import"
2
+
3
+ namespace :postgresql do
4
+ desc "Generate the database.yml configuration file"
5
+ task :setup do
6
+ get_postgresql_password
7
+ invoke :'postgresql:create_user'
8
+ invoke :'postgresql:create_database'
9
+ template "postgresql.yml.erb", "#{config_path}/database.yml"
10
+ end
11
+
12
+ desc "Create a user for this application."
13
+ task :create_user do
14
+ get_postgresql_password
15
+ queue %{sudo -u postgres psql -c "create user \\"#{postgresql_user}\\" with password '#{postgresql_password}';"; true}
16
+ end
17
+
18
+ desc "Create a database for this application."
19
+ task :create_database do
20
+ queue %Q{sudo -u postgres psql -c "create database \\"#{postgresql_database}\\" owner \\"#{postgresql_user}\\";"; true}
21
+ end
22
+
23
+ desc "Symlink the database.yml file into latest release"
24
+ task :symlink do
25
+ run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
26
+ end
27
+ after "deploy:finalize_update", "postgresql:symlink"
28
+ end
29
+
30
+ def get_postgresql_password
31
+ if !postgresql_password
32
+ pw = ask "Postgresql password: " do |p|
33
+ p.echo = '*'
34
+ end
35
+ set :postgresql_password, pw
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ namespace :unicorn do
2
+ desc "Setup Unicorn initializer and app configuration"
3
+ task :setup do
4
+ queue 'echo "-----> Creating unicorn configuration file"'
5
+ queue "mkdir -p #{shared_path}/config"
6
+ template "unicorn.rb.erb", unicorn_config
7
+
8
+ queue 'echo "-----> Creating unicorn init script"'
9
+ template "unicorn_init.erb", unicorn_script, :tee, :sudo
10
+ queue echo_cmd "sudo chmod +x #{unicorn_script}"
11
+ queue echo_cmd "sudo update-rc.d -f unicorn_#{application}_#{deploy_server} defaults"
12
+ end
13
+
14
+ %w[start stop restart].each do |command|
15
+ desc "#{command.capitalize} unicorn"
16
+ task command do
17
+ queue %{echo "-----> #{command.capitalize} Unicorn"}
18
+ queue echo_cmd "/etc/init.d/unicorn_#{application}_#{deploy_server} #{command}"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,45 @@
1
+ task :setup do
2
+ invoke :'postgresql:setup'
3
+ invoke :'nginx:setup'
4
+ invoke :'unicorn:setup'
5
+ invoke :'logrotate:setup'
6
+ invoke :create_extra_paths
7
+ end
8
+
9
+ task :echo_config do
10
+ queue %{echo #{rails_env}}
11
+ queue %{echo #{deploy_to}}
12
+ queue %{echo #{shared_path}}
13
+ queue %{echo #{shared_paths.first}}
14
+ end
15
+
16
+ task :create_extra_paths do
17
+ queue 'echo "-----> Create configs path"'
18
+ queue echo_cmd "mkdir -p #{config_path}"
19
+
20
+ queue 'echo "-----> Create shared paths"'
21
+ shared_dirs = shared_paths.map { |file| "#{deploy_to}/#{shared_path}/#{file}" }.uniq
22
+ cmds = shared_dirs.map do |dir|
23
+ queue echo_cmd %{mkdir -p "#{dir}"}
24
+ end
25
+
26
+ queue 'echo "-----> Create PID and Sockets paths"'
27
+ cmds = [pids_path, sockets_path].map do |path|
28
+ queue echo_cmd %{mkdir -p #{path}}
29
+ end
30
+ end
31
+
32
+ def template(from, to, *opts)
33
+ templates_path ||= File.expand_path("../../templates", __FILE__)
34
+ queue %{echo "-----> Creating file at #{to} using template #{from}"}
35
+ if opts.include? :tee
36
+ command = ''
37
+ command << 'sudo ' if opts.include? :sudo
38
+ command << %{tee #{to} <<'zzENDOFFILEzz' > /dev/null\n}
39
+ command << %{#{erb("#{templates_path}/#{from}")}}
40
+ command << %{\nzzENDOFFILEzz}
41
+ else
42
+ command = %{echo '#{erb("#{templates_path}/#{from}")}' > #{to}}
43
+ end
44
+ queue command
45
+ end
@@ -0,0 +1,9 @@
1
+ <%= logs_path %>/*.log {
2
+ weekly
3
+ missingok
4
+ rotate 52
5
+ compress
6
+ delaycompress
7
+ notifempty
8
+ copytruncate
9
+ }
@@ -0,0 +1,71 @@
1
+ upstream unicorn_<%= "#{application}_#{deploy_server}" %> {
2
+ server unix:/tmp/unicorn.<%= "#{application}_#{deploy_server}" %>.sock fail_timeout=0;
3
+ }
4
+
5
+ <% if rewrite_www %>
6
+ ##############################
7
+ # Rewrite non-www to www #
8
+ ##############################
9
+ server {
10
+ server_name www.<%= domain_name %>;
11
+ rewrite ^(.*) http://<%= domain_name %>$1 permanent;
12
+ }
13
+ <% end %>
14
+
15
+ ############################
16
+ # Server configuration #
17
+ ############################
18
+ server {
19
+ listen 80<%= " default_server" if default_host %>;
20
+ server_name <%= domain_name %><%= " #{server_ip}" if default_host %>;
21
+ root /home/<%= user %>/<%= application %>/<%= deploy_server %>/current/public;
22
+
23
+ location ^~ /assets/ {
24
+ gzip_static on;
25
+ expires max;
26
+ add_header Cache-Control public;
27
+ }
28
+
29
+ try_files $uri @unicorn;
30
+ location @unicorn {
31
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
32
+ proxy_set_header Host $http_host;
33
+ proxy_redirect off;
34
+ proxy_pass http://unicorn_<%= application %>_<%= deploy_server %>;
35
+ }
36
+
37
+ error_page 500 502 503 504 /500.html;
38
+ client_max_body_size 4G;
39
+ keepalive_timeout 10;
40
+ }
41
+
42
+ <% if include_ssl %>
43
+ server {
44
+ listen 443;
45
+ server_name <%= domain_name %>;
46
+ ssl on;
47
+ ssl_certificate <%= ssl_cert_path %>;
48
+ ssl_certificate_key <%= ssl_cert_key_path %>;
49
+ root /home/<%= user %>/<%= application %>/<%= deploy_server %>/current/public;
50
+
51
+ add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
52
+
53
+ location ^~ /assets/ {
54
+ gzip_static on;
55
+ expires max;
56
+ add_header Cache-Control public;
57
+ }
58
+
59
+ try_files $uri @unicorn;
60
+ location @unicorn {
61
+ proxy_set_header X-Forwarded-Proto $scheme;
62
+ proxy_set_header Host $http_host;
63
+ proxy_redirect off;
64
+ proxy_pass http://unicorn_<%= application %>_<%= deploy_server %>;
65
+ }
66
+
67
+ error_page 500 502 503 504 /500.html;
68
+ client_max_body_size 4G;
69
+ keepalive_timeout 10;
70
+ }
71
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <%= rails_env %>:
2
+ adapter: postgresql
3
+ encoding: unicode
4
+ database: <%= postgresql_database %>
5
+ pool: 5
6
+ username: <%= postgresql_user %>
7
+ password: <%= postgresql_password %>
8
+ host: <%= postgresql_host %>
@@ -0,0 +1,36 @@
1
+ # This example config should work with Ubuntu 12.04+. It
2
+ # allows you to manage multiple Sidekiq instances with
3
+ # Upstart, Ubuntu's native service management tool.
4
+ #
5
+ # See workers.conf for how to manage all Sidekiq instances at once.
6
+ #
7
+ # Save this config as /etc/init/sidekiq.conf then manage sidekiq with:
8
+ # sudo start sidekiq index=0
9
+ # sudo stop sidekiq index=0
10
+ # sudo status sidekiq index=0
11
+ #
12
+ # or use the service command:
13
+ # sudo service sidekiq {start,stop,restart,status}
14
+ #
15
+
16
+ description "Sidekiq Background Worker"
17
+
18
+ # no "start on", we don't want to automatically start
19
+ stop on (stopping workers or runlevel [06])
20
+
21
+ setuid deployer
22
+ setgid deployer
23
+
24
+ respawn
25
+ respawn limit 3 30
26
+
27
+ # TERM and USR1 are sent by sidekiqctl when stopping sidekiq. Without declaring these as normal exit codes, it just respawns.
28
+ normal exit 0 TERM USR1
29
+
30
+ instance $index
31
+
32
+ script
33
+ exec > /tmp/sidekiq 2>&1
34
+ set -x
35
+ exec <%= deploy_to %>/shared/bundle/ruby/2.1.0/bin/sidekiq -i $index -e <%= rails_env %> -P <%= sidekiq_pid %> -L <%= sidekiq_log %>
36
+ end script
@@ -0,0 +1,36 @@
1
+ working_directory "<%= deploy_to %>/<%= current_path %>"
2
+ pid "<%= unicorn_pid %>"
3
+ stderr_path "<%= unicorn_log %>"
4
+ stdout_path "<%= unicorn_log %>"
5
+
6
+ preload_app true
7
+
8
+ listen "/tmp/unicorn.<%= "#{application}_#{deploy_server}" %>.sock"
9
+ worker_processes <%= unicorn_workers %>
10
+ timeout 30
11
+
12
+ before_exec do |server|
13
+ if defined? ActiveRecord::Base
14
+ ActiveRecord::Base.connection.disconnect!
15
+ end
16
+
17
+ old_pid = "#{server.config[:pid]}.oldbin"
18
+
19
+ if File.exists?(old_pid) && server.pid != old_pid
20
+ begin
21
+ Process.kill("QUIT", File.read(old_pid).to_i)
22
+ rescue Errno::ENOENT, Errno::ESRCH
23
+ # Already done
24
+ end
25
+ end
26
+ # ENV['BUNDLE_GEMFILE'] = "<%= deploy_to %>/<%= current_path %>"
27
+ end
28
+
29
+ after_fork do |server, worker|
30
+ if defined? ActiveRecord::Base
31
+ ActiveRecord::Base.establish_connection
32
+ end
33
+ # CHIMNEY.client.connect_to_server
34
+ # child_pid = server.config[:pid].sub(".pid", "#{worker.nr}.pid")
35
+ # system("echo #{Process.pid} > #{child_pid}")
36
+ end
@@ -0,0 +1,84 @@
1
+ #!/bin/sh
2
+ ### BEGIN INIT INFO
3
+ # Provides: unicorn
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 unicorn server
9
+ # Description: Start, stop, restart unicorn 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=<%= deploy_to %>/current
16
+ PID=<%= unicorn_pid %>
17
+ CMD="cd $APP_ROOT; bundle exec unicorn -D -c <%= unicorn_config %> -E <%= rails_env %>"
18
+ AS_USER=<%= unicorn_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,3 @@
1
+ module ClMina
2
+ VERSION = "0.1.0"
3
+ end
data/lib/cl_mina.rb ADDED
@@ -0,0 +1,5 @@
1
+ # require "mina"
2
+ require "cl-mina/version"
3
+
4
+ module ClMina
5
+ end
@@ -0,0 +1,24 @@
1
+ require 'rails/generators'
2
+
3
+ module ClMina
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("../../templates", __FILE__)
7
+
8
+ desc "Creates deploy configuration files."
9
+
10
+ def copy_deploy_rb
11
+ template "deploy.rb", "config/deploy.rb"
12
+ end
13
+
14
+ def copy_deploy_environments
15
+ template "staging.rb", "config/deploy/staging.rb"
16
+ template "production.rb", "config/deploy/production.rb"
17
+ end
18
+
19
+ def copy_defaults
20
+ template "defaults.rb", "config/deploy/defaults.rb"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,38 @@
1
+ task :defaults do
2
+ set_default :user, 'deployer'
3
+ set_default :group, user
4
+ set_default :port, '22'
5
+ set_default :ssh_options, '-t'
6
+ set_default :forward_agent, true
7
+ set_default :term_mode, :nil
8
+ set_default :rails_env, 'staging'
9
+ set_default :shared_paths, ['tmp', 'log', 'public/uploads', 'config']
10
+ set_default :branch, 'staging'
11
+ set_default :deploy_to, "/home/#{user}/#{application}/#{deploy_server}"
12
+
13
+ set_default :sockets_path, "#{deploy_to}/#{shared_path}/tmp/sockets"
14
+ set_default :pids_path, "#{deploy_to}/#{shared_path}/tmp/pids"
15
+ set_default :logs_path, "#{deploy_to}/#{shared_path}/log"
16
+ set_default :config_path, "#{deploy_to}/#{shared_path}/config"
17
+
18
+ set_default :unicorn_socket, "#{sockets_path}/unicorn.sock"
19
+ set_default :unicorn_pid, "#{pids_path}/unicorn.pid"
20
+ set_default :unicorn_config, "#{config_path}/unicorn.rb"
21
+ set_default :unicorn_workers, 1
22
+ set_default :unicorn_log, "#{logs_path}/unicorn.log"
23
+ set_default :unicorn_user, user
24
+ set_default :unicorn_script, "/etc/init.d/unicorn_#{application}_#{deploy_server}"
25
+
26
+ set_default :sidekiq_log, "#{logs_path}/sidekiq.log"
27
+ set_default :sidekiq_pid, "#{pids_path}/sidekiq.pid"
28
+ set_default :sidekiq_script, "/etc/init/sidekiq_#{application}_#{deploy_server}.conf"
29
+
30
+ set_default :nginx_config, "#{nginx_path}/sites-enabled/#{application}_#{deploy_server}"
31
+ set_default :nginx_log_path, "#{deploy_to}/#{shared_path}/log/nginx"
32
+ set_default :nginx_server_name, domain || server_ip
33
+
34
+ set_default :postgresql_host, "localhost"
35
+ set_default :postgresql_user, application
36
+ set_default :postgresql_database, "#{application}_#{deploy_server}"
37
+ set_default :postgresql_pid, "/var/run/postgresql/9.1-main.pid"
38
+ end
@@ -0,0 +1,71 @@
1
+ ###########################################################################
2
+
3
+ #### Setup ####
4
+ # 1. Set "Common settings for all servers" in this file
5
+ # 2. Set environment-specific settings in config/deploy/staging.rb and config/deploy/production.rb
6
+ # 3. Verify defaults in config/deploy/defaults.rb
7
+
8
+ #### Usage ####
9
+ # mina [namespace]:[task] to=[server]
10
+
11
+ #### Usage Examples ####
12
+ # mina setup to=staging
13
+ # mina nginx:setup to=production
14
+ # mina log:rails to=production
15
+ ###########################################################################
16
+
17
+ require 'mina/bundler'
18
+ require 'mina/rails'
19
+ require 'mina/git'
20
+
21
+ load 'config/deploy/defaults.rb'
22
+
23
+ require 'cl_mina/tasks/all'
24
+
25
+ # Load environments from config/deploy
26
+ Dir['config/deploy/*.rb'].each { |f| load f }
27
+
28
+ ###########################################################################
29
+ # Common settings for all servers
30
+ ###########################################################################
31
+
32
+ set :application, "your_app"
33
+ set :application_name, "Human Name for Your App"
34
+ set :domain_name, "example.com"
35
+ set :keep_releases, 5
36
+ set :repository, "user@git.example.com:/your-app.git"
37
+ set :default_server, "staging"
38
+
39
+ # IRC options
40
+ set :send_irc_messages, true
41
+ set :irc_uri, "irc://MinaBot:password@git.example.com:6697/#log"
42
+ set :irc_ssl, true
43
+
44
+ # SSL Options
45
+ set :ssl_cert_path, "/etc/nginx/ssl/your_app.crt"
46
+ set :ssl_cert_key_path, "/etc/nginx/ssl/your_app.key"
47
+
48
+ ###########################################################################
49
+
50
+ set :server, ENV['to'] || default_server
51
+ invoke :"env:#{server}"
52
+
53
+ desc "Deploys the current version to the server."
54
+ task :deploy => :environment do
55
+ deploy do
56
+ invoke :'check:revision'
57
+ invoke :'git:clone'
58
+ invoke :'deploy:link_shared_paths'
59
+ invoke :'bundle:install'
60
+ invoke :'rails:db_migrate'
61
+ invoke :'rails:assets_precompile'
62
+
63
+ to :launch do
64
+ invoke :'unicorn:restart'
65
+ end
66
+
67
+ if send_irc_messages
68
+ invoke :'irc:announce_deploy'
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,15 @@
1
+ namespace :env do
2
+ task :production => [:environment] do
3
+ set :server_ip, '1.1.1.1'
4
+ set :domain, server_ip
5
+ set :deploy_server, 'production'
6
+ set :rails_env, 'production'
7
+ set :branch, 'master'
8
+ set :rewrite_www, false
9
+ set :include_ssl, false
10
+ set :default_host, true
11
+ set :unicorn_workers, 2
12
+
13
+ invoke :defaults
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ namespace :env do
2
+ task :staging => [:environment] do
3
+ set :server_ip, '1.1.1.1'
4
+ set :domain, server_ip
5
+ set :deploy_server, 'staging'
6
+ set :rails_env, 'staging'
7
+ set :branch, 'staging'
8
+ set :rewrite_www, false
9
+ set :include_ssl, false
10
+ set :default_host, true
11
+ set :unicorn_workers, 1
12
+
13
+ invoke :defaults
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ require "generator_spec"
2
+ require "generators/cl_mina/install_generator"
3
+
4
+ describe ClMina::Generators::InstallGenerator, type: :generator do
5
+ destination File.expand_path('../../tmp', __FILE__)
6
+
7
+ before(:all) do
8
+ prepare_destination
9
+ run_generator
10
+ end
11
+
12
+ it "creates a deploy.rb in config" do
13
+ assert_file "config/deploy.rb"
14
+ end
15
+
16
+ it "creates deploy defaults file" do
17
+ assert_file "config/deploy/defaults.rb"
18
+ end
19
+
20
+ it "creates deploy environment files" do
21
+ assert_file "config/deploy/staging.rb"
22
+ assert_file "config/deploy/production.rb"
23
+ end
24
+ end
@@ -0,0 +1,68 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'cl-mina'
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ # The settings below are suggested to provide a good initial experience
9
+ # with RSpec, but feel free to customize to your heart's content.
10
+ =begin
11
+ # These two settings work together to allow you to limit a spec run
12
+ # to individual examples or groups you care about by tagging them with
13
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
14
+ # get run.
15
+ config.filter_run :focus
16
+ config.run_all_when_everything_filtered = true
17
+
18
+ # Many RSpec users commonly either run the entire suite or an individual
19
+ # file, and it's useful to allow more verbose output when running an
20
+ # individual spec file.
21
+ if config.files_to_run.one?
22
+ # Use the documentation formatter for detailed output,
23
+ # unless a formatter has already been configured
24
+ # (e.g. via a command-line flag).
25
+ config.default_formatter = 'doc'
26
+ end
27
+
28
+ # Print the 10 slowest examples and example groups at the
29
+ # end of the spec run, to help surface which specs are running
30
+ # particularly slow.
31
+ config.profile_examples = 10
32
+
33
+ # Run specs in random order to surface order dependencies. If you find an
34
+ # order dependency and want to debug it, you can fix the order by providing
35
+ # the seed, which is printed after each run.
36
+ # --seed 1234
37
+ config.order = :random
38
+
39
+ # Seed global randomization in this process using the `--seed` CLI option.
40
+ # Setting this allows you to use `--seed` to deterministically reproduce
41
+ # test failures related to randomization by passing the same `--seed` value
42
+ # as the one that triggered the failure.
43
+ Kernel.srand config.seed
44
+
45
+ # rspec-expectations config goes here. You can use an alternate
46
+ # assertion/expectation library such as wrong or the stdlib/minitest
47
+ # assertions if you prefer.
48
+ config.expect_with :rspec do |expectations|
49
+ # Enable only the newer, non-monkey-patching expect syntax.
50
+ # For more details, see:
51
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
52
+ expectations.syntax = :expect
53
+ end
54
+
55
+ # rspec-mocks config goes here. You can use an alternate test double
56
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
57
+ config.mock_with :rspec do |mocks|
58
+ # Enable only the newer, non-monkey-patching expect syntax.
59
+ # For more details, see:
60
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
61
+ mocks.syntax = :expect
62
+
63
+ # Prevents you from mocking or stubbing a method that does not exist on
64
+ # a real object. This is generally recommended.
65
+ mocks.verify_partial_doubles = true
66
+ end
67
+ =end
68
+ end
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cl-mina
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Sharpe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: generator_spec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mina
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pg
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: unicorn
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: carrier-pigeon
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: highline
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Designed for use in a fairly specific context, so probably not that versatile.
140
+ email:
141
+ - nathan@cliftonlabs.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - Gemfile
149
+ - LICENSE.txt
150
+ - README.md
151
+ - Rakefile
152
+ - cl-mina.gemspec
153
+ - lib/cl_mina.rb
154
+ - lib/cl_mina/tasks/all.rb
155
+ - lib/cl_mina/tasks/check.rb
156
+ - lib/cl_mina/tasks/db.rb
157
+ - lib/cl_mina/tasks/irc.rb
158
+ - lib/cl_mina/tasks/log.rb
159
+ - lib/cl_mina/tasks/logrotate.rb
160
+ - lib/cl_mina/tasks/nginx.rb
161
+ - lib/cl_mina/tasks/postgresql.rb
162
+ - lib/cl_mina/tasks/unicorn.rb
163
+ - lib/cl_mina/tasks/utility.rb
164
+ - lib/cl_mina/templates/logrotate.erb
165
+ - lib/cl_mina/templates/nginx_unicorn.erb
166
+ - lib/cl_mina/templates/postgresql.yml.erb
167
+ - lib/cl_mina/templates/sidekiq_init.conf.erb
168
+ - lib/cl_mina/templates/unicorn.rb.erb
169
+ - lib/cl_mina/templates/unicorn_init.erb
170
+ - lib/cl_mina/version.rb
171
+ - lib/generators/cl_mina/install_generator.rb
172
+ - lib/generators/templates/defaults.rb
173
+ - lib/generators/templates/deploy.rb
174
+ - lib/generators/templates/production.rb
175
+ - lib/generators/templates/staging.rb
176
+ - spec/generators/intall_generator_spec.rb
177
+ - spec/spec_helper.rb
178
+ homepage: ''
179
+ licenses:
180
+ - MIT
181
+ metadata: {}
182
+ post_install_message:
183
+ rdoc_options: []
184
+ require_paths:
185
+ - lib
186
+ required_ruby_version: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ requirements: []
197
+ rubyforge_project:
198
+ rubygems_version: 2.2.1
199
+ signing_key:
200
+ specification_version: 4
201
+ summary: Common deploy tasks and settings.
202
+ test_files:
203
+ - spec/generators/intall_generator_spec.rb
204
+ - spec/spec_helper.rb
205
+ has_rdoc: