visionbundles 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +8 -0
  3. data/README.md +24 -229
  4. data/Rakefile +12 -0
  5. data/lib/generators/install_generator.rb +42 -0
  6. data/lib/generators/security_generator.rb +44 -0
  7. data/lib/generators/templates/Capfile +3 -0
  8. data/lib/generators/templates/database.yml +26 -0
  9. data/lib/generators/templates/deploy_multiple.rb +59 -0
  10. data/lib/generators/templates/deploy_single.rb +49 -0
  11. data/lib/visionbundles.rb +2 -1
  12. data/lib/visionbundles/asset_sync.rb +4 -0
  13. data/lib/visionbundles/helpers.rb +2 -0
  14. data/lib/visionbundles/helpers/configuration.rb +41 -0
  15. data/lib/visionbundles/helpers/git.rb +10 -0
  16. data/lib/visionbundles/helpers/logger.rb +27 -0
  17. data/lib/visionbundles/helpers/recipes.rb +17 -0
  18. data/lib/visionbundles/helpers/servers.rb +32 -0
  19. data/lib/visionbundles/helpers/templates.rb +19 -0
  20. data/lib/visionbundles/rails.rb +7 -0
  21. data/lib/visionbundles/recipes/db.rb +20 -34
  22. data/lib/visionbundles/recipes/dev.rb +0 -2
  23. data/lib/visionbundles/recipes/fast_assets.rb +25 -3
  24. data/lib/visionbundles/recipes/nginx.rb +3 -1
  25. data/lib/visionbundles/recipes/preconfig.rb +69 -0
  26. data/lib/visionbundles/recipes/preconfig/helpers.rb +28 -0
  27. data/lib/visionbundles/recipes/puma.rb +7 -8
  28. data/lib/visionbundles/recipes/secret.rb +14 -37
  29. data/lib/visionbundles/recipes/valid.rb +52 -0
  30. data/lib/visionbundles/templates/puma/config.erb +9 -7
  31. data/lib/visionbundles/version.rb +1 -1
  32. data/todo.md +15 -0
  33. data/visionbundles.gemspec +3 -2
  34. metadata +38 -5
  35. data/lib/visionbundles/base.rb +0 -100
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d815ace0686f65fa24871eb6cdcbc7b49ea2adc7
4
- data.tar.gz: 563de8f20eba78ffa3df7d0a8e2638046ec4dfd1
3
+ metadata.gz: d0c3ca7386446d5ff3f50ab5bc193f4111f489b5
4
+ data.tar.gz: 50c01e9a716dcbdd13f595dd8d31d86fc8cc9734
5
5
  SHA512:
