vpsb 1.0.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.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/Gemfile +20 -0
  4. data/Gemfile.lock +175 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +62 -0
  7. data/Rakefile +2 -0
  8. data/bin/vpsb +10 -0
  9. data/lib/vpsb/ask_support.rb +27 -0
  10. data/lib/vpsb/base_ask_resource.rb +40 -0
  11. data/lib/vpsb/base_resource.rb +13 -0
  12. data/lib/vpsb/base_task.rb +32 -0
  13. data/lib/vpsb/commands/base.rb +68 -0
  14. data/lib/vpsb/commands/build.rb +61 -0
  15. data/lib/vpsb/commands/cook.rb +27 -0
  16. data/lib/vpsb/commands/deploy.rb +25 -0
  17. data/lib/vpsb/commands/help_messages.rb +23 -0
  18. data/lib/vpsb/commands/init.rb +52 -0
  19. data/lib/vpsb/commands/setup.rb +23 -0
  20. data/lib/vpsb/core.rb +41 -0
  21. data/lib/vpsb/helpers/file_replace.rb +20 -0
  22. data/lib/vpsb/helpers/ssh.rb +117 -0
  23. data/lib/vpsb/resources/app_bags_json.rb +38 -0
  24. data/lib/vpsb/resources/app_env_variables.rb +24 -0
  25. data/lib/vpsb/resources/app_host.rb +12 -0
  26. data/lib/vpsb/resources/app_name.rb +11 -0
  27. data/lib/vpsb/resources/app_nginx_use_ssl.rb +12 -0
  28. data/lib/vpsb/resources/base_path.rb +10 -0
  29. data/lib/vpsb/resources/db_postgres_json.rb +62 -0
  30. data/lib/vpsb/resources/db_postgres_pass.rb +11 -0
  31. data/lib/vpsb/resources/db_postgres_version.rb +21 -0
  32. data/lib/vpsb/resources/db_postgresql_bags_json.rb +20 -0
  33. data/lib/vpsb/resources/deploy_bags_json.rb +36 -0
  34. data/lib/vpsb/resources/deploy_config.rb +32 -0
  35. data/lib/vpsb/resources/deploy_keychain.rb +19 -0
  36. data/lib/vpsb/resources/deploy_pass.rb +11 -0
  37. data/lib/vpsb/resources/deploy_ssh_keys.rb +20 -0
  38. data/lib/vpsb/resources/deploy_to_known_hosts.rb +13 -0
  39. data/lib/vpsb/resources/do_api_key.rb +14 -0
  40. data/lib/vpsb/resources/do_client_id.rb +8 -0
  41. data/lib/vpsb/resources/do_droplet_ssh_key.rb +15 -0
  42. data/lib/vpsb/resources/do_host.rb +8 -0
  43. data/lib/vpsb/resources/do_host_ip.rb +8 -0
  44. data/lib/vpsb/resources/do_image.rb +16 -0
  45. data/lib/vpsb/resources/do_region.rb +16 -0
  46. data/lib/vpsb/resources/do_size.rb +16 -0
  47. data/lib/vpsb/resources/do_ssh_path.rb +15 -0
  48. data/lib/vpsb/resources/do_ssh_pub_path.rb +15 -0
  49. data/lib/vpsb/resources/es_cluster_name.rb +9 -0
  50. data/lib/vpsb/resources/es_json.rb +50 -0
  51. data/lib/vpsb/resources/es_memlock.rb +18 -0
  52. data/lib/vpsb/resources/es_node_name.rb +8 -0
  53. data/lib/vpsb/resources/es_nofile.rb +18 -0
  54. data/lib/vpsb/resources/es_version.rb +21 -0
  55. data/lib/vpsb/resources/has_do_account.rb +19 -0
  56. data/lib/vpsb/resources/hostname.rb +12 -0
  57. data/lib/vpsb/resources/knife_rb_path.rb +10 -0
  58. data/lib/vpsb/resources/local_ssh_path.rb +15 -0
  59. data/lib/vpsb/resources/local_ssh_pub.rb +13 -0
  60. data/lib/vpsb/resources/monit_role_json.rb +33 -0
  61. data/lib/vpsb/resources/newrelic_lic.rb +8 -0
  62. data/lib/vpsb/resources/node_json.rb +31 -0
  63. data/lib/vpsb/resources/packages_bags_json.rb +20 -0
  64. data/lib/vpsb/resources/packages_list.rb +18 -0
  65. data/lib/vpsb/resources/rails_app_path.rb +11 -0
  66. data/lib/vpsb/resources/read_do_api_access.rb +21 -0
  67. data/lib/vpsb/resources/ruby_version.rb +21 -0
  68. data/lib/vpsb/resources/server_app_path.rb +11 -0
  69. data/lib/vpsb/resources/ssh_helper.rb +10 -0
  70. data/lib/vpsb/resources/unicorn_worker_processes.rb +18 -0
  71. data/lib/vpsb/resources/unicorn_worker_timeout.rb +18 -0
  72. data/lib/vpsb/resources/web_role_json.rb +92 -0
  73. data/lib/vpsb/resources.rb +4 -0
  74. data/lib/vpsb/shell_support.rb +7 -0
  75. data/lib/vpsb/tasks/apps_bags.rb +33 -0
  76. data/lib/vpsb/tasks/create_droplet.rb +51 -0
  77. data/lib/vpsb/tasks/db_postgres_bags.rb +32 -0
  78. data/lib/vpsb/tasks/db_postgres_role.rb +32 -0
  79. data/lib/vpsb/tasks/deploy_bags.rb +32 -0
  80. data/lib/vpsb/tasks/deploy_config.rb +19 -0
  81. data/lib/vpsb/tasks/do_api_access.rb +52 -0
  82. data/lib/vpsb/tasks/droplet_ssh_keys.rb +22 -0
  83. data/lib/vpsb/tasks/droplet_ssh_update_config.rb +20 -0
  84. data/lib/vpsb/tasks/es_role.rb +32 -0
  85. data/lib/vpsb/tasks/monit_role.rb +32 -0
  86. data/lib/vpsb/tasks/node.rb +32 -0
  87. data/lib/vpsb/tasks/packages_bags.rb +32 -0
  88. data/lib/vpsb/tasks/web_role.rb +32 -0
  89. data/lib/vpsb/version.rb +3 -0
  90. data/lib/vpsb.rb +16 -0
  91. data/spec/spec_helper.rb +22 -0
  92. data/vpsb.gemspec +30 -0
  93. metadata +263 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1bb4cc65e110c6625d772d44d78315f14b92a39d
