smartmachine 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +661 -0
  3. data/README.md +147 -0
  4. data/bin/console +14 -0
  5. data/bin/setup +8 -0
  6. data/exe/smartmachine +3 -0
  7. data/lib/smart_machine/apps/app.rb +165 -181
  8. data/lib/smart_machine/apps/container.rb +120 -0
  9. data/lib/smart_machine/apps/manager.rb +182 -0
  10. data/lib/smart_machine/base.rb +24 -6
  11. data/lib/smart_machine/buildpackers/buildpacker.rb +95 -0
  12. data/lib/smart_machine/{engine/buildpacks → buildpackers}/rails/Dockerfile +3 -3
  13. data/lib/smart_machine/buildpackers/rails.rb +221 -0
  14. data/lib/smart_machine/commands/app.rb +112 -0
  15. data/lib/smart_machine/commands/buildpacker.rb +53 -0
  16. data/lib/smart_machine/commands/credentials.rb +17 -0
  17. data/lib/smart_machine/commands/docker.rb +23 -0
  18. data/lib/smart_machine/commands/engine.rb +27 -0
  19. data/lib/smart_machine/commands/grid.rb +33 -0
  20. data/lib/smart_machine/commands/grid_commands/elasticsearch.rb +68 -0
  21. data/lib/smart_machine/commands/grid_commands/minio.rb +65 -0
  22. data/lib/smart_machine/commands/grid_commands/mysql.rb +71 -0
  23. data/lib/smart_machine/commands/grid_commands/nginx.rb +53 -0
  24. data/lib/smart_machine/commands/grid_commands/prereceiver.rb +96 -0
  25. data/lib/smart_machine/commands/grid_commands/redis.rb +65 -0
  26. data/lib/smart_machine/commands/grid_commands/scheduler.rb +15 -0
  27. data/lib/smart_machine/commands/grid_commands/sub_thor.rb +15 -0
  28. data/lib/smart_machine/commands/machine.rb +24 -0
  29. data/lib/smart_machine/commands/syncer.rb +23 -0
  30. data/lib/smart_machine/commands/utilities.rb +37 -0
  31. data/lib/smart_machine/commands.rb +66 -0
  32. data/lib/smart_machine/configuration.rb +79 -0
  33. data/lib/smart_machine/credentials.rb +93 -95
  34. data/lib/smart_machine/docker.rb +144 -143
  35. data/lib/smart_machine/engine/Dockerfile +7 -5
  36. data/lib/smart_machine/engine.rb +104 -79
  37. data/lib/smart_machine/grids/elasticsearch.rb +70 -89
  38. data/lib/smart_machine/grids/minio.rb +79 -68
  39. data/lib/smart_machine/grids/mysql.rb +207 -202
  40. data/lib/smart_machine/grids/nginx.rb +176 -135
  41. data/lib/smart_machine/grids/prereceiver/Dockerfile +2 -2
  42. data/lib/smart_machine/grids/prereceiver/pre-receive +17 -0
  43. data/lib/smart_machine/grids/prereceiver.rb +169 -169
  44. data/lib/smart_machine/grids/redis.rb +73 -57
  45. data/lib/smart_machine/logger.rb +26 -26
  46. data/lib/smart_machine/machine.rb +128 -194
  47. data/lib/smart_machine/scp.rb +15 -0
  48. data/lib/smart_machine/ssh.rb +69 -40
  49. data/lib/smart_machine/syncer.rb +133 -0
  50. data/lib/smart_machine/templates/dotsmartmachine/Gemfile +7 -0
  51. data/lib/smart_machine/templates/dotsmartmachine/config/elasticsearch.yml +5 -0
  52. data/lib/smart_machine/templates/dotsmartmachine/config/environment.rb +0 -9
  53. data/lib/smart_machine/templates/dotsmartmachine/config/minio.yml +13 -0
  54. data/lib/smart_machine/templates/dotsmartmachine/config/mysql/schedule.rb +3 -3
  55. data/lib/smart_machine/templates/dotsmartmachine/config/mysql.yml +13 -0
  56. data/lib/smart_machine/templates/dotsmartmachine/config/prereceiver.yml +7 -0
  57. data/lib/smart_machine/templates/dotsmartmachine/config/redis.yml +13 -0
  58. data/lib/smart_machine/templates/dotsmartmachine/config/users.yml +1 -1
  59. data/lib/smart_machine/templates/dotsmartmachine/gitignore-template +47 -0
  60. data/lib/smart_machine/templates/dotsmartmachine/{grids/elasticsearch/data → vendor}/.keep +0 -0
  61. data/lib/smart_machine/version.rb +30 -6
  62. data/lib/smart_machine.rb +42 -16
  63. metadata +97 -47
  64. data/CHANGELOG.rdoc +0 -0
  65. data/MIT-LICENSE +0 -21
  66. data/README.rdoc +0 -87
  67. data/bin/buildpacker +0 -8
  68. data/bin/prereceiver +0 -8
  69. data/bin/scheduler +0 -18
  70. data/bin/smartmachine +0 -81
  71. data/bin/smartrunner +0 -33
  72. data/lib/smart_machine/apps/rails.rb +0 -250
  73. data/lib/smart_machine/apps.rb +0 -14
  74. data/lib/smart_machine/boot.rb +0 -32
  75. data/lib/smart_machine/buildpacker.rb +0 -106
  76. data/lib/smart_machine/gem_version.rb +0 -17
  77. data/lib/smart_machine/grids.rb +0 -18
  78. data/lib/smart_machine/sync.rb +0 -120
  79. data/lib/smart_machine/templates/dotsmartmachine/grids/elasticsearch/logs/.keep +0 -0
  80. data/lib/smart_machine/templates/dotsmartmachine/grids/minio/data/.keep +0 -0
  81. data/lib/smart_machine/templates/dotsmartmachine/grids/mysql/backups/.keep +0 -0
  82. data/lib/smart_machine/templates/dotsmartmachine/grids/mysql/data/.keep +0 -0
  83. data/lib/smart_machine/templates/dotsmartmachine/grids/prereceiver/pre-receive +0 -17
  84. data/lib/smart_machine/templates/dotsmartmachine/grids/redis/data/.keep +0 -0
  85. data/lib/smart_machine/user.rb +0 -38