6
- metadata.gz: 0d5f4c7066cb7696e9f28272b2f3e757089235c2b1e9e8aab17b149903e379c7635fd2b1a1098eabb5456938a7da0ce1f71e8e77743dc8b7270178352b680b90
7
- data.tar.gz: 51aa5a97884b704a0ede9af6e2096b8b52e1200302dceb80ff0893fd4083389034391d2eca2ecbb96522bf6bba3220ddf84f67dc25b5ed2f524400f28d79b8fd
6
+ metadata.gz: accce3319314d222393e047e5539966277c8dcc929ffa9bc19fe908a4f082a5a10bc2e036a2db0424d6c2ca69659444b57b3894848faf701b98ee5baca0bdc99
7
+ data.tar.gz: 1c7a12503752b49d768d5013fd17ab2ac9a1e860dbf34045606cafb0c2201b5b7e2c948fcdc52d86cec3864fea0718cd39f8f58b870495ad847f5e7a14748113
data/CHANGELOG ADDED
@@ -0,0 +1,8 @@
1
+ 0.3.0
2
+
3
+ * Add base valid task `deploy:valid` include git, and remote server connection
4
+ * Add db valid task called `db:valid` to check if all server have permission to access db
5
+ * Add secret file rails version checker (4.0 use `secret_token.rb`, 4.1 use `secrets.yml`)
6
+ * Add fast_assets valid task, it valid if local commit same as deploying version (because compile assets locally)
7
+ * Add more options for puma setting (preload_app, puma_worker_timeout, puma_prune_bundler, .. etc)
8
+ * Change method `config_from_yaml` to `load_config_from`
data/README.md CHANGED
@@ -1,13 +1,16 @@
1
+ [![Code Climate](https://codeclimate.com/github/afunction/visionbundles/badges/gpa.svg)](https://codeclimate.com/github/afunction/visionbundles) [![security](https://hakiri.io/github/afunction/visionbundles/master.svg)](https://hakiri.io/github/afunction/visionbundles/master)
2
+
1
3
  ## Summary
2
4
 
3
- This gem with basic deploy flow tasks for capistrano 2.15.5, you don't have to write deploy tasks yourself, just configuare it. And that includes recipes:
5
+ This gem is the basic deploy recipes for capistrano 2.15.5, the recipes includes tasks hooks around capistrano deploy tasks, and configuration template for each service (like nginx, puma .. etc), you don't have to write deploy tasks yourself, just configure it. And below is all recipes:
4
6
 
5
7
  1. nginx
6
8
  2. puma
7
- 3. db
8
- 4. secret
9
- 5. fast_assets
10
- 6. dev
9
+ 3. preconfig (new feature)
10
+ 4. db
11
+ 5. secret
12
+ 6. fast_assets
13
+ 7. dev
11
14
 
12
15
  ## Installation
13
16
 
@@ -15,237 +18,24 @@ in your `Gemfile`
15
18
 
16
19
  ```ruby
17
20
  group :development do
18
- gem 'capistrano', '~> 2.15.5'
19
- gem 'visionbundles'
20
- # or use latest source
21
- # gem 'visionbundles', github: 'afunction/visionbundles'
21
+ gem 'capistrano', '~> 2.15.5', require: false
22
+ gem 'visionbundles', '~> 0.2.0'
23
+ # gem 'visionbundles', github: 'afunction/visionbundles' # or use latest source
22
24
  end
23
25
  ```
24
26
 
25
27
  then run `bundle install`
26
28
 
27
29
 
28
- ## deploy.rb
29
-
30
- ```ruby
31
- # Add this line on top
32
- require 'visionbundles'
33
-
34
- # Setup recipes what you need (include option nginx, puma, db, dev, fast_assets, secret)
35
- include_recipes :nginx, :puma, :db, :dev
36
- ```
37
-
38
- Once you include recipes like `db` `nginx` `puma` ... etc, it will hook tasks in your deploy flow, and you need to run `cap deploy:setup` at first time, it will setup all you need. but you have to config your recipes setting before.
39
-
40
-
41
- ## Recipe configurations
42
-
43
- ### nginx (role: :web)
44
-
45
- ```ruby
46
- set :nginx_vhost_domain, 'your.domain' # default is _, means all
47
- set :nginx_upstream_via_sock_file, false, # if your app server bind a unix socket file, you need setup to true
48
-
49
- set :nginx_app_servers, ['127.0.0.1:9290'] # your app server ip with port
50
- ```
51
-
52
- `cap nginx:start`
53
- `cap nginx:stop`
54
- `cap nginx:restart`
55
-
56
- Source: https://github.com/afunction/visionbundles/blob/master/lib/visionbundles/recipes/nginx.rb
57
-
58
-
59
- ### puma (role: :app)
60
-
61
- If you have multiple app server, you should setup `puma_bind_to` to `0.0.0.0`, and use other way to avoid directly connection to your app server form internet.
62
-
63
- ```ruby
64
- set :puma_bind_for, :tcp # default is 'sock_file'
65
- set :puma_bind_to, '127.0.0.1' # default is '0.0.0.0'
66
- set :puma_bind_port, '9290' # default is 9292
67
- set :puma_thread_min, 32
68
- set :puma_thread_max, 32
69
- set :puma_workers, 3
70
- ```
71
-
72
- `cap puma:start`
73
- `cap puma:stop`
74
- `cap puma:restart`
75
-
76
- Source: https://github.com/afunction/visionbundles/blob/master/lib/visionbundles/recipes/puma.rb
77
-
78
- ### fast_assets (locally)
79
-
80
- If you have multiple app servers, or separate servers between app and web roles, or your assets on CDN, you may concern which server is resiponsible to compile assets and upload to servers.
81
-
82
-
83
- This task will use least resource to compile assets and upload to remote server. it combine [Gem - AssetSync](https://github.com/rumblelabs/asset_sync) and compile assets locally instead of capistrano precompile task.
84
-
85
-
86
- **Without CDN**
87
-
88
- You don't have to configure it, just add `fast_assets` recipe in your `deploy.rb`, it will compile assets locally, and upload `manifest file` to servers of app role and `assets files` to servers of web role.
89
-
90
-
91
- **With CDN**
92
-
93
- After include `fast_assets`recipe, you have to config your CDN access token, it will use [asset_sync](https://github.com/rumblelabs/asset_sync) to upload your assets to cloud, the example below using AWS S3:
94
-
95
- ```ruby
96
- # CDN
97
- set :cdn, {
98
- fog_provider: 'AWS',
99
- fog_directory: 'your_bucket_name',
100
- aws_access_key_id: 'your aws id', # create from IAM
101
- aws_secret_access_key: 'your aws secret token',
102
- fog_region: 'ap-northeast-1' # bucket region
103
- }
104
- ```
105
-
106
- Once you choose upload assets to CDN, deploy task will NOT upload asset files to your web server, because web dose not need it. For more details about CDN configuration, please visit: https://github.com/rumblelabs/asset_sync
107
-
108
- Source: https://github.com/afunction/visionbundles/blob/master/lib/visionbundles/recipes/fast_assets.rb
109
-
110
- ### db (role: :app)
111
-
112
- To avoid setting up db configuration manually, setup task will copy `config/database.production.yml` to your servers with `roles: :app`, and you can create the file with REAL production db configuration, and list the file to `.gitignore` to avoid sensitive data in your source control.
113
-
114
-
115
- **cap db:reset_config**
116
-
117
- The setup task will not overwide db config file if exists in remote server, but i also can use `cap db:reset_config` to replace your remote db config from local.
30
+ ## Wiki
118
31
 
119
- Source: https://github.com/afunction/visionbundles/blob/master/lib/visionbundles/recipes/db.rb
120
-
121
- ### Secret (role: :app)
122
-
123
- Setup task will copy `initializers/secret_token.production.rb` to your servers which roles is app, like db recipes, you should create the file, and list in `.gitignore`.
124
-
125
- **cap secret:reset_config**
126
-
127
- Just like `db:reset_config` functionality.
128
-
129
- Source: https://github.com/afunction/visionbundles/blob/master/lib/visionbundles/recipes/secret.rb
130
-
131
- ### dev (role: :app)
132
-
133
- 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 the server (same server which runs db:migrate).
134
-
135
- This command will show a prompt box to confirm that you really want to do it.
136
-
137
- Source: https://github.com/afunction/visionbundles/blob/master/lib/visionbundles/recipes/dev.rb
138
-
139
-
140
- ## Maintain multiple deploy settings by yaml
141
-
142
- You may think server architecture details should not in source control, or you often update to different website in same project. you can use yaml easy to switch configuration. below is the example:
143
-
144
-
145
- **deploy.rb**
146
-
147
- ```ruby
148
- config_from_yaml 'deploy/config.yml', :my_testing_production
149
- ```
150
-
151
- **deploy/config.yml**
152
-
153
- ```yaml
154
- # Nginx
155
- my_testing_production:
156
- servers:
157
- - host: '1.1.1.1'
158
- roles:
159
- - :web
160
- - :app
161
- - :db
162
- opts:
163
- primary: yes
164
- - host: '2.2.2.2'
165
- roles: :app
166
- config:
167
- nginx_vhost_domain: 'my.domain.com'
168
- nginx_upstream_via_sock_file: no
169
- nginx_app_servers:
170
- - 192.168.1.3:9290
171
- - 192.168.1.4:9290
172
- # Puma
173
- puma_bind_for: :tcp
174
- puma_bind_port: '9290'
175
- puma_thread_min: 32
176
- puma_thread_max: 32
177
- puma_workers: 3
178
- cdn:
179
- fog_provider: 'AWS'
180
- fog_directory: ''
181
- aws_access_key_id: ''
182
- aws_secret_access_key: ''
183
- fog_region: 'ap-northeast-1'
184
-
185
- ```
186
-
187
-
188
- ### Full setting example
189
-
190
- in `Capfile`
191
-
192
- ```ruby
193
- load 'deploy'
194
- load 'deploy/assets'
195
- load 'config/deploy'
196
- ```
197
-
198
- in `deploy.rb`
199
-
200
- ```ruby
201
- require 'bundler/capistrano'
202
- require 'rvm/capistrano'
203
- require 'visionbundles'
204
-
205
- # RVM Settings
206
- set :rvm_ruby_string, '2.1.0'
207
- set :rvm_type, :user
208
- $:.unshift(File.expand_path('./lib', ENV['rvm_path']))
209
-
210
- # Recipes Settings
211
- include_recipes :nginx, :puma, :db, :dev
212
-
213
- # Nginx
214
- set :nginx_vhost_domain, '111.222.33.44'
215
- set :nginx_upstream_via_sock_file, false
216
- set :nginx_app_servers, ['127.0.0.1:9290']
217
-
218
- # Puma
219
- set :puma_bind_for, :tcp
220
- set :puma_bind_to, '127.0.0.1'
221
- set :puma_bind_port, '9290'
222
- set :puma_thread_min, 32
223
- set :puma_thread_max, 32
224
- set :puma_workers, 3
225
-
226
- # Role Settings
227
- server '11.222.33.44', :web, :app, :db, primary: true
228
-
229
- # Capistrano Base Setting
230
- set :application, 'my-project-name'
231
- set :user, 'rails'
232
- set :deploy_to, "/home/#{user}/apps/#{application}"
233
- set :deploy_via, :remote_cache
234
- set :use_sudo, false
235
- set :rails_env, 'test'
236
-
237
- # Git Settings
238
- set :scm, :git
239
- set :repository, "git@github.com:username/#{application}.git"
240
- set :branch, 'develop'
241
-
242
- # Others
243
- default_run_options[:pty] = true
244
- ssh_options[:forward_agent] = true
245
-
246
- # Deploy Flow
247
- after 'deploy', 'deploy:cleanup' # keep only the last 5 releases
248
- ```
32
+ * [Getting Started](https://github.com/afunction/visionbundles/wiki/Getting-Started)
33
+ * [Recipe - nginx](https://github.com/afunction/visionbundles/wiki/%5BRecipe%5D-nginx)
34
+ * [Recipe - puma](https://github.com/afunction/visionbundles/wiki/%5BRecipe%5D-puma)
35
+ * [Recipe - fast_assets (compile assets locally)](https://github.com/afunction/visionbundles/wiki/%5BRecipe%5D-fast_assets)
36
+ * [Recipe - preconfig](https://github.com/afunction/visionbundles/wiki/%5BRecipe%5D--preconfig)
37
+ * [Recipe - db, dev](https://github.com/afunction/visionbundles/wiki/%5BRecipe%5D-db,-dev)
38
+ * [Using yaml to define your stage with deploy.rb](https://github.com/afunction/visionbundles/wiki/Using-yaml-to-define-your-stage-with-deploy.rb)
249
39
 
250
40
 
251
41
  ## Other tools
@@ -257,4 +47,9 @@ after 'deploy', 'deploy:cleanup' # keep only the last 5 releases
257
47
 
258
48
  Just send PR to me.
259
49
 
50
+ # Contact me
51
+
52
+ eddie [at] visionbundles [dot] com
53
+
260
54
 
55
+ ![Visionbundles Int'l Ltd.](http://www.visionbundles.com/assets/logo-927ee5bf7632c30e2642ddf03b607e42.png)
data/Rakefile CHANGED
@@ -1 +1,13 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
1
2
  require 'bundler/gem_tasks'
3
+ require 'visionbundles/version'
4
+
5
+ task :build do
6
+ system "gem build visionbundles.gemspec"
7
+ end
8
+
9
+ task :release => :build do
10
+ gem_name = "visionbundles-#{Visionbundles::VERSION}.gem"
11
+ system "gem push #{gem_name}"
12
+ system "rm -rf #{gem_name}"
13
+ end
@@ -0,0 +1,42 @@
1
+ require 'rails/generators'
2
+ module Visionbundles
3
+ module Generators
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path("../templates", __FILE__)
6
+ argument :deploy_template, type: :string, default: "single"
7
+
8
+ # check the argument deploy_template, should be single or mutiple
9
+ def check
10
+ unless %w(single multiple).include?(deploy_template)
11
+ puts "You have to choice a template: single or multiple"
12
+ puts "\trails g visionbundles:install single"
13
+ puts "\trails g visionbundles:install mutiple"
14
+ exit
15
+ end
16
+ end
17
+
18
+ # copy the capistrano setting from template
19
+ def copy_deploy_template
20
+ copy_file "deploy_#{deploy_template}.rb", "config/deploy.rb"
21
+ end
22
+
23
+ # add gem for capistrano + rvm
24
+ def add_capistrano_rvm
25
+ unless File.readlines("Gemfile").grep(/rvm-capistrano/).any?
26
+ gem_group :development do
27
+ gem 'rvm-capistrano'
28
+ end
29
+ end
30
+ end
31
+
32
+ # copy exists database config to predefine folder
33
+ def create_database_example_config
34
+ if File.exists?('config/database.yml')
35
+ copy_file "#{Rails.root}/config/database.example.yml", "preconfig/database.yml"
36
+ else
37
+ copy_file "database.yml", "preconfig/database.yml"
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,44 @@
1
+ require 'rails/generators'
2
+ module Visionbundles
3
+ module Generators
4
+ class SecurityGenerator < Rails::Generators::Base
5
+ source_root File.expand_path("../templates", __FILE__)
6
+
7
+ # check and add first commit for this project
8
+ def git_init
9
+ run 'git init; git add .; git commit -m "init project"' unless File.exists?('.git')
10
+ run 'git reset .'
11
+ end
12
+
13
+ # copy exists database config to predefine folder
14
+ def create_database_example_config
15
+ if File.exists?('config/database.yml')
16
+ copy_file "#{Rails.root}/config/database.yml", "config/database.example.yml"
17
+ copy_file "#{Rails.root}/config/database.example.yml", "preconfig/database.yml"
18
+ else
19
+ copy_file "database.yml", "preconfig/database.yml"
20
+ copy_file "database.yml", "config/database.example.yml"
21
+ end
22
+ run 'git add config/database.example.yml'
23
+ run 'git commit -m "create a database config template!"'
24
+ end
25
+
26
+ # check and ignore database config out of source control
27
+ def out_of_database_config_from_source_control
28
+ if `git ls-files config/database.yml` != ''
29
+ run 'git rm config/database.yml'
30
+ run 'git commit -m "remove database configuration out of source control!"'
31
+ end
32
+
33
+ append_file ".gitignore" do
34
+ <<-eos
35
+ /preconfig/ # production preconfig folder
36
+ /config/database.yml" # should not in source control
37
+ eos
38
+ end
39
+ run 'git add .gitignore'
40
+ run 'git commit -m "git ignore files: preconfig, database.yml"'
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ load 'deploy'
2
+ load 'deploy/assets'
3
+ load 'config/deploy'
@@ -0,0 +1,26 @@
1
+ development:
2
+ adapter: mysql2
3
+ encoding: utf8
4
+ database: your_database_name_development
5
+ pool: 5
6
+ username: root
7
+ password:
8
+ host: ''
9
+
10
+ test:
11
+ adapter: mysql2
12
+ encoding: utf8
13
+ database: your_database_name_test
14
+ pool: 5
15
+ username: root
16
+ password:
17
+ host: ''
18
+
19
+ production:
20
+ adapter: mysql2
21
+ encoding: utf8
22
+ database: your_database_name_production
23
+ pool: 50
24
+ username: root
25
+ password:
26
+ host: ''
@@ -0,0 +1,59 @@
1
+ require 'bundler/capistrano'
2
+ require 'rvm/capistrano'
3
+ require 'visionbundles'
4
+
5
+ # RVM Settings
6
+ set :rvm_ruby_string, '2.1.0'
7
+ set :rvm_type, :user
8
+ $:.unshift(File.expand_path('./lib', ENV['rvm_path']))
9
+
10
+ # Recipes Included
11
+ # Source: https://github.com/afunction/visionbundles/blob/master/lib/visionbundles/recipes
12
+ include_recipes :nginx, :puma, :db, :dev, :fast_assets
13
+ # :fast_assets recipes will compile assets locally then upload assets files to servers
14
+ # So if you use :fast_assets you have to make sure your local repository commit id same as you deployed.
15
+
16
+ # Nginx
17
+ # Please change `nginx_app_servers` to your app servers ip, and make sure your web server have permission to
18
+ # connect to the ips that you set.
19
+ # Source: https://github.com/afunction/visionbundles/blob/master/lib/visionbundles/recipes/nginx.rb
20
+ set :nginx_vhost_domain, 'www.domain.com' # your domain that to nginx.
21
+ set :nginx_upstream_via_sock_file, false
22
+ set :nginx_app_servers, [ '192.168.1.100:9290', '192.168.1.101:9290' ] # upstream will point to app server.
23
+
24
+
25
+ # Puma
26
+ # This setting will bind puma service to each ip address (include public ip)
27
+ # for security you may using firewall to make sure people cannot connect to your app server directly.
28
+ # Source: https://github.com/afunction/visionbundles/blob/master/lib/visionbundles/recipes/puma.rb
29
+ set :puma_bind_for, :tcp
30
+ set :puma_bind_to, '0.0.0.0'
31
+ set :puma_bind_port, '9290'
32
+ set :puma_thread_min, 32
33
+ set :puma_thread_max, 32
34
+ set :puma_workers, 3
35
+
36
+ # Role Settings
37
+ # The db roles mean the app server which you specify the run the db operation like `db:migrate`.
38
+ server '11.22.33.44', :web
39
+ server '22.33.44.55', :app
40
+ server '33.44.55.66', :app, :db, primary: true
41
+
42
+ # Capistrano Base Setting
43
+ set :application, 'your_project_name'
44
+ set :user, 'rails'
45
+ set :deploy_to, "/home/#{user}/apps/#{application}"
46
+ set :deploy_via, :remote_cache
47
+ set :use_sudo, false
48
+ set :rails_env, :production
49
+
50
+ # Git Settings
51
+ set :scm, :git
52
+ set :repository, "git@github.com:username/#{application}.git" # your git source, and make sure your server have premission to access your git server
53
+ set :branch, :master # the branch you want to deploy
54
+
55
+ # Extra settings
56
+ default_run_options[:pty] = true
57
+ ssh_options[:forward_agent] = true
58
+
59
+ after 'deploy', 'deploy:cleanup' # keep only the last 5 releases