4
+ data.tar.gz: 60f5711c62d7b2a34080482e8e0da91317c49b11
5
+ SHA512:
6
+ metadata.gz: daae50c8e175e3e730b703c9aa315e9267d673602421c4a7458f5e17911a790f40b7c1a990f44edeec8b356c303c73bba958e877579378f20a79385ec8d0e94c
7
+ data.tar.gz: d7ec8e60c53120845a486dfcd2d267125c3f8906a4af0253c2963821ebc6e61adcf30e4ce6456400195193d4f771597d78c08702fcd274736581d0a7516e8304
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
17
+ *.bundle
18
+ *.so
19
+ *.o
20
+ *.a
21
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vpsb.gemspec
4
+ gemspec
5
+
6
+ gem 'librarian-chef'
7
+ gem 'knife-solo'
8
+ gem 'knife-digital_ocean'
9
+ gem 'chef', '>= 10.4'
10
+ gem "activesupport"
11
+ gem "awesome_print"
12
+ gem "hashie"
13
+ gem "executable"
14
+ gem "json"
15
+ gem "rendering_engine"
16
+ gem 'capistrano'
17
+ gem 'capistrano-rvm'
18
+ gem 'capistrano-rails'
19
+ gem 'capistrano-bundler'
20
+ gem 'capistrano-rsync'
data/Gemfile.lock ADDED
@@ -0,0 +1,175 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vpsb (1.0.0)
5
+ activesupport (~> 4.0)
6
+ awesome_print (~> 1.2)
7
+ executable (~> 1.2)
8
+ hashie (~> 2.1)
9
+ json (~> 1.7)
10
+ rendering_engine (= 0.1)
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ activesupport (4.1.1)
16
+ i18n (~> 0.6, >= 0.6.9)
17
+ json (~> 1.7, >= 1.7.7)
18
+ minitest (~> 5.1)
19
+ thread_safe (~> 0.1)
20
+ tzinfo (~> 1.1)
21
+ archive-tar-minitar (0.5.2)
22
+ awesome_print (1.2.0)
23
+ capistrano (3.1.0)
24
+ i18n
25
+ rake (>= 10.0.0)
26
+ sshkit (~> 1.3)
27
+ capistrano-bundler (1.1.2)
28
+ capistrano (~> 3.0)
29
+ sshkit (~> 1.2)
30
+ capistrano-rails (1.1.1)
31
+ capistrano (~> 3.1)
32
+ capistrano-bundler (~> 1.1)
33
+ capistrano-rsync (1.0.2)
34
+ capistrano (>= 3.0.0.pre14, < 4)
35
+ capistrano-rvm (0.1.1)
36
+ capistrano (~> 3.0)
37
+ sshkit (~> 1.2)
38
+ chef (11.14.0.alpha.2)
39
+ chef-zero (~> 2.0, >= 2.0.2)
40
+ diff-lcs (~> 1.2, >= 1.2.4)
41
+ erubis (~> 2.7)
42
+ highline (~> 1.6, >= 1.6.9)
43
+ json (>= 1.4.4, <= 1.8.1)
44
+ mime-types (~> 1.16)
45
+ mixlib-authentication (~> 1.3)
46
+ mixlib-cli (~> 1.4)
47
+ mixlib-config (~> 2.0)
48
+ mixlib-log (~> 1.3)
49
+ mixlib-shellout (~> 1.4)
50
+ net-ssh (~> 2.6)
51
+ net-ssh-multi (~> 1.1)
52
+ ohai (~> 7.0)
53
+ pry (~> 0.9)
54
+ rest-client (>= 1.0.4, < 1.7.0)
55
+ yajl-ruby (~> 1.1)
56
+ chef-zero (2.1.4)
57
+ hashie (~> 2.0)
58
+ json
59
+ mixlib-log (~> 1.3)
60
+ rack
61
+ coderay (1.1.0)
62
+ diff-lcs (1.2.5)
63
+ digital_ocean (1.5.0)
64
+ faraday (~> 0.9.0)
65
+ faraday_middleware (~> 0.9.0)
66
+ hashie (~> 2.1.1)
67
+ json
68
+ erubis (2.7.0)
69
+ executable (1.2.1)
70
+ faraday (0.9.0)
71
+ multipart-post (>= 1.2, < 3)
72
+ faraday_middleware (0.9.1)
73
+ faraday (>= 0.7.4, < 0.10)
74
+ hashie (2.1.1)
75
+ highline (1.6.21)
76
+ i18n (0.6.9)
77
+ ipaddress (0.8.0)
78
+ json (1.8.1)
79
+ knife-digital_ocean (0.7.0)
80
+ chef (>= 10.18)
81
+ digital_ocean (~> 1.5.0)
82
+ highline
83
+ knife-solo (0.4.1)
84
+ chef (>= 10.12)
85
+ erubis (~> 2.7.0)
86
+ net-ssh (>= 2.2.2, < 3.0)
87
+ librarian (0.1.2)
88
+ highline
89
+ thor (~> 0.15)
90
+ librarian-chef (0.0.2)
91
+ archive-tar-minitar (>= 0.5.2)
92
+ chef (>= 0.10)
93
+ librarian (~> 0.1.0)
94
+ method_source (0.8.2)
95
+ mime-types (1.25.1)
96
+ minitest (5.3.4)
97
+ mixlib-authentication (1.3.0)
98
+ mixlib-log
99
+ mixlib-cli (1.5.0)
100
+ mixlib-config (2.1.0)
101
+ mixlib-log (1.6.0)
102
+ mixlib-shellout (1.4.0)
103
+ multipart-post (2.0.0)
104
+ net-scp (1.1.2)
105
+ net-ssh (>= 2.6.5)
106
+ net-ssh (2.9.1)
107
+ net-ssh-gateway (1.2.0)
108
+ net-ssh (>= 2.6.5)
109
+ net-ssh-multi (1.2.0)
110
+ net-ssh (>= 2.6.5)
111
+ net-ssh-gateway (>= 1.2.0)
112
+ ohai (7.0.4)
113
+ ipaddress
114
+ mime-types (~> 1.16)
115
+ mixlib-cli
116
+ mixlib-config (~> 2.0)
117
+ mixlib-log
118
+ mixlib-shellout (~> 1.2)
119
+ systemu (~> 2.5.2)
120
+ yajl-ruby
121
+ pry (0.9.12.6)
122
+ coderay (~> 1.0)
123
+ method_source (~> 0.8)
124
+ slop (~> 3.4)
125
+ rack (1.5.2)
126
+ rake (10.3.2)
127
+ rendering_engine (0.1.0)
128
+ rest-client (1.6.7)
129
+ mime-types (>= 1.16)
130
+ rspec (2.14.1)
131
+ rspec-core (~> 2.14.0)
132
+ rspec-expectations (~> 2.14.0)
133
+ rspec-mocks (~> 2.14.0)
134
+ rspec-core (2.14.8)
135
+ rspec-expectations (2.14.5)
136
+ diff-lcs (>= 1.1.3, < 2.0)
137
+ rspec-mocks (2.14.6)
138
+ slop (3.5.0)
139
+ sshkit (1.3.0)
140
+ net-scp (>= 1.1.2)
141
+ net-ssh
142
+ term-ansicolor
143
+ systemu (2.5.2)
144
+ term-ansicolor (1.3.0)
145
+ tins (~> 1.0)
146
+ thor (0.19.1)
147
+ thread_safe (0.3.3)
148
+ tins (1.0.1)
149
+ tzinfo (1.1.0)
150
+ thread_safe (~> 0.1)
151
+ yajl-ruby (1.2.0)
152
+
153
+ PLATFORMS
154
+ ruby
155
+
156
+ DEPENDENCIES
157
+ activesupport
158
+ awesome_print
159
+ bundler (~> 1.6)
160
+ capistrano
161
+ capistrano-bundler
162
+ capistrano-rails
163
+ capistrano-rsync
164
+ capistrano-rvm
165
+ chef (>= 10.4)
166
+ executable
167
+ hashie
168
+ json
169
+ knife-digital_ocean
170
+ knife-solo
171
+ librarian-chef
172
+ rake
173
+ rendering_engine
174
+ rspec
175
+ vpsb!
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Pawel Niemczyk
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,62 @@
1
+ ## Bootstraping DigitalOcean server with nginx, and working rails application
2
+ ---
3
+ ### Where to start?
4
+
5
+ Create account on DigitalOcean through [link](https://www.digitalocean.com/?refcode=71281f14ac3c).
6
+ *(Using it you appreciate our efforts into releasing this tutorial with [vpsb gem](gem))*
7
+
8
+ - start by installing our gem
9
+
10
+ ```
11
+ gem install vpsb
12
+
13
+ ```
14
+
15
+ - then run gem by
16
+
17
+ ```
18
+ vpsb i <directory_name_to_create> # f.e. vpsb i my_first_app
19
+ cd <directory_name_to_create> # cd my_first_app
20
+ vpsb g
21
+
22
+ ```
23
+
24
+ In the last step you will be asked for several questions to provide base configuration
25
+
26
+ At the end you will have working rails app.
27
+
28
+ ---
29
+ ALTERNATIVELY, you may want to build server manually. If so, then
30
+
31
+ - create DigitalOcean droplet manually (https://cloud.digitalocean.com/droplets/new)
32
+
33
+ - clone server app repo from github
34
+
35
+ `git clone https://github.com/pniemczyk/bootstrap_server_app_in_do.git`
36
+
37
+ - install all dependencies by script
38
+
39
+ `./init_env.sh #installs all gems and downloads all coookbooks`
40
+
41
+ - update configuration (read README to know the meaning of files in repo)
42
+
43
+ - run bootstrap script `./bootstrap.sh`
44
+
45
+ - clone our sample rails app
46
+
47
+ `git clone https://github.com/pniemczyk/bootstrap_rails_app_in_do.git`
48
+
49
+ - run `bundle install`
50
+
51
+ - reconfigure app (enter domain in production deploy files)
52
+
53
+ - run `cap production deploy`
54
+
55
+ ## Contributing
56
+
57
+ 1. Fork it ( https://github.com/[my-github-username]/vpsb/fork )
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create a new Pull Request
62
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/vpsb ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # require 'vpsb'
4
+
5
+ # Vpsb::Commands::Base.run
6
+
7
+ #For tests
8
+
9
+ require 'vpsb'
10
+ Vpsb::Commands::Base.run
@@ -0,0 +1,27 @@
1
+ module Vpsb
2
+ module AskSupport
3
+ def ask(&block)
4
+ yield if block
5
+ STDIN.gets.chomp
6
+ end
7
+
8
+ def ask_to_confirm(question, &block)
9
+ answer = ask { puts "#{question} y[es]/n[o]?" }
10
+ cond = (answer[0].to_s.downcase == 'y')
11
+
12
+ yield cond if block
13
+
14
+ cond
15
+ end
16
+
17
+ def ask_loop(condition = nil, &block)
18
+ condition ||= proc { |res| !res.strip.empty? }
19
+
20
+ begin
21
+ yield if block
22
+ res = STDIN.gets.chomp
23
+ end until condition.call(res)
24
+ res
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,40 @@
1
+ module Vpsb
2
+ class BaseAskResource < BaseResource
3
+ include AskSupport
4
+
5
+ def self.question(text)
6
+ @question = text
7
+ end
8
+
9
+ def question
10
+ self.class.instance_variable_get(:@question)
11
+ end
12
+
13
+ def self.default(text)
14
+ @default = text
15
+ end
16
+
17
+ def default
18
+ self.class.instance_variable_get(:@default)
19
+ end
20
+
21
+ def call(data)
22
+ answer = ask_loop(validate) do
23
+ puts question
24
+ end
25
+ finalize(answer.strip)
26
+ end
27
+
28
+ protected
29
+
30
+ def finalize(answer)
31
+ return default if answer.empty? && !default.nil?
32
+ answer
33
+ end
34
+
35
+ def validate
36
+ return Proc.new { true } if !default.nil?
37
+ nil
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,13 @@
1
+ module Vpsb
2
+ class BaseResource
3
+
4
+ protected
5
+
6
+ def self.res(value)
7
+ define_method(:name){ value.to_sym }
8
+ end
9
+
10
+ def call(core)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ module Vpsb
2
+ class BaseTask
3
+ @prepare_squence = []
4
+ attr_reader :core, :prepare_squence
5
+
6
+ def initialize(core)
7
+ @core = core
8
+ end
9
+
10
+ def self.prepare_squence(*resource)
11
+ (@prepare_squence ||= []).push(*resource)
12
+ end
13
+
14
+ def prepare_squence
15
+ self.class.instance_variable_get(:@prepare_squence)
16
+ end
17
+
18
+ protected
19
+
20
+ def prepare
21
+ (prepare_squence || []).each{ |r| core.get(r) }
22
+ end
23
+
24
+ def reprepare
25
+ (prepare_squence || []).each{ |r| core.get(r, force:true) }
26
+ end
27
+
28
+ def preparation_results
29
+ (prepare_squence || []).inject({}){ |h, r| h[r] = core.get(r); h }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,68 @@
1
+ require "vpsb/version"
2
+ require 'executable'
3
+ require 'awesome_print'
4
+
5
+ module Vpsb
6
+ module Commands
7
+ class Base
8
+ include Executable
9
+
10
+ def go(*params)
11
+ setup(*params)
12
+ build(*params)
13
+ cook(*params)
14
+ deploy(*params)
15
+ end
16
+
17
+ def init(*params)
18
+ Init.new.execute(*params)
19
+ end
20
+
21
+ def setup(*params)
22
+ Setup.new(core).execute(*params)
23
+ end
24
+
25
+ def build(*params)
26
+ Build.new(core).execute(*params)
27
+ end
28
+
29
+ def cook(*params)
30
+ Cook.new(core).execute(*params)
31
+ end
32
+
33
+ def deploy(*params)
34
+ Deploy.new(core).execute(*params)
35
+ end
36
+
37
+ def help!
38
+ puts Vpsb::Commands::HelpMessages.show
39
+ exit
40
+ end
41
+ alias :h! :help!
42
+
43
+ def core
44
+ @core ||= (
45
+ c = Core.new
46
+ Vpsb::Resources.constants.each do |k|
47
+ klass = Vpsb::Resources.const_get(k)
48
+ c.register_resource klass.new if klass.is_a?(Class)
49
+ end
50
+ c
51
+ )
52
+ end
53
+
54
+ def call(name=nil, *params)
55
+ puts Vpsb::Commands::HelpMessages.intro
56
+ case name.to_s.strip
57
+ when 'go', 'g' then go(params)
58
+ when 'init', 'i' then init(params)
59
+ when 'setup', 's' then setup(params)
60
+ when 'build', 'b' then build(params)
61
+ when 'cook', 'c' then cook(params)
62
+ when 'deploy', 'd' then deploy(params)
63
+ else puts Vpsb::Commands::HelpMessages.unknown_command
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,61 @@
1
+ module Vpsb
2
+ module Commands
3
+ class Build
4
+ include AskSupport
5
+ def initialize(core)
6
+ @core = core
7
+ end
8
+
9
+ def execute(params)
10
+ web_role.call
11
+ deploy_bags.call
12
+ apps_bags.call
13
+ db_postgres_role.call
14
+ db_postgres_bags.call if core.present?(:db_postgres_json)
15
+ es_role.call if ask_to_confirm("Do you want configure elasticsearch")
16
+ monit_role.call if ask_to_confirm("Do you want configure monit(newrelic)")
17
+ packages_bags.call if ask_to_confirm("Do you want to install additional apt-get apps")
18
+ node.call
19
+ end
20
+
21
+ private
22
+ attr_reader :core
23
+
24
+ def node
25
+ Vpsb::Tasks::Node.new(core)
26
+ end
27
+
28
+ def apps_bags
29
+ Vpsb::Tasks::AppsBags.new(core)
30
+ end
31
+
32
+ def deploy_bags
33
+ Vpsb::Tasks::DeployBags.new(core)
34
+ end
35
+
36
+ def packages_bags
37
+ Vpsb::Tasks::PackagesBags.new(core)
38
+ end
39
+
40
+ def db_postgres_bags
41
+ Vpsb::Tasks::DbPostgresBags.new(core)
42
+ end
43
+
44
+ def db_postgres_role
45
+ Vpsb::Tasks::DbPostgresRole.new(core)
46
+ end
47
+
48
+ def es_role
49
+ Vpsb::Tasks::EsRole.new(core)
50
+ end
51
+
52
+ def monit_role
53
+ Vpsb::Tasks::MonitRole.new(core)
54
+ end
55
+
56
+ def web_role
57
+ Vpsb::Tasks::WebRole.new(core)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,27 @@
1
+ module Vpsb
2
+ module Commands
3
+ class Cook
4
+ include AskSupport
5
+ include ShellSupport
6
+ def initialize(core)
7
+ @core = core
8
+ end
9
+
10
+ def execute(params)
11
+ # ip = ask { puts "What is ip address server node to cook (example: 22.11.3.11)?" }
12
+ ip = core.get(:do_host_ip)
13
+ run("librarian-chef install")
14
+ run("knife solo prepare root@#{ip} --bootstrap-version 11.12.4")
15
+ run("knife solo bootstrap root@#{ip}")
16
+ end
17
+
18
+ private
19
+ attr_reader :core
20
+
21
+ def run(what)
22
+ in_dir('bootstrap_server_app_in_do', what)
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ module Vpsb
2
+ module Commands
3
+ class Deploy
4
+ include AskSupport
5
+ def initialize(core)
6
+ @core = core
7
+ end
8
+
9
+ def execute(params)
10
+
11
+ Vpsb::Tasks::DeployConfig.new(core).call
12
+ puts "Start deploying app."
13
+ run(core.get(:rails_app_path), 'bundle exec cap production deploy')
14
+ puts "app is ready! Visit #{core.get(:do_host_ip)}"
15
+ end
16
+
17
+ private
18
+ attr_reader :core
19
+
20
+ def run(where, what)
21
+ %x{cd #{where} && #{what}}
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ module Vpsb
2
+ module Commands
3
+ class HelpMessages
4
+ def self.intro
5
+ "Vpsb ver: #{VERSION}"
6
+ end
7
+
8
+ def self.unknown_command
9
+ "Command unknown"
10
+ end
11
+
12
+ def self.show
13
+ %{
14
+ Need help :D
15
+
16
+ commands:
17
+ init <name> #name is optional when is present all files will be created in in folder that name
18
+
19
+ }
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,52 @@
1
+ module Vpsb
2
+ module Commands
3
+ class Init
4
+
5
+ def execute(params)
6
+ unless params.empty?
7
+ name = params[0]
8
+ p "creating directory #{name}"
9
+ make_dir(name)
10
+ enter_to_the_dir(name)
11
+ end
12
+
13
+ p 'installing all gems'
14
+ install_all_gems
15
+ p 'clone all repos'
16
+ clone_all_repos
17
+ end
18
+
19
+ private
20
+
21
+ GEMS = %w{ knife-solo knife-digital_ocean librarian-chef knife-solo_data_bag }
22
+ REPOS = %w{
23
+ https://github.com/pniemczyk/bootstrap_rails_app_in_do.git
24
+ https://github.com/pniemczyk/bootstrap_server_app_in_do.git
25
+ }
26
+
27
+ def install_all_gems
28
+ GEMS.each{ |gem_name| gem_install(gem_name) }
29
+ end
30
+
31
+ def clone_all_repos
32
+ REPOS.each { |source| git_clone(source) }
33
+ end
34
+
35
+ def enter_to_the_dir(name)
36
+ Dir.chdir(name)
37
+ end
38
+
39
+ def make_dir(name)
40
+ Dir.mkdir name
41
+ end
42
+
43
+ def gem_install(name)
44
+ system("gem install #{name} --no-ri --no-rdoc")
45
+ end
46
+
47
+ def git_clone(source)
48
+ system("git clone #{source}")
49
+ end
50
+ end
51
+ end
52
+ end