@@ -1,97 +1,78 @@
1
- # The main SmartMachine Grids Elasticsearch driver
2
1
  module SmartMachine
3
- class Grids
4
- class Elasticsearch < SmartMachine::Base
5
- def initialize
6
- end
2
+ class Grids
3
+ class Elasticsearch < SmartMachine::Base
4
+ def initialize(name:)
5
+ config = SmartMachine.config.grids.elasticsearch.dig(name.to_sym)
6
+ raise "elasticsearch config for #{name} not found." unless config
7
7
 
8
- def install
9
- puts "-----> Installing Elasticsearch"
8
+ @port = config.dig(:port)
10
9
 
11
- print "-----> Creating settings for elasticsearch ... "
12
- ssh = SmartMachine::SSH.new
13
- ssh.run "echo 'vm.max_map_count=262144' | sudo tee /etc/sysctl.d/60-smartmachine-elasticsearch.conf && sudo sysctl --system"
14
- puts "done"
10
+ @name = name.to_s
11
+ @home_dir = File.expand_path('~')
12
+ end
15
13
 
16
- puts "-----> Elasticsearch Installation Complete"
17
- end
14
+ def uper
15
+ # Creating networks
16
+ unless system("docker network inspect #{@name}-network", [:out, :err] => File::NULL)
17
+ print "-----> Creating network #{@name}-network ... "
18
+ if system("docker network create #{@name}-network", out: File::NULL)
19
+ puts "done"
20
+ end
21
+ end
18
22
 
19
- def uninstall
20
- puts "-----> Uninstalling Elasticsearch"
23
+ FileUtils.mkdir_p("#{@home_dir}/machine/grids/elasticsearch/#{@name}/data")
24
+ FileUtils.mkdir_p("#{@home_dir}/machine/grids/elasticsearch/#{@name}/logs")
21
25
 
