smartmachine 0.8.0 → 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 (86) 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 +75 -57
  45. data/lib/smart_machine/grids/scheduler/Dockerfile +1 -1
  46. data/lib/smart_machine/logger.rb +26 -26
  47. data/lib/smart_machine/machine.rb +128 -194
  48. data/lib/smart_machine/scp.rb +15 -0
  49. data/lib/smart_machine/ssh.rb +69 -40
  50. data/lib/smart_machine/syncer.rb +133 -0
  51. data/lib/smart_machine/templates/dotsmartmachine/Gemfile +7 -0
  52. data/lib/smart_machine/templates/dotsmartmachine/config/elasticsearch.yml +5 -0
  53. data/lib/smart_machine/templates/dotsmartmachine/config/environment.rb +0 -9
  54. data/lib/smart_machine/templates/dotsmartmachine/config/minio.yml +13 -0
  55. data/lib/smart_machine/templates/dotsmartmachine/config/mysql/schedule.rb +3 -3
  56. data/lib/smart_machine/templates/dotsmartmachine/config/mysql.yml +13 -0
  57. data/lib/smart_machine/templates/dotsmartmachine/config/prereceiver.yml +7 -0
  58. data/lib/smart_machine/templates/dotsmartmachine/config/redis.yml +15 -0
  59. data/lib/smart_machine/templates/dotsmartmachine/config/users.yml +1 -1
  60. data/lib/smart_machine/templates/dotsmartmachine/gitignore-template +47 -0
  61. data/lib/smart_machine/templates/dotsmartmachine/{grids/elasticsearch/data → vendor}/.keep +0 -0
  62. data/lib/smart_machine/version.rb +30 -6
  63. data/lib/smart_machine.rb +42 -16
  64. metadata +97 -47
  65. data/CHANGELOG.rdoc +0 -0
  66. data/MIT-LICENSE +0 -21
  67. data/README.rdoc +0 -87
  68. data/bin/buildpacker +0 -8
  69. data/bin/prereceiver +0 -8
  70. data/bin/scheduler +0 -18
  71. data/bin/smartmachine +0 -81
  72. data/bin/smartrunner +0 -33
  73. data/lib/smart_machine/apps/rails.rb +0 -250
  74. data/lib/smart_machine/apps.rb +0 -14
  75. data/lib/smart_machine/boot.rb +0 -32
  76. data/lib/smart_machine/buildpacker.rb +0 -106
  77. data/lib/smart_machine/gem_version.rb +0 -17
  78. data/lib/smart_machine/grids.rb +0 -18
  79. data/lib/smart_machine/sync.rb +0 -120
  80. data/lib/smart_machine/templates/dotsmartmachine/grids/elasticsearch/logs/.keep +0 -0
  81. data/lib/smart_machine/templates/dotsmartmachine/grids/minio/data/.keep +0 -0
  82. data/lib/smart_machine/templates/dotsmartmachine/grids/mysql/backups/.keep +0 -0
  83. data/lib/smart_machine/templates/dotsmartmachine/grids/mysql/data/.keep +0 -0
  84. data/lib/smart_machine/templates/dotsmartmachine/grids/prereceiver/pre-receive +0 -17
  85. data/lib/smart_machine/templates/dotsmartmachine/grids/redis/data/.keep +0 -0
  86. data/lib/smart_machine/user.rb +0 -38
