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
@@ -0,0 +1,51 @@
1
+ module Vpsb
2
+ module Tasks
3
+ class CreateDroplet < BaseTask
4
+ include AskSupport
5
+ include ShellSupport
6
+ prepare_squence :do_image, :do_region, :do_size, :do_droplet_ssh_key
7
+
8
+ def call
9
+ prepare
10
+
11
+ ask_loop(proc {|r| process(r)}) do
12
+ ap preparation_results
13
+ puts "Save this configuration y[es]/n[o]?"
14
+ end
15
+
16
+ create_droplet
17
+ puts "Your droplet has been created. Congratulations! Visit https://cloud.digitalocean.com/ to see more details"
18
+ end
19
+
20
+ private
21
+
22
+ def process(r)
23
+ return true if r[0].to_s.downcase == 'y'
24
+ reprepare
25
+ false
26
+ end
27
+
28
+ def create_droplet
29
+ puts "Creating droplet please wait... It may take a couple of minutes"
30
+ command = [
31
+ "knife digital_ocean droplet create",
32
+ "--server-name #{core.get(:do_host)}",
33
+ "--image #{core.get(:do_image)}",
34
+ "--location #{core.get(:do_region)}",
35
+ "--size #{core.get(:do_size)}",
36
+ "--ssh-keys #{core.get(:do_droplet_ssh_key)}",
37
+ ].join(' ')
38
+
39
+ output = run(core.get(:server_app_path), command)
40
+ ip = output.split("\n").find{ |x| x.include?('IPv4 address is:')}.split(':').last.strip
41
+ core.data[:do_host_ip] = ip
42
+ puts output
43
+ end
44
+
45
+ def run(where, what)
46
+ %x{cd #{where} && #{what}}
47
+ end
48
+ end
49
+ end
50
+ end
51
+
@@ -0,0 +1,32 @@
1
+ module Vpsb
2
+ module Tasks
3
+ class DbPostgresBags < BaseTask
4
+ include AskSupport
5
+
6
+ PATH = 'bootstrap_server_app_in_do/data_bags/db_users/postgresql.json'
7
+
8
+ prepare_squence :db_postgres_pass, :db_postgresql_bags_json
9
+
10
+ def call
11
+ prepare
12
+
13
+ ask_loop(proc {|r| process(r)}) do
14
+ ap preparation_results
15
+ p "Save this configuration y[es]/n[o]?"
16
+ end
17
+
18
+ Vpsb::Helpers::FileReplace.replace_json(PATH, core.get(:db_postgresql_bags_json))
19
+ end
20
+
21
+ private
22
+
23
+ def process(result)
24
+ return true if result[0].to_s.downcase == 'y'
25
+ reprepare
26
+ false
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+
@@ -0,0 +1,32 @@
1
+ module Vpsb
2
+ module Tasks
3
+ class DbPostgresRole < BaseTask
4
+ include AskSupport
5
+
6
+ PATH = 'bootstrap_server_app_in_do/roles/db.json'
7
+
8
+ prepare_squence :db_postgres_version, :db_postgres_json
9
+
10
+ def call
11
+ prepare
12
+
13
+ ask_loop(proc {|r| process(r)}) do
14
+ ap preparation_results
15
+ p "Save this configuration y[es]/n[o]?"
16
+ end
17
+
18
+ Vpsb::Helpers::FileReplace.replace_json(PATH,core.get(:db_postgres_json))
19
+ end
20
+
21
+ private
22
+
23
+ def process(result)
24
+ return true if result[0].to_s.downcase == 'y'
25
+ reprepare
26
+ false
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+
@@ -0,0 +1,32 @@
1
+ module Vpsb
2
+ module Tasks
3
+ class DeployBags < BaseTask
4
+ include AskSupport
5
+
6
+ PATH = 'bootstrap_server_app_in_do/data_bags/users/deploy.json'
7
+
8
+ prepare_squence :deploy_pass, :deploy_ssh_keys, :deploy_bags_json
9
+
10
+ def call
11
+ prepare
12
+
13
+ ask_loop(proc {|r| process(r)}) do
14
+ ap preparation_results
15
+ p "Save this configuration y[es]/n[o]?"
16
+ end
17
+
18
+ Vpsb::Helpers::FileReplace.replace_json(PATH, core.get(:deploy_bags_json))
19
+ end
20
+
21
+ private
22
+
23
+ def process(result)
24
+ return true if result[0].to_s.downcase == 'y'
25
+ reprepare
26
+ false
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+
@@ -0,0 +1,19 @@
1
+ module Vpsb
2
+ module Tasks
3
+ class DeployConfig < BaseTask
4
+ include AskSupport
5
+
6
+ PATH = 'bootstrap_rails_app_in_do/config/deploy/production.rb'
7
+
8
+ prepare_squence :deploy_config
9
+
10
+ def call
11
+ prepare
12
+
13
+ Vpsb::Helpers::FileReplace.replace_text(PATH, core.get(:deploy_config))
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+
@@ -0,0 +1,52 @@
1
+ require 'fileutils'
2
+
3
+ module Vpsb
4
+ module Tasks
5
+ class DoApiAccess < BaseTask
6
+ include AskSupport
7
+
8
+ prepare_squence :has_do_account, :do_host, :do_api_key, :do_client_id
9
+
10
+ def call
11
+ prepare
12
+
13
+ ask_loop(proc {|r| process(r)}) do
14
+ ap preparation_results
15
+ puts "Save this configuration y[es]/n[o]?"
16
+ end
17
+
18
+ update_knife_rb
19
+ end
20
+
21
+ private
22
+
23
+ def process(result)
24
+ return true if result[0].to_s.downcase == 'y'
25
+ reprepare
26
+ false
27
+ end
28
+
29
+ def update_knife_rb
30
+ File.open(core.get(:knife_rb_path), "w+") { |f| f.write(config) }
31
+ puts 'Knife.rb file created'
32
+ end
33
+
34
+ def config
35
+ <<-EOS
36
+ cookbook_path ["cookbooks", "site-cookbooks"]
37
+ node_path "nodes"
38
+ role_path "roles"
39
+ environment_path "environments"
40
+ data_bag_path "data_bags"
41
+ encrypted_data_bag_secret "data_bag_key"
42
+
43
+ # knife[:secret_file] = "data_bag_key"
44
+ knife[:secret_file] = "~/chef-solo/data_bag_key"
45
+ knife[:berkshelf_path] = "cookbooks"
46
+ knife[:digital_ocean_client_id] = '#{core.get(:do_client_id)}'
47
+ knife[:digital_ocean_api_key] = '#{core.get(:do_api_key)}'
48
+ EOS
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,22 @@
1
+ module Vpsb
2
+ module Tasks
3
+ class DropletSshKeys < BaseTask
4
+ include AskSupport
5
+ attr_reader :core
6
+
7
+ def initialize(core)
8
+ @core = core
9
+ end
10
+
11
+ prepare_squence :do_ssh_path
12
+
13
+ def call
14
+ prepare
15
+ core.get(:ssh_helper).generate_ssh(core.get(:do_ssh_path))
16
+ puts core.get(:ssh_helper).pub_key(core.get(:do_ssh_path))
17
+ ask { puts "Visit https://cloud.digitalocean.com/ssh_keys and add add the key above. Press Enter to continue" }
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ module Vpsb
2
+ module Tasks
3
+ class DropletSshUpdateConfig < BaseTask
4
+ include AskSupport
5
+ attr_reader :core
6
+
7
+ def initialize(core)
8
+ @core = core
9
+ end
10
+
11
+ prepare_squence :ssh_helper, :do_host_ip, :do_ssh_pub_path
12
+
13
+ def call
14
+ prepare
15
+ core.get(:ssh_helper).add_host_to_config(core.get(:do_host_ip), core.get(:do_ssh_pub_path), 'root')
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,32 @@
1
+ module Vpsb
2
+ module Tasks
3
+ class EsRole < BaseTask
4
+ include AskSupport
5
+
6
+ PATH = 'bootstrap_server_app_in_do/roles/es.json'
7
+
8
+ prepare_squence :es_version, :es_nofile, :es_memlock, :es_node_name, :es_cluster_name, :es_json
9
+
10
+ def call
11
+ prepare
12
+
13
+ ask_loop(proc {|r| process(r)}) do
14
+ ap preparation_results
15
+ p "Save this configuration y[es]/n[o]?"
16
+ end
17
+
18
+ Vpsb::Helpers::FileReplace.replace_json(PATH, core.get(:es_json))
19
+ end
20
+
21
+ private
22
+
23
+ def process(result)
24
+ return true if result[0].to_s.downcase == 'y'
25
+ reprepare
26
+ false
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+
@@ -0,0 +1,32 @@
1
+ module Vpsb
2
+ module Tasks
3
+ class MonitRole < BaseTask
4
+ include AskSupport
5
+
6
+ PATH = 'bootstrap_server_app_in_do/roles/monit.json'
7
+
8
+ prepare_squence :hostname, :newrelic_lic, :monit_role_json
9
+
10
+ def call
11
+ prepare
12
+
13
+ ask_loop(proc {|r| process(r)}) do
14
+ ap preparation_results
15
+ p "Save this configuration y[es]/n[o]?"
16
+ end
17
+
18
+ Vpsb::Helpers::FileReplace.replace_json(PATH, core.get(:monit_role_json))
19
+ end
20
+
21
+ private
22
+
23
+ def process(result)
24
+ return true if result[0].to_s.downcase == 'y'
25
+ reprepare
26
+ false
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+
@@ -0,0 +1,32 @@
1
+ module Vpsb
2
+ module Tasks
3
+ class Node < BaseTask
4
+ include AskSupport
5
+
6
+ PATH = 'bootstrap_server_app_in_do/nodes/'
7
+
8
+ prepare_squence :node_json
9
+
10
+ def call
11
+ prepare
12
+
13
+ # ip = ask_loop(proc {|r| process(r)}) do
14
+ # p "What is server ip address (example: 1.23.44.11)?"
15
+ # end
16
+
17
+ ip = core.get(:do_host_ip)
18
+
19
+ Vpsb::Helpers::FileReplace.replace_json("#{PATH}#{ip}.json",core.get(:node_json))
20
+ end
21
+
22
+ private
23
+
24
+ def process(result)
25
+ return true if result.split('.').length == 4
26
+ false
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+
@@ -0,0 +1,32 @@
1
+ module Vpsb
2
+ module Tasks
3
+ class PackagesBags < BaseTask
4
+ include AskSupport
5
+
6
+ PATH = 'bootstrap_server_app_in_do/data_bags/components/packages.json'
7
+
8
+ prepare_squence :packages_list, :packages_bags_json
9
+
10
+ def call
11
+ prepare
12
+
13
+ ask_loop(proc {|r| process(r)}) do
14
+ ap preparation_results
15
+ p "Save this configuration y[es]/n[o]?"
16
+ end
17
+
18
+ Vpsb::Helpers::FileReplace.replace_json(PATH, core.get(:packages_bags_json))
19
+ end
20
+
21
+ private
22
+
23
+ def process(result)
24
+ return true if result[0].to_s.downcase == 'y'
25
+ reprepare
26
+ false
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+
@@ -0,0 +1,32 @@
1
+ module Vpsb
2
+ module Tasks
3
+ class WebRole < BaseTask
4
+ include AskSupport
5
+
6
+ PATH = 'bootstrap_server_app_in_do/roles/web.json'
7
+
8
+ prepare_squence :ruby_version, :unicorn_worker_processes, :unicorn_worker_timeout
9
+
10
+ def call
11
+ prepare
12
+
13
+ ask_loop(proc {|r| process(r)}) do
14
+ ap preparation_results
15
+ p "Save this configuration y[es]/n[o]?"
16
+ end
17
+
18
+ Vpsb::Helpers::FileReplace.replace_json(PATH, core.get(:web_role_json))
19
+ end
20
+
21
+ private
22
+
23
+ def process(result)
24
+ return true if result[0].to_s.downcase == 'y'
25
+ reprepare
26
+ false
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+
@@ -0,0 +1,3 @@
1
+ module Vpsb
2
+ VERSION = "1.0.0"
3
+ end
data/lib/vpsb.rb ADDED
@@ -0,0 +1,16 @@
1
+ require "vpsb/version"
2
+ require "vpsb/ask_support"
3
+ require "vpsb/core"
4
+ require "vpsb/shell_support"
5
+ require "vpsb/helpers/file_replace"
6
+ require "vpsb/base_resource"
7
+ require "vpsb/base_ask_resource"
8
+ require "vpsb/base_task"
9
+
10
+ Dir[File.join(File.expand_path('../', __FILE__), "**/*.rb")].each{ |f| require f}
11
+
12
+ module Vpsb
13
+
14
+ end
15
+
16
+
@@ -0,0 +1,22 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/vpsg')
9
+ require 'rspec'
10
+ require 'ostruct'
11
+
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+
17
+ # Run specs in random order to surface order dependencies. If you find an
18
+ # order dependency and want to debug it, you can fix the order by providing
19
+ # the seed, which is printed after each run.
20
+ # --seed 1234
21
+ config.order = 'random'
22
+ end
data/vpsb.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vpsb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vpsb"
8
+ spec.version = Vpsb::VERSION
9
+ spec.authors = ["Pawel Niemczyk"]
10
+ spec.email = ["pniemczyk@o2.pl"]
11
+ spec.summary = %q{VPS bootstrap}
12
+ spec.description = %q{From instalation server and configure to deploy}
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.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_dependency "executable", "~> 1.2"
25
+ spec.add_dependency "json", "~> 1.7"
26
+ spec.add_dependency "activesupport", "~> 4.0"
27
+ spec.add_dependency "awesome_print", "~> 1.2"
28
+ spec.add_dependency "hashie", "~> 2.1"
29
+ spec.add_dependency "rendering_engine", "0.1"
30
+ end