22
- print "-----> Removing settings for elasticsearch ... "
23
- ssh = SmartMachine::SSH.new
24
- # NOTE: sysctl does not reset this setting until restart of system even after sudo sysctl --system is run.
25
- ssh.run "test -f /etc/sysctl.d/60-smartmachine-elasticsearch.conf && sudo rm /etc/sysctl.d/60-smartmachine-elasticsearch.conf && sudo sysctl --system"
26
- puts "done"
26
+ # Creating & Starting containers
27
+ print "-----> Creating container #{@name} ... "
28
+ command = [
29
+ "docker create",
30
+ "--name='#{@name}'",
31
+ "--label='smartmachine.elasticsearch.name=#{@name}'",
32
+ "--env discovery.type=single-node",
33
+ "--env cluster.name=#{@name}-cluster",
34
+ "--env 'ES_JAVA_OPTS=-Xms512m -Xmx512m -Des.enforce.bootstrap.checks=true'",
35
+ "--env bootstrap.memory_lock=true",
36
+ "--ulimit memlock=-1:-1",
37
+ "--ulimit nofile=65535:65535",
38
+ "--user `id -u`:`id -g`",
39
+ "--publish='#{@port}:#{@port}'",
40
+ "--volume='#{@home_dir}/smartmachine/grids/elasticsearch/#{@name}/data:/usr/share/elasticsearch/data'",
41
+ "--volume='#{@home_dir}/smartmachine/grids/elasticsearch/#{@name}/logs:/usr/share/elasticsearch/logs'",
42
+ "--restart='always'",
43
+ "--network='#{@name}-network'",
44
+ "elasticsearch:7.4.1"
45
+ ]
46
+ if system(command.compact.join(" "), out: File::NULL)
47
+ puts "done"
48
+ puts "-----> Starting container #{@name} ... "
49
+ if system("docker start #{@name}", out: File::NULL)
50
+ puts "done"
51
+ else
52
+ raise "Error: Could not start the created #{@name} container"
53
+ end
54
+ else
55
+ raise "Error: Could not create #{@name} container"
56
+ end
57
+ end
27
58
 
28
- puts "-----> Elasticsearch Uninstallation Complete"
29
- end
59
+ def downer
60
+ # Stopping & Removing containers - in reverse order
61
+ print "-----> Stopping container #{@name} ... "
62
+ if system("docker stop '#{@name}'", out: File::NULL)
63
+ puts "done"
64
+ print "-----> Removing container #{@name} ... "
65
+ if system("docker rm '#{@name}'", out: File::NULL)
66
+ puts "done"
67
+ end
68
+ end
30
69
 