data/bin/smartrunner DELETED
@@ -1,33 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "smart_machine"
4
-
5
- command = ARGV.shift
6
-
7
- machine = SmartMachine::Machine.new
8
-
9
- case command
10
- when "grids"
11
- grids = SmartMachine::Grids.new
12
- grids.run ARGV
13
-
14
- when "apps"
15
- grids = SmartMachine::Apps.new
16
- grids.run ARGV
17
-
18
- when "buildpacker"
19
- action = ARGV.shift
20
- buildpacker = SmartMachine::Buildpacker.new
21
- buildpacker.public_send(action, *ARGV)
22
-
23
- when "prereceiver"
24
- action = ARGV.shift
25
- prereceiver = SmartMachine::Grids::Prereceiver.new
26
- prereceiver.public_send(action, *ARGV)
27
-
28
- when "scheduler"
29
- action = ARGV.shift
30
- scheduler = SmartMachine::Grids::Scheduler.new
31
- scheduler.public_send(action, *ARGV)
32
-
33
- end
@@ -1,250 +0,0 @@
1
- # The main SmartMachine Apps Rails driver
2
- module SmartMachine
3
- class Apps
4
- class Rails < SmartMachine::Base
5
- def initialize
6
- end
7
-
8
- def start(appname, container_path, container_path_with_version)
9
- return unless File.exist? "#{container_path_with_version}/bin/rails"
10
-
11
- logger.formatter = proc do |severity, datetime, progname, message|
12
- severity_text = { "DEBUG" => "\u{1f527} #{severity}:", "INFO" => " \u{276f}", "WARN" => "\u{2757} #{severity}:",
13
- "ERROR" => "\u{274c} #{severity}:", "FATAL" => "\u{2b55} #{severity}:", "UNKNOWN" => "\u{2753} #{severity}:"
14
- }
15
- "\t\t\t\t#{severity_text[severity]} #{message}\n"
16
- end
17
-
18
- logger.info "Ruby on Rails application detected."
19
-
20
- # Setup rails env
21
- env_path = "#{container_path}/env"
22
- system("grep -q '^## Rails' #{env_path} || echo '## Rails' >> #{env_path}")
23
- system("grep -q '^MALLOC_ARENA_MAX=' #{env_path} || echo '# MALLOC_ARENA_MAX=2' >> #{env_path}")
24
- system("grep -q '^RAILS_ENV=' #{env_path} || echo 'RAILS_ENV=production' >> #{env_path}")
25
- system("grep -q '^RACK_ENV=' #{env_path} || echo 'RACK_ENV=production' >> #{env_path}")
26
- system("grep -q '^RAILS_LOG_TO_STDOUT=' #{env_path} || echo 'RAILS_LOG_TO_STDOUT=enabled' >> #{env_path}")
27
- system("grep -q '^RAILS_SERVE_STATIC_FILES=' #{env_path} || echo 'RAILS_SERVE_STATIC_FILES=enabled' >> #{env_path}")
28
- system("grep -q '^LANG=' #{env_path} || echo 'LANG=en_US.UTF-8' >> #{env_path}")
29
- system("grep -q '^RAILS_MASTER_KEY=' #{env_path} || echo 'RAILS_MASTER_KEY=yourmasterkey' >> #{env_path}")
30
- logger.warn "Please set your RAILS_MASTER_KEY env var for this rails app." if system("grep -q '^RAILS_MASTER_KEY=yourmasterkey' #{env_path}")
31
-
32
- # Setup app folders needed for volumes. If this is not created then docker will create it while running the container,
33
- # but the folder will have root user assigned instead of the current user.
34
- FileUtils.mkdir_p("#{container_path}/app/vendor/bundle")
35
- FileUtils.mkdir_p("#{container_path}/app/public/assets")
36
- FileUtils.mkdir_p("#{container_path}/app/public/packs")
37
- FileUtils.mkdir_p("#{container_path}/app/node_modules")
38
- FileUtils.mkdir_p("#{container_path}/app/storage")
39
- FileUtils.mkdir_p("#{container_path_with_version}/vendor/bundle")
40
- FileUtils.mkdir_p("#{container_path_with_version}/public/assets")
41
- FileUtils.mkdir_p("#{container_path_with_version}/public/packs")
42
- FileUtils.mkdir_p("#{container_path_with_version}/node_modules")
43
- FileUtils.mkdir_p("#{container_path_with_version}/storage")
44
-
45
- # Creating & Starting container
46
- container_id = `docker ps -a -q --filter='name=^#{appname}_1$' --filter='status=running'`.chomp
47
- new_container = container_id.empty? ? "#{appname}_1" : "#{appname}_2"
48
- old_container = container_id.empty? ? "#{appname}_2" : "#{appname}_1"
49
-
50
- SmartMachine::Apps::App.stop("#{new_container}")
51
- if system("docker create \
52
- --name='#{new_container}' \
53
- --env-file='#{container_path}/env' \
54
- --user `id -u`:`id -g` \
55
- --workdir /app \
56
- --expose='3000' \
57
- --volume='#{SmartMachine.config.user_home_path}/.smartmachine/config:#{SmartMachine.config.user_home_path}/.smartmachine/config' \
58
- --volume='#{container_path_with_version}:/app' \
59
- --volume='#{container_path}/app/vendor/bundle:/app/vendor/bundle' \
60
- --volume='#{container_path}/app/public/assets:/app/public/assets' \
61
- --volume='#{container_path}/app/public/packs:/app/public/packs' \
62
- --volume='#{container_path}/app/node_modules:/app/node_modules' \
63
- --volume='#{container_path}/app/storage:/app/storage' \
64
- --restart='always' \
65
- --init \
66
- --network='nginx-network' \
67
- smartmachine/buildpacks/rails:#{SmartMachine.version}", out: File::NULL)
68
-
69
- system("docker network connect elasticsearch-network #{new_container}")
70
- system("docker network connect minio-network #{new_container}")
71
- system("docker network connect mysql-network #{new_container}")
72
-
73
- if system("docker start --attach #{new_container}")
74
- logger.debug "Starting Web Server ..."
75
- if system("docker start #{new_container}", out: File::NULL)
76
- sleep 7
77
- logger.info "Web Server started successfully."
78
- SmartMachine::Apps::App.stop(old_container)
79
- SmartMachine::Apps::App.clean_up(container_path)
80
- logger.info "Launched Application ... Success."
81
- exit 10
82
- end
83
- else
84
- SmartMachine::Apps::App.stop("#{new_container}")
85
- end
86
- end
87
-
88
- logger.formatter = nil
89
- end
90
-
91
- def pack
92
- set_logger_formatter_arrow
93
-
94
- if File.exist? "tmp/smartmachine/packed"
95
- begin
96
- pid = File.read('tmp/smartmachine/packed').to_i
97
- Process.kill('QUIT', pid)
98
- rescue Errno::ESRCH # No such process
99
- end
100
- exec "bundle", "exec", "puma", "--config", "config/puma.rb"
101
- else
102
- if initial_setup? && bundle_install? && precompile_assets? && db_migrate? && test_web_server?
103
- logger.formatter = nil
104
-
105
- exit 0
106
- else
107
- logger.error "Could not continue ... Launch Failed."
108
- logger.formatter = nil
109
-
110
- exit 1
111
- end
112
- end
113
- end
114
-
115
- private
116
-
117
- # Perform initial_setup
118
- def initial_setup?
119
- logger.info "Performing initial setup ..."
120
-
121
- exit_status = nil
122
-
123
- # Fix for mysql2 gem to support sha256_password, until it is fixed in main mysql2 gem.
124
- # https://github.com/brianmario/mysql2/issues/1023
125
- exit_status = system("mkdir -p ./lib/mariadb && ln -s /usr/lib/mariadb/plugin ./lib/mariadb/plugin")
126
-
127
- if exit_status
128
- return true
129
- else
130
- logger.error "Could not complete initial setup."
131
- return false
132
- end
133
- end
134
-
135
- # Perform bundle install
136
- def bundle_install?
137
- logger.info "Performing bundle install ..."
138
-
139
- set_logger_formatter_tabs
140
-
141
- unless system("bundle config set deployment 'true' && bundle config set clean 'true'")
142
- logger.error "Could not complete bundle config setting."
143
- return false
144
- end
145
-
146
- exit_status = nil
147
- Open3.popen2e("bundle", "install") do |stdin, stdout_and_stderr, wait_thr|
148
- stdout_and_stderr.each { |line| logger.info "#{line}" }
149
- exit_status = wait_thr.value.success?
150
- end
151
- set_logger_formatter_arrow
152
-
153
- if exit_status
154
- return true
155
- else
156
- logger.error "Could not complete bundle install."
157
- return false
158
- end
159
- end
160
-
161
- # Perform pre-compiling of assets
162
- def precompile_assets?
163
- logger.info "Installing Javascript dependencies & pre-compiling assets ..."
164
-
165
- set_logger_formatter_tabs
166
- exit_status = nil
167
- Open3.popen2e("bundle", "exec", "rails", "assets:precompile") do |stdin, stdout_and_stderr, wait_thr|
168
- stdout_and_stderr.each { |line| logger.info "#{line}" }
169
- exit_status = wait_thr.value.success?
170
- end
171
- set_logger_formatter_arrow
172
-
173
- if exit_status
174
- return true
175
- else
176
- logger.error "Could not install Javascript dependencies or pre-compile assets."
177
- return false
178
- end
179
- end
180
-
181
- # Perform db_migrate
182
- def db_migrate?
183
- return true # remove this line when you want to start using db_migrate?
184
-
185
- logger.info "Performing database migrations ..."
186
-
187
- set_logger_formatter_tabs
188
- exit_status = nil
189
- Open3.popen2e("bundle", "exec", "rails", "db:migrate") do |stdin, stdout_and_stderr, wait_thr|
190
- stdout_and_stderr.each { |line| logger.info "#{line}" }
191
- exit_status = wait_thr.value.success?
192
- end
193
- set_logger_formatter_arrow
194
-
195
- if exit_status
196
- return true
197
- else
198
- logger.error "Could not complete database migrations."
199
- return false
200
- end
201
- end
202
-
203
- # Perform testing of web server
204
- def test_web_server?
205
- logger.info "Setting up Web Server ..."
206
-
207
- # tmp folders
208
- FileUtils.mkdir_p("tmp/pids")
209
- FileUtils.mkdir_p("tmp/smartmachine")
210
- FileUtils.rm_f("tmp/smartmachine/packed")
211
-
212
- # Spawn Process
213
- pid = Process.spawn("bundle", "exec", "puma", "--config", "config/puma.rb", out: File::NULL)
214
- Process.detach(pid)
215
-
216
- # Sleep
217
- sleep 5
218
-
219
- # Check PID running
220
- status = nil
221
- begin
222
- Process.kill(0, pid)
223
- system("echo '#{pid}' > tmp/smartmachine/packed")
224
- status = true
225
- rescue Errno::ESRCH # No such process
226
- logger.info "Web Server could not start"
227
- status = false
228
- end
229
-
230
- # Return status
231
- return status
232
- end
233
-
234
- def set_logger_formatter_arrow
235
- logger.formatter = proc do |severity, datetime, progname, message|
236
- severity_text = { "DEBUG" => "\u{1f527} #{severity}:", "INFO" => " \u{276f}", "WARN" => "\u{2757} #{severity}:",
237
- "ERROR" => "\u{274c} #{severity}:", "FATAL" => "\u{2b55} #{severity}:", "UNKNOWN" => "\u{2753} #{severity}:"
238
- }
239
- "\t\t\t\t#{severity_text[severity]} #{message}\n"
240
- end
241
- end
242
-
243
- def set_logger_formatter_tabs
244
- logger.formatter = proc do |severity, datetime, progname, message|
245
- "\t\t\t\t #{message}"
246
- end
247
- end
248
- end
249
- end
250
- end
@@ -1,14 +0,0 @@
1
- # The main SmartMachine Apps
2
- module SmartMachine
3
- class Apps < SmartMachine::Base
4
- def run(*args)
5
- args.flatten!
6
-
7
- action = args.shift
8
-
9
- raise "invalid action on the app" unless ['create', 'destroy', 'start', 'stop'].include? action
10
-
11
- Object.const_get("SmartMachine::Apps::App").public_send(action, *args)
12
- end
13
- end
14
- end
@@ -1,32 +0,0 @@
1
- # The main SmartMachine Boot driver
2
- module SmartMachine
3
- class Boot < SmartMachine::Base
4
- def initialize
5
- end
6
- end
7
- end
8
-
9
- require 'smart_machine/credentials'
10
-
11
- require 'smart_machine/ssh'
12
- require 'smart_machine/machine'
13
-
14
- require 'smart_machine/docker'
15
- require 'smart_machine/engine'
16
- require 'smart_machine/buildpacker'
17
- require 'smart_machine/sync'
18
-
19
- require 'smart_machine/user'
20
-
21
- require 'smart_machine/grids'
22
- require 'smart_machine/grids/elasticsearch'
23
- require 'smart_machine/grids/minio'
24
- require 'smart_machine/grids/mysql'
25
- require 'smart_machine/grids/nginx'
26
- require 'smart_machine/grids/prereceiver'
27
- require 'smart_machine/grids/scheduler'
28
- require 'smart_machine/grids/solr'
29
-
30
- require 'smart_machine/apps'
31
- require 'smart_machine/apps/app'
32
- require 'smart_machine/apps/rails'
@@ -1,106 +0,0 @@
1
- require 'open3'
2
-
3
- module SmartMachine
4
- class Buildpacker < SmartMachine::Base
5
- def initialize
6
- end
7
-
8
- def install
9
- puts "-----> Installing Buildpacker"
10
-
11
- ssh = SmartMachine::SSH.new
12
- commands = ["smartmachine runner buildpacker create"]
13
- ssh.run commands
14
-
15
- puts "-----> Buildpacker Installation Complete"
16
- end
17
-
18
- def uninstall
19
- puts "-----> Uninstalling Buildpacker"
20
-
21
- ssh = SmartMachine::SSH.new
22
- commands = ["smartmachine runner buildpacker destroy"]
23
- ssh.run commands
24
-
25
- puts "-----> Buildpacker Uninstallation Complete"
26
- end
27
-
28
- def update
29
- self.uninstall
30
- self.install
31
- end
32
-
33
- def create
34
- self.destroy
35
-
36
- unless system("docker image inspect #{buildpacker_image_name}", [:out, :err] => File::NULL)
37
- print "-----> Creating image #{buildpacker_image_name} ... "
38
- if system("docker image build -t #{buildpacker_image_name} \
39
- --build-arg SMARTMACHINE_VERSION=#{SmartMachine.version} \
40
- --build-arg USER_UID=`id -u` \
41
- --build-arg USER_NAME=`id -un` \
42
- #{SmartMachine.config.root_path}/lib/smart_machine/engine/buildpacks/rails", out: File::NULL)
43
- puts "done"
44
- end
45
- end
46
- end
47
-
48
- def destroy
49
- if system("docker image inspect #{buildpacker_image_name}", [:out, :err] => File::NULL)
50
- print "-----> Removing image #{buildpacker_image_name} ... "
51
- if system("docker image rm #{buildpacker_image_name}", out: File::NULL)
52
- puts "done"
53
- end
54
- end
55
- end
56
-
57
- def pack
58
- if File.exist? "bin/rails"
59
- rails = SmartMachine::Apps::Rails.new
60
- rails.pack
61
- end
62
- end
63
-
64
- # These swapfile methods can be used (after required modification), when you need to make swapfile for more memory.
65
- # def self.create_swapfile
66
- # # Creating swapfile for bundler to work properly
67
- # unless system("sudo swapon -s | grep -ci '/swapfile'", out: File::NULL)
68
- # print "-----> Creating swap swapfile ... "
69
- # system("sudo install -o root -g root -m 0600 /dev/null /swapfile", out: File::NULL)
70
- # system("sudo dd if=/dev/zero of=/swapfile bs=1k count=2048k", [:out, :err] => File::NULL)
71
- # system("sudo mkswap /swapfile", out: File::NULL)
72
- # system("sudo sh -c 'echo \"/swapfile none swap sw 0 0\" >> /etc/fstab'", out: File::NULL)
73
- # system("echo 10 | sudo tee /proc/sys/vm/swappiness", out: File::NULL)
74
- # system("sudo sed -i '/^vm.swappiness = /d' /etc/sysctl.conf", out: File::NULL)
75
- # system("echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf", out: File::NULL)
76
- # puts "done"
77
- #
78
- # print "-----> Starting swap swapfile ... "
79
- # if system("sudo swapon /swapfile", out: File::NULL)
80
- # puts "done"
81
- # end
82
- # end
83
- # end
84
- #
85
- # def self.destroy_swapfile
86
- # if system("sudo swapon -s | grep -ci '/swapfile'", out: File::NULL)
87
- # print "-----> Stopping swap swapfile ... "
88
- # if system("sudo swapoff /swapfile", out: File::NULL)
89
- # system("sudo sed -i '/^vm.swappiness = /d' /etc/sysctl.conf", out: File::NULL)
90
- # system("echo 60 | sudo tee /proc/sys/vm/swappiness", out: File::NULL)
91
- # puts "done"
92
- #
93
- # print "-----> Removing swap swapfile ... "
94
- # system("sudo sed -i '/^\\/swapfile/d' /etc/fstab", out: File::NULL)
95
- # if system("sudo rm /swapfile", out: File::NULL)
96
- # puts "done"
97
- # end
98
- # end
99
- # end
100
- # end
101
-
102
- def buildpacker_image_name
103
- "smartmachine/buildpacks/rails:#{SmartMachine.version}"
104
- end
105
- end
106
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SmartMachine
4
- # Returns the version of the currently loaded SmartMachine as a <tt>Gem::Version</tt>.
5
- def self.gem_version
6
- Gem::Version.new VERSION::STRING
7
- end
8
-
9
- module VERSION
10
- MAJOR = 0
11
- MINOR = 8
12
- TINY = 0
13
- PRE = nil
14
-
15
- STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
16
- end
17
- end
@@ -1,18 +0,0 @@
1
- # The main SmartMachine Grids
2
- module SmartMachine
3
- class Grids < SmartMachine::Base
4
- def run(*args)
5
- args.flatten!
6
-
7
- grid_name = args.shift
8
- action = args.shift
9
-
10
- valid_actions = ['up', 'down']
11
- valid_actions.push(*['backup', 'flushlogs']) if grid_name == 'mysql'
12
- valid_actions.push(*["start", "stop"]) if grid_name == 'scheduler'
13
- raise "invalid action on the grid #{grid_name}" unless valid_actions.include? action
14
-
15
- Object.const_get("SmartMachine::Grids::#{grid_name.capitalize}").new.public_send(action, *args)
16
- end
17
- end
18
- end
@@ -1,120 +0,0 @@
1
- module SmartMachine
2
- class Sync < SmartMachine::Base
3
-
4
- def run(**params)
5
- puts "-----> Syncing SmartMachine"
6
-
7
- only = params[:only] ? Array(params[:only]).flatten : [:push, :pull]
8
-
9
- pull if only.include? :pull
10
- yield if block_given?
11
- push if only.include? :push
12
-
13
- puts "-----> Syncing SmartMachine Complete"
14
- end
15
-
16
- private
17
-
18
- def pull
19
- print "-----> Sync pulling ... "
20
- system("rsync -azumv --delete --include={#{pull_files_list}} --exclude=* -e ssh #{SmartMachine.credentials.machine[:username]}@#{SmartMachine.credentials.machine[:address]}:~/.smartmachine/ .")
21
- puts "done"
22
- end
23
-
24
- def push
25
- print "-----> Sync pushing ... "
26
- system("rsync -azumv --delete --include={#{push_files_list}} --exclude=* -e ssh ./ #{SmartMachine.credentials.machine[:username]}@#{SmartMachine.credentials.machine[:address]}:~/.smartmachine")
27
- puts "done"
28
- end
29
-
30
- def pull_files_list
31
- files = [
32
- 'apps/***',
33
-
34
- 'bin/***',
35
-
36
- 'grids',
37
-
38
- 'grids/elasticsearch',
39
- 'grids/elasticsearch/data/***',
40
- 'grids/elasticsearch/logs/***',
41
-
42
- 'grids/minio',
43
- 'grids/minio/data/***',
44
-
45
- 'grids/mysql',
46
- 'grids/mysql/backups/***',
47
- 'grids/mysql/data/***',
48
-
49
- 'grids/nginx',
50
- 'grids/nginx/certificates/***',
51
-
52
- 'grids/scheduler',
53
- 'grids/scheduler/crontabs/***',
54
-
55
- 'grids/solr',
56
- 'grids/solr/solr/***',
57
- ]
58
- files.join(',')
59
- end
60
-
61
- def push_files_list
62
- files = [
63
- 'apps',
64
- 'apps/containers',
65
- 'apps/containers/.keep',
66
- 'apps/repositories',
67
- 'apps/repositories/.keep',
68
-
69
- 'config',
70
- 'config/mysql',
71
- 'config/mysql/schedule.rb',
72
- 'config/credentials.yml.enc',
73
- 'config/environment.rb',
74
-
75
- 'grids',
76
-
77
- 'grids/elasticsearch',
78
- 'grids/elasticsearch/data',
79
- 'grids/elasticsearch/data/.keep',
80
- 'grids/elasticsearch/logs',
81
- 'grids/elasticsearch/logs/.keep',
82
-
83
- 'grids/minio',
84
- 'grids/minio/data',
85
- 'grids/minio/data/.keep',
86
-
87
- 'grids/mysql',
88
- 'grids/mysql/backups',
89
- 'grids/mysql/backups/.keep',
90
- 'grids/mysql/data',
91
- 'grids/mysql/data/.keep',
92
-
93
- 'grids/nginx',
94
- 'grids/nginx/certificates',
95
- 'grids/nginx/certificates/.keep',
96
- 'grids/nginx/htpasswd/***',
97
- 'grids/nginx/fastcgi.conf',
98
- 'grids/nginx/nginx.tmpl',
99
-
100
- 'grids/prereceiver',
101
- 'grids/prereceiver/pre-receive',
102
-
103
- 'grids/redis',
104
- 'grids/redis/data',
105
- 'grids/redis/data/.keep',
106
-
107
- 'grids/scheduler',
108
- 'grids/scheduler/crontabs',
109
- 'grids/scheduler/crontabs/.keep',
110
-
111
- 'grids/solr',
112
- 'grids/solr/solr',
113
- 'grids/solr/solr/.keep',
114
-
115
- 'tmp/***',
116
- ]
117
- files.join(',')
118
- end
119
- end
120
- end
@@ -1,17 +0,0 @@
1
- #!/bin/sh
2
-
3
- # oldrev, newrev, refname are a feature of the way in which Git executes the pre-receive hook.
4
- # See https://www.kernel.org/pub/software/scm/git/docs/githooks.html
5
- while read oldrev newrev refname; do
6
- if [ $(git rev-parse --is-bare-repository) = true ]; then
7
- REPOSITORY_BASENAME=$(basename "$PWD")
8
- REPOSITORY_BASENAME=${REPOSITORY_BASENAME%.git}
9
- else
10
- REPOSITORY_BASENAME=$(basename $(readlink -nf "$PWD"/..))
11
- fi
12
- script --quiet --return --flush --command "prereceiver prereceive $REPOSITORY_BASENAME $REMOTE_USER $oldrev $newrev $refname" /home/$(whoami)/.smartmachine/apps/containers/$REPOSITORY_BASENAME/typescript
13
- if [ "$?" -eq 10 ]; then
14
- exit 0
15
- fi
16
- exit 1
17
- done
@@ -1,38 +0,0 @@
1
- require 'yaml'
2
- require "base64"
3
- require 'bcrypt'
4
-
5
- # The main SmartMachine User driver
6
- module SmartMachine
7
- class User < SmartMachine::Base
8
- def initialize
9
- end
10
-
11
- def self.create_htpasswd_files
12
- htpasswd_dirpath = "#{Dir.pwd}/grids/nginx/htpasswd"
13
-
14
- # Remove existing htpasswd_dirpath
15
- FileUtils.rm_r htpasswd_dirpath if Dir.exist?(htpasswd_dirpath)
16
-
17
- # Create new htpasswd_dirpath
18
- FileUtils.mkdir htpasswd_dirpath
19
-
20
- # Add hostfiles to htpasswd_dirpath
21
- self.get_users_from_file.each do |domainname, users|
22
- next unless users
23
-
24
- file_data = ""
25
- users.each do |user, password|
26
- file_data += "#{user}:#{BCrypt::Password.create(password)}\n"
27
- end
28
- File.open("#{Dir.pwd}/grids/nginx/htpasswd/#{domainname}", "w") { |file| file.write(file_data) }
29
- end
30
- end
31
-
32
- private
33
-
34
- def self.get_users_from_file
35
- YAML.load_file("#{Dir.pwd}/config/users.yml") || Hash.new
36
- end
37
- end
38
- end