visionbundles 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 67412ca6dbdc960b75b67fa29105fc414b34e272
4
+ data.tar.gz: de90b6eb913091f29ebca51392e57086f3cb3701
5
+ SHA512:
6
+ metadata.gz: 944e53ed1f29cc6cbe5e43286a5314d5fd3d9b9de0c088c87e3daa151b387ec17038f2a50f287bda9b7e3ea56f80ca6e66914d2615c4fbfe7029729649ca779b
7
+ data.tar.gz: ba53c9e616b22f45d059365286540fa7d65a34c60d4ee50c62f3ea3d31b59990d0b88097b98973ecece6bb10769e5759aa7e6dce89299ed834dc56a6db62a68e
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in demrec.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,103 @@
1
+ ## Summary
2
+
3
+ This gem have basic deploy flow tasks for capistrano 2.x, that include templates (nginx / puma / sidekiq). you don't have to write deploy tasks yourself, just configuare it.
4
+
5
+ ## Installation
6
+
7
+
8
+ in your `Gemfile`
9
+
10
+ ```ruby
11
+ group :development do
12
+ gem 'capistrano', '~> 2.15.5'
13
+ gem 'visionbundles', path: '../demrec'
14
+ end
15
+ ```
16
+
17
+ then run `bundle install`
18
+
19
+
20
+ ## deploy.rb
21
+
22
+ ```ruby
23
+ # deploy.rb
24
+
25
+ # add this line on top
26
+ require 'visionbundles'
27
+
28
+ # setup recipes what your need (nginx, puma, db, dev)
29
+ include_recipes :nginx, :puma, :db, :dev
30
+ ```
31
+
32
+ once you include recipes like `db` `nginx` `puma` it will hook tasks in your deploy flow, you just need run `cap deploy:setup` at first, it will setup all you need. but you have to config your recipes setting.
33
+
34
+
35
+ ## Recipes configurations
36
+
37
+ ### nginx
38
+
39
+ ```ruby
40
+ # Nginx (role: :web)
41
+ set :nginx_vhost_domain, 'your.domain' # default is _, means all
42
+ set :nginx_upstream_via_sock_file, false, # if your app server bind a unix socket file, you need setup to true
43
+
44
+ set :nginx_app_servers, ['127.0.0.1:9290'] # your app server ip with port
45
+ ```
46
+
47
+ `cap nginx:start`
48
+ `cap nginx:stop`
49
+ `cap nginx:restart`
50
+
51
+
52
+ ### puma (role: :app)
53
+
54
+ ```ruby
55
+ # Puma
56
+ set :puma_bind_for, :tcp # default is 'sock_file'
57
+ set :puma_bind_to, '127.0.0.1' # default is '0.0.0.0'
58
+ set :puma_bind_port, '9290' # default is 9292
59
+ set :puma_thread_min, 32
60
+ set :puma_thread_max, 32
61
+ set :puma_workers, 3
62
+ ```
63
+
64
+ `cap puma:start`
65
+ `cap puma:stop`
66
+ `cap puma:restart`
67
+
68
+
69
+ ### db (role: :app)
70
+
71
+ If you include this recipe, when you run `cap deploy:setup` will copy database config file from your project `config/database.example.yml` to server site shared path.
72
+
73
+ If database config file exists in remote server, will not replace. so if you change nginx / puma configuration and you want to reset again, you can run `cap deploy:setup` again.
74
+
75
+ ### sidekiq (role: :workers)
76
+
77
+ `cap sidekiq:start`
78
+ `cap sidekiq:stop`
79
+ `cap sidekiq:restart`
80
+
81
+ P.S this task is not test.
82
+
83
+
84
+ ### dev (role: :app)
85
+
86
+ This task provide a command `cap dev:build`, it will invoke tasks `tmp:clear` `log:clear` `db:drop` `db:create` `db:migrate` `db:seed` on remote server.
87
+
88
+ when you run this command, you have to type `Y` to confirm that you really want to run it.
89
+
90
+
91
+ ## Other tools
92
+
93
+ [ubuntu-rails-app-installer](https://github.com/afunction/ubuntu-rails-app-installer) is a server tool for install basic rails production environment and this script write on `shellscript`, you can use it to install nginx, percona database, basic secure setting, firewall, rails deploy user ... etc.
94
+
95
+
96
+ ## Contribution
97
+
98
+ Just send PR to me.
99
+
100
+
101
+
102
+
103
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,44 @@
1
+ require 'erb'
2
+ require 'colorize'
3
+ if defined?(Capistrano)
4
+ def from_template(file)
5
+ abs_path = File.join(File.dirname(__FILE__), file)
6
+ template = File.read(abs_path)
7
+ ERB.new(template).result(binding)
8
+ end
9
+
10
+ def template(erb_source, to_dir, filename)
11
+ mkdir(to_dir)
12
+ compiled_file = "#{to_dir}/#{filename}"
13
+ put from_template(erb_source), compiled_file
14
+ end
15
+
16
+ def remote_file_exists?(path)
17
+ results = []
18
+
19
+ invoke_command("if [ -f '#{path}' ]; then echo -n 'true'; fi") do |ch, stream, out|
20
+ results << (out == 'true')
21
+ end
22
+
23
+ !results.empty?
24
+ end
25
+
26
+ def mkdir(remote_path)
27
+ run "mkdir -p #{remote_path}"
28
+ end
29
+
30
+ def include_recipes(*recipes)
31
+ recipes.each do |recipe|
32
+ require "#{File.dirname(__FILE__)}/recipes/#{recipe}.rb"
33
+ end
34
+ end
35
+
36
+
37
+ def set_default(name, *args, &block)
38
+ set(name, *args, &block) unless exists?(name)
39
+ end
40
+
41
+ def current_server
42
+ capture("echo $CAPISTRANO:HOST$").strip
43
+ end
44
+ end
@@ -0,0 +1,23 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ namespace :db do
3
+ desc "setup database configuration"
4
+ task :setup, roles: :app do
5
+ mkdir("#{shared_path}/config")
6
+ database_setting_path = "#{shared_path}/config/database.yml"
7
+ if remote_file_exists?(database_setting_path)
8
+ puts '[SKIP] Database configuration exists already ...'.colorize(:red)
9
+ else
10
+ puts '[Shared] Setup database configuration files ...'.colorize(:light_cyan)
11
+ put File.read("config/database.example.yml"), database_setting_path
12
+ end
13
+ end
14
+ after 'deploy:setup', 'db:setup'
15
+
16
+ desc "setup database symlink for every time deploy"
17
+ task :symlink_config, roles: :app do
18
+ run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
19
+ end
20
+ after "deploy:finalize_update", "db:symlink_config"
21
+ before 'deploy:symlink', 'deploy:migrate'
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ set_default(:dev_sure_danger_command) {
3
+ Capistrano::CLI.password_prompt "Are you sure run danger command in #{current_server} if yes type Y"
4
+ }
5
+
6
+ namespace :dev do
7
+ desc "dev:build task"
8
+ task :build, roles: :app, except: {no_release: true} do
9
+ if dev_sure_danger_command == 'Y'
10
+ ["tmp:clear", "log:clear", "db:drop", "db:create", "db:migrate", "db:seed"].each do |rake_command|
11
+ run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake #{rake_command}"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ set_default(:nginx_vhost_domain, '_')
3
+ set_default(:nginx_app_timeout, nil)
4
+ set_default(:nginx_upstream_via_sock_file, true)
5
+ set_default(:nginx_app_servers) {
6
+ nginx_upstream_via_sock_file ? "/tmp/#{application}.sock" : "127.0.0.1:9292"
7
+ }
8
+
9
+ namespace :nginx do
10
+ desc "setup nginx vhost config"
11
+ task :setup, roles: :web do
12
+ puts '[Nginx] Setup vhost configuration files ...'.colorize(:light_cyan)
13
+ template "templates/nginx/nginx.conf.erb", "#{shared_path}/nginx", "vhost.conf"
14
+ sudo "ln -nfs #{shared_path}/nginx/vhost.conf /etc/nginx/sites-enabled/#{application}"
15
+ end
16
+ after 'deploy:setup', 'nginx:setup'
17
+
18
+ %w[start stop restart reload].each do |command|
19
+ desc "#{command} nginx server"
20
+ task command, roles: :web do
21
+ sudo "service nginx #{command}"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ set_default(:puma_bind_for, 'sock_file') # sock_file / tcp
3
+ set_default(:puma_bind_to, '0.0.0.0')
4
+ set_default(:puma_bind_port, '9292')
5
+ set_default(:puma_thread_min, 1)
6
+ set_default(:puma_thread_max, 16)
7
+ set_default(:puma_workers, 0)
8
+
9
+ namespace :puma do
10
+ desc "Setup Puma Scripts"
11
+ task :setup do
12
+ puts '[Puma] copying the config'.colorize(:light_cyan)
13
+ template "templates/puma/config.erb", "#{shared_path}/puma", "config.rb"
14
+ end
15
+ after 'deploy:setup', 'puma:setup'
16
+
17
+ %w[start stop].each do |command|
18
+ desc "#{command} puma server"
19
+ task command, roles: :app do
20
+ run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec pumactl -F #{shared_path}/puma/config.rb #{command}"
21
+ end
22
+ end
23
+ desc "restart puma server"
24
+ task "restart", roles: :app do
25
+ %w(stop start).each do |command|
26
+ run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec pumactl -F #{shared_path}/puma/config.rb #{command}"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,10 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ namespace :sidekiq do
3
+ %w[start stop restart killall].each do |command|
4
+ desc "#{command} sidekiq"
5
+ task command, roles: :workers, except: {no_release: true} do
6
+ run "cd #{current_path}/scripts/ && RAILS_ENV=#{rails_env} ./workers.sh #{command}"
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,50 @@
1
+ upstream <%= "app_#{application}" %> {
2
+ <%
3
+ nginx_timeout_string = ""
4
+ nginx_timeout_string = unless nginx_app_timeout.nil?
5
+ "fail_timeout=#{nginx_app_timeout}"
6
+ end
7
+ %>
8
+
9
+ <% if nginx_upstream_via_sock_file %>
10
+ server unix:<%= nginx_app_servers %> <%= nginx_timeout_string %>;
11
+ <% else %>
12
+
13
+ <% nginx_app_servers.each do |server| %>
14
+ server <%= server %> <%= nginx_timeout_string %>;
15
+ <% end %>
16
+ <% end %>
17
+ }
18
+
19
+ server {
20
+ listen 80;
21
+ server_name <%= nginx_vhost_domain %>;
22
+
23
+ root <%= "#{deploy_to}/current/public" %>;
24
+
25
+ location ^~ /assets/ {
26
+ gzip_static on;
27
+ expires max;
28
+ add_header Cache-Control public;
29
+ open_file_cache max=1000 inactive=500s;
30
+ open_file_cache_valid 600s;
31
+ open_file_cache_errors on;
32
+ break;
33
+ }
34
+
35
+ try_files $uri/index.html $uri @puma;
36
+
37
+ location @puma {
38
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
39
+ proxy_set_header Host $http_host;
40
+ proxy_set_header X-Real-IP $remote_addr;
41
+ proxy_set_header Client-IP $remote_addr;
42
+ proxy_set_header X-Forwarded-Proto $scheme;
43
+ proxy_redirect off;
44
+ proxy_pass http://<%= "app_#{application}" %>;
45
+ }
46
+
47
+ error_page 500 502 503 504 /500.html;
48
+ client_max_body_size 4G;
49
+ keepalive_timeout 10;
50
+ }
@@ -0,0 +1,173 @@
1
+ <% app_root = "/home/rails/apps/#{application}/current" %>
2
+ # The directory to operate out of.
3
+ #
4
+ # The default is the current directory.
5
+ #
6
+ directory '<%= app_root %>'
7
+
8
+ # Use an object or block as the rack application. This allows the
9
+ # config file to be the application itself.
10
+ #
11
+ # app do |env|
12
+ # puts env
13
+ #
14
+ # body = 'Hello, World!'
15
+ #
16
+ # [200, { 'Content-Type' => 'text/plain', 'Content-Length' => body.length.to_s }, [body]]
17
+ # end
18
+
19
+ # Load “path” as a rackup file.
20
+ #
21
+ # The default is “config.ru”.
22
+ #
23
+ # rackup '/u/apps/lolcat/config.ru'
24
+
25
+ # Set the environment in which the rack's app will run. The value must be a string.
26
+ #
27
+ # The default is “development”.
28
+ #
29
+ # environment 'production'
30
+
31
+ # Daemonize the server into the background. Highly suggest that
32
+ # this be combined with “pidfile” and “stdout_redirect”.
33
+ #
34
+ # The default is “false”.
35
+ #
36
+ daemonize
37
+ # daemonize false
38
+
39
+ # Store the pid of the server in the file at “path”.
40
+ #
41
+ pidfile "<%= app_root %>/tmp/pids/puma.pid"
42
+
43
+ # Use “path” as the file to store the server info state. This is
44
+ # used by “pumactl” to query and control the server.
45
+ #
46
+ # state_path '/u/apps/lolcat/tmp/pids/puma.state'
47
+
48
+ # Redirect STDOUT and STDERR to files specified. The 3rd parameter
49
+ # (“append”) specifies whether the output is appended, the default is
50
+ # “false”.
51
+ #
52
+ stdout_redirect "<%= app_root %>/log/puma_stdout.log", "<%= app_root %>/log/puma_stderr.log"
53
+ # stdout_redirect '/u/apps/lolcat/log/stdout', '/u/apps/lolcat/log/stderr'
54
+ # stdout_redirect '/u/apps/lolcat/log/stdout', '/u/apps/lolcat/log/stderr', true
55
+
56
+ # Disable request logging.
57
+ #
58
+ # The default is “false”.
59
+ #
60
+ # quiet
61
+
62
+ # Configure “min” to be the minimum number of threads to use to answer
63
+ # requests and “max” the maximum.
64
+ #
65
+ # The default is “0, 16”.
66
+ #
67
+ threads <%= puma_thread_min %>, <%= puma_thread_max %>
68
+
69
+ # Bind the server to “url”. “tcp://”, “unix://” and “ssl://” are the only
70
+ # accepted protocols.
71
+ #
72
+ # The default is “tcp://0.0.0.0:9292”.
73
+ #
74
+ <%=
75
+ case puma_bind_for
76
+ when :sock_file
77
+ %(bind "unix:///tmp/#{application}.sock")
78
+ when :tcp
79
+ if puma_bind_to.is_a? String
80
+ %(bind 'tcp://#{puma_bind_to}:#{puma_bind_port}')
81
+ elsif puma_bind_to.is_a? Hash
82
+ puma_bind_ip[current_server] ||= '0.0.0.0'
83
+ %(bind 'tcp://#{puma_bind_ip[current_server]}:#{puma_bind_port}')
84
+ end
85
+ end
86
+ %>
87
+ # bind 'tcp://0.0.0.0:9293'
88
+ # bind 'unix:///var/run/puma.sock?umask=0777'
89
+ # bind 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
90
+
91
+ # Instead of “bind 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'” you
92
+ # can also use the “ssl_bind” option.
93
+ #
94
+ # ssl_bind '127.0.0.1', '9292', { key: path_to_key, cert: path_to_cert }
95
+
96
+ # Code to run before doing a restart. This code should
97
+ # close log files, database connections, etc.
98
+ #
99
+ # This can be called multiple times to add code each time.
100
+ #
101
+ # on_restart do
102
+ # puts 'On restart...'
103
+ # end
104
+
105
+ # Command to use to restart puma. This should be just how to
106
+ # load puma itself (ie. 'ruby -Ilib bin/puma'), not the arguments
107
+ # to puma, as those are the same as the original process.
108
+ #
109
+ # restart_command '/u/app/lolcat/bin/restart_puma'
110
+
111
+ # === Cluster mode ===
112
+
113
+ # How many worker processes to run.
114
+ #
115
+ # The default is “0”.
116
+ #
117
+ workers <%= puma_workers %>
118
+
119
+ # Code to run when a worker boots to setup the process before booting
120
+ # the app.
121
+ #
122
+ # This can be called multiple times to add hooks.
123
+ #
124
+
125
+ on_worker_boot do
126
+ ActiveSupport.on_load(:active_record) do
127
+ ActiveRecord::Base.establish_connection
128
+ end
129
+ end
130
+
131
+ # Code to run when a worker boots to setup the process after booting
132
+ # the app.
133
+ #
134
+ # This can be called multiple times to add hooks.
135
+ #
136
+ # after_worker_boot do
137
+ # puts 'On worker boot...'
138
+ # end
139
+
140
+ # Allow workers to reload bundler context when master process is issued
141
+ # a USR1 signal. This allows proper reloading of gems while the master
142
+ # is preserved across a phased-restart. (incompatible with preload_app)
143
+ # (off by default)
144
+
145
+ # prune_bundler
146
+
147
+ # Preload the application before starting the workers; this conflicts with
148
+ # phased restart feature. (off by default)
149
+
150
+ preload_app!
151
+
152
+ # Additional text to display in process listing
153
+ #
154
+ # tag 'gambling'
155
+
156
+ # Change the default timeout of workers
157
+ #
158
+ # worker_timeout 60
159
+
160
+ # === Puma control rack application ===
161
+
162
+ # Start the puma control rack application on “url”. This application can
163
+ # be communicated with to control the main server. Additionally, you can
164
+ # provide an authentication token, so all requests to the control server
165
+ # will need to include that token as a query parameter. This allows for
166
+ # simple authentication.
167
+ #
168
+ # Check out https://github.com/puma/puma/blob/master/lib/puma/app/status.rb
169
+ # to see what the app has available.
170
+ #
171
+ # activate_control_app 'unix:///var/run/pumactl.sock'
172
+ # activate_control_app 'unix:///var/run/pumactl.sock', { auth_token: '12345' }
173
+ # activate_control_app 'unix:///var/run/pumactl.sock', { no_token: true }
@@ -0,0 +1,3 @@
1
+ module Visionbundles
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,2 @@
1
+ require "visionbundles/version"
2
+ require "visionbundles/base"
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "visionbundles/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "visionbundles"
7
+ s.version = Visionbundles::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.summary = %q{common deploy flow tasks for capistrano 2.x.x}
10
+ s.description = %q{nginx, puma, sidekiq, deploy flow}
11
+
12
+ s.required_ruby_version = ">= 1.8.7"
13
+ s.required_rubygems_version = ">= 1.3.6"
14
+
15
+ s.authors = ["Eddie Li"]
16
+ s.email = ["eddie@visionbundles.com"]
17
+ s.homepage = "https://github.com/afunction/visionbundles"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.require_paths = ["lib"]
22
+
23
+ s.license = 'MIT'
24
+
25
+ s.add_dependency 'colorize', '~> 0'
26
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: visionbundles
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Eddie Li
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: nginx, puma, sidekiq, deploy flow
28
+ email:
29
+ - eddie@visionbundles.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - README.md
37
+ - Rakefile
38
+ - lib/visionbundles.rb
39
+ - lib/visionbundles/base.rb
40
+ - lib/visionbundles/recipes/db.rb
41
+ - lib/visionbundles/recipes/dev.rb
42
+ - lib/visionbundles/recipes/nginx.rb
43
+ - lib/visionbundles/recipes/puma.rb
44
+ - lib/visionbundles/recipes/sidekiq.rb
45
+ - lib/visionbundles/templates/nginx/nginx.conf.erb
46
+ - lib/visionbundles/templates/puma/config.erb
47
+ - lib/visionbundles/version.rb
48
+ - visionbundles.gemspec
49
+ homepage: https://github.com/afunction/visionbundles
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.7
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 1.3.6
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.3.0
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: common deploy flow tasks for capistrano 2.x.x
73
+ test_files: []