31
- def update
32
- self.uninstall
33
- self.install
34
- end
35
-
36
- def up(*args)
37
- args.flatten!
38
- exposed = args.empty? ? '' : args.shift
39
-
40
- if SmartMachine::Docker.running?
41
- # Creating networks
42
- unless system("docker network inspect elasticsearch-network", [:out, :err] => File::NULL)
43
- print "-----> Creating network elasticsearch-network ... "
44
- if system("docker network create elasticsearch-network", out: File::NULL)
45
- puts "done"
46
- end
47
- end
48
-
49
- # Creating & Starting containers
50
- print "-----> Creating container elasticsearch ... "
51
- if system("docker create \
52
- --name='elasticsearch' \
53
- --env discovery.type=single-node \
54
- --env cluster.name=elasticsearch-cluster \
55
- --env 'ES_JAVA_OPTS=-Xms512m -Xmx512m -Des.enforce.bootstrap.checks=true' \
56
- --env bootstrap.memory_lock=true \
57
- --ulimit memlock=-1:-1 \
58
- --ulimit nofile=65535:65535 \
59
- --user `id -u`:`id -g` \
60
- #{"--publish='#{SmartMachine.credentials.elasticsearch[:port]}:#{SmartMachine.credentials.elasticsearch[:port]}'" if exposed == '--exposed'} \
61
- --volume='#{SmartMachine.config.user_home_path}/.smartmachine/grids/elasticsearch/data:/usr/share/elasticsearch/data' \
62
- --volume='#{SmartMachine.config.user_home_path}/.smartmachine/grids/elasticsearch/logs:/usr/share/elasticsearch/logs' \
63
- --restart='always' \
64
- --network='elasticsearch-network' \
65
- elasticsearch:7.4.1", out: File::NULL)
66
-
67
- puts "done"
68
- print "-----> Starting container elasticsearch ... "
69
- if system("docker start elasticsearch", out: File::NULL)
70
- puts "done"
71
- end
72
- end
73
- end
74
- end
75
-
76
- def down
77
- if SmartMachine::Docker.running?
78
- # Stopping & Removing containers - in reverse order
79
- print "-----> Stopping container elasticsearch ... "
80
- if system("docker stop 'elasticsearch'", out: File::NULL)
81
- puts "done"
82
- print "-----> Removing container elasticsearch ... "
83
- if system("docker rm 'elasticsearch'", out: File::NULL)
84
- puts "done"
85
- end
86
- end
87
-
88
- # Removing networks
89
- print "-----> Removing network elasticsearch-network ... "
90
- if system("docker network rm elasticsearch-network", out: File::NULL)
91
- puts "done"
92
- end
93
- end
94
- end
95
- end
96
- end
97
- end
70
+ # Removing networks
71
+ print "-----> Removing network #{@name}-network ... "
72
+ if system("docker network rm #{@name}-network", out: File::NULL)
73
+ puts "done"
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -1,77 +1,88 @@
1
- # The main SmartMachine Grids Minio driver
2
1
  module SmartMachine
3
- class Grids
4
- class Minio < SmartMachine::Base
5
- def initialize
6
- end
2
+ class Grids
3
+ class Minio < SmartMachine::Base
4
+ def initialize(name:)
5
+ config = SmartMachine.config.grids.minio.dig(name.to_sym)
6
+ raise "minio config for #{name} not found." unless config
7
7
 
8
- def up(*args)
9
- args.flatten!
10
- exposed = args.empty? ? '' : args.shift
8
+ @host = config.dig(:host)
9
+ @access_key = config.dig(:access_key)
10
+ @secret_key = config.dig(:secret_key)
11
+ @browser = config.dig(:browser)
12
+ @worm = config.dig(:worm)
11
13
 
12
- if SmartMachine::Docker.running?
13
- # Creating networks
14
- unless system("docker network inspect minio-network", [:out, :err] => File::NULL)
15
- print "-----> Creating network minio-network ... "
16
- if system("docker network create minio-network", out: File::NULL)
17
- puts "done"
18
- end
19
- end
14
+ @name = name.to_s
15
+ @home_dir = File.expand_path('~')
16
+ end
20
17
 
21
- # Creating & Starting containers
22
- print "-----> Creating container minio ... "
23
- if system("docker create \
24
- --name='minio' \
25
- --env VIRTUAL_HOST=#{SmartMachine.credentials.minio[:name]}.#{SmartMachine.config.apps_domain} \
26
- --env LETSENCRYPT_HOST=#{SmartMachine.credentials.minio[:name]}.#{SmartMachine.config.apps_domain} \
27
- --env LETSENCRYPT_EMAIL=#{SmartMachine.config.sysadmin_email} \
28
- --env LETSENCRYPT_TEST=false \
29
- --env MINIO_ACCESS_KEY=#{SmartMachine.credentials.minio[:access_key]} \
30
- --env MINIO_SECRET_KEY=#{SmartMachine.credentials.minio[:secret_key]} \
31
- --env MINIO_BROWSER=#{SmartMachine.credentials.minio[:browser]} \
32
- --env MINIO_WORM=#{SmartMachine.credentials.minio[:worm]} \
33
- --user `id -u`:`id -g` \
34
- --volume='#{SmartMachine.config.user_home_path}/.smartmachine/grids/minio/data:/data' \
35
- --restart='always' \
36
- --network='minio-network' \
37
- minio/minio:RELEASE.2020-02-27T00-23-05Z server /data", out: File::NULL)
18
+ def uper
19
+ # Creating networks
20
+ unless system("docker network inspect #{@name}-network", [:out, :err] => File::NULL)
21
+ print "-----> Creating network #{@name}-network ... "
22
+ if system("docker network create #{@name}-network", out: File::NULL)
23
+ puts "done"
24
+ end
25
+ end
38
26
 
39
- # The alias is necessary to support internal network requests directed to minio container using public url
40
- system("docker network connect --alias #{SmartMachine.credentials.minio[:name]}.#{SmartMachine.config.apps_domain} minio-network nginx")
41
- system("docker network connect nginx-network minio")
27
+ FileUtils.mkdir_p("#{@home_dir}/machine/grids/minio/#{@name}/data")
42
28
 
43
- puts "done"
44
- print "-----> Starting container minio ... "
45
- if system("docker start minio", out: File::NULL)
46
- puts "done"
47
- end
48
- end
49
- end
50
- end
29
+ # Creating & Starting containers
30
+ print "-----> Creating container #{@name} ... "
31
+ command = [
32
+ "docker create",
33
+ "--name='#{@name}'",
34
+ "--env VIRTUAL_HOST=#{@host}",
35
+ "--env LETSENCRYPT_HOST=#{@host}",
36
+ "--env LETSENCRYPT_EMAIL=#{SmartMachine.config.sysadmin_email}",
37
+ "--env LETSENCRYPT_TEST=false",
38
+ "--env MINIO_ACCESS_KEY=#{@access_key}",
39
+ "--env MINIO_SECRET_KEY=#{@secret_key}",
40
+ "--env MINIO_BROWSER=#{@browser}",
41
+ "--env MINIO_WORM=#{@worm}",
42
+ "--user `id -u`:`id -g`",
43
+ "--volume='#{@home_dir}/smartmachine/grids/minio/#{@name}/data:/data'",
44
+ "--restart='always'",
45
+ "--network='#{@name}-network'",
46
+ "minio/minio:RELEASE.2020-02-27T00-23-05Z server /data"
47
+ ]
48
+ if system(command.compact.join(" "), out: File::NULL)
49
+ # The alias is necessary to support internal network requests directed to minio container using public url
50
+ system("docker network connect --alias #{@host} #{@name}-network nginx")
51
+ system("docker network connect nginx-network #{@name}")
51
52
 
52
- def down
53
- if SmartMachine::Docker.running?
54
- # Disconnecting networks
55
- system("docker network disconnect nginx-network minio")
56
- system("docker network disconnect minio-network nginx")
53
+ puts "done"
54
+ puts "-----> Starting container #{@name} ... "
55
+ if system("docker start #{@name}", out: File::NULL)
56
+ puts "done"
57
+ else
58
+ raise "Error: Could not start the created #{@name} container"
59
+ end
60
+ else
61
+ raise "Error: Could not create #{@name} container"
62
+ end
63
+ end
57
64
 
58
- # Stopping & Removing containers - in reverse order
59
- print "-----> Stopping container minio ... "
60
- if system("docker stop 'minio'", out: File::NULL)
61
- puts "done"
62
- print "-----> Removing container minio ... "
63
- if system("docker rm 'minio'", out: File::NULL)
64
- puts "done"
65
- end
66
- end
65
+ def downer
66
+ # Disconnecting networks
67
+ system("docker network disconnect nginx-network #{@name}")
68
+ system("docker network disconnect #{@name}-network nginx")
67
69
 
68
- # Removing networks
69
- print "-----> Removing network minio-network ... "
70
- if system("docker network rm minio-network", out: File::NULL)
71
- puts "done"
72
- end
73
- end
74
- end
75
- end
76
- end
77
- end
70
+ # Stopping & Removing containers - in reverse order
71
+ print "-----> Stopping container #{@name} ... "
72
+ if system("docker stop '#{@name}'", out: File::NULL)
73
+ puts "done"
74
+ print "-----> Removing container #{@name} ... "
75
+ if system("docker rm '#{@name}'", out: File::NULL)
76
+ puts "done"
77
+ end
78
+ end
79
+
80
+ # Removing networks
81
+ print "-----> Removing network #{@name}-network ... "
82
+ if system("docker network rm #{@name}-network", out: File::NULL)
83
+ puts "done"
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end