smartmachine 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -14
  3. data/lib/smart_machine/apps/container.rb +1 -0
  4. data/lib/smart_machine/apps/manager.rb +1 -1
  5. data/lib/smart_machine/base.rb +6 -0
  6. data/lib/smart_machine/buildpackers/buildpacker.rb +49 -1
  7. data/lib/smart_machine/buildpackers/rails.rb +87 -12
  8. data/lib/smart_machine/commands/grid.rb +8 -0
  9. data/lib/smart_machine/commands/grid_commands/elasticsearch.rb +0 -3
  10. data/lib/smart_machine/commands/grid_commands/nextcloud.rb +65 -0
  11. data/lib/smart_machine/commands/grid_commands/terminal.rb +107 -0
  12. data/lib/smart_machine/commands/machine.rb +8 -0
  13. data/lib/smart_machine/configuration.rb +23 -1
  14. data/lib/smart_machine/credentials.rb +9 -0
  15. data/lib/smart_machine/docker.rb +10 -9
  16. data/lib/smart_machine/engine.rb +44 -9
  17. data/lib/smart_machine/grids/nextcloud.rb +93 -0
  18. data/lib/smart_machine/grids/prereceiver/Dockerfile +10 -13
  19. data/lib/smart_machine/grids/redis.rb +8 -3
  20. data/lib/smart_machine/grids/redmine.rb +61 -0
  21. data/lib/smart_machine/grids/terminal/entrypoint.rb +95 -0
  22. data/lib/smart_machine/grids/terminal/haproxy.cfg +45 -0
  23. data/lib/smart_machine/grids/terminal/init.el +310 -0
  24. data/lib/smart_machine/grids/terminal/wetty.rb +44 -0
  25. data/lib/smart_machine/grids/terminal.rb +179 -0
  26. data/lib/smart_machine/machine.rb +26 -5
  27. data/lib/smart_machine/syncer.rb +8 -7
  28. data/lib/smart_machine/templates/dotsmartmachine/config/nextcloud.yml +27 -0
  29. data/lib/smart_machine/templates/dotsmartmachine/config/redis.yml +6 -1
  30. data/lib/smart_machine/templates/dotsmartmachine/config/terminal.yml +13 -0
  31. data/lib/smart_machine/templates/dotsmartmachine/grids/nginx/fastcgi.conf +1 -1
  32. data/lib/smart_machine/templates/dotsmartmachine/grids/nginx/nginx.tmpl +448 -314
  33. data/lib/smart_machine/version.rb +3 -3
  34. data/lib/smart_machine.rb +3 -1
  35. metadata +57 -24
  36. data/lib/smart_machine/buildpackers/rails/Dockerfile +0 -21
  37. data/lib/smart_machine/commands/grid_commands/scheduler.rb +0 -15
  38. data/lib/smart_machine/engine/Dockerfile +0 -30
  39. data/lib/smart_machine/grids/elasticsearch/.keep +0 -0
  40. data/lib/smart_machine/grids/minio/.keep +0 -0
  41. data/lib/smart_machine/grids/nginx/.keep +0 -0
  42. data/lib/smart_machine/grids/prereceiver/fcgiwrap/APKBUILD +0 -49
  43. data/lib/smart_machine/grids/prereceiver/fcgiwrap/fcgiwrap.confd +0 -6
  44. data/lib/smart_machine/grids/prereceiver/fcgiwrap/fcgiwrap.initd +0 -43
  45. data/lib/smart_machine/grids/prereceiver/fcgiwrap/fcgiwrap.pre-install +0 -7
  46. data/lib/smart_machine/grids/prereceiver/fcgiwrap/packages/main/x86_64/APKINDEX.tar.gz +0 -0
  47. data/lib/smart_machine/grids/prereceiver/fcgiwrap/packages/main/x86_64/fcgiwrap-1.1.1-r4.apk +0 -0
  48. data/lib/smart_machine/grids/prereceiver/fcgiwrap/packages/main/x86_64/fcgiwrap-doc-1.1.1-r4.apk +0 -0
  49. data/lib/smart_machine/grids/prereceiver/fcgiwrap/packages/main/x86_64/fcgiwrap-openrc-1.1.1-r4.apk +0 -0
  50. data/lib/smart_machine/grids/redis/.keep +0 -0
  51. data/lib/smart_machine/grids/scheduler/Dockerfile +0 -14
  52. data/lib/smart_machine/grids/scheduler.rb +0 -188
  53. data/lib/smart_machine/templates/dotsmartmachine/grids/scheduler/crontabs/.keep +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d77d6ff76ab2f6f4337bebd16aa3151238818d1abc8adc35acbf70bc6d7d4489
4
- data.tar.gz: c4bdace421a0d57b8ad4604660ab0950217720cb9aa7a9f3d037ae2ab6e8ee3e
3
+ metadata.gz: 5f4220956064ccc882a0f4bce3a90921b42e7904a1b46c93b5a5786e9b384a01
4
+ data.tar.gz: fa860c7a78280a2b0db69ff3acbdd133ce426efffd52583ad1cdf887ab910bc7
5
5
  SHA512:
6
- metadata.gz: df9e0408228f0af69b30ab32d2754f9231e25656b8947032d44ea9b592ca436c269df8f3a7f0ea77a9330e4e726d2cca9a727e7bcd1d037b21648f17c0cad376
7
- data.tar.gz: c9b22b7c5d2ba4b82ce3d7d17f8254d51f3dc9cf8d805a3a554bf4becec31b46d3ef80b8d3cb582a529d652a3b0f67cb7f6e33c853421863f87dd7ff5e7f7123
6
+ metadata.gz: 2b40194c50f6137985819f3fe5b190ed2fe08104f9e9a6149358ba5e4653c1f3ade8e8ac406c583515d4c50b16603aec0fa745b623d6e1a1bdf175fbdf584a97
7
+ data.tar.gz: c7cb2b875385bf57215ac80f19ae326c9af54e6a2870eefd2016b74a37b0cad410595efbbd1698811cf8d9ed70bba9a0d235308eb8d00988803e42603eea1fff
data/README.md CHANGED
@@ -50,13 +50,9 @@ Add your credentials using:
50
50
 
51
51
  $ smartmachine credentials:edit
52
52
 
53
- Add your environment details using: - Coming Soon
53
+ Add your config details with your favourite editor (here emacs is shown):
54
54
 
55
- $ smartmachine environment:edit
56
-
57
- Add your users using:
58
-
59
- $ smartmachine grid nginx users:edit
55
+ $ emacs ./config
60
56
 
61
57
  Install docker, and add UFW rules for Docker if specified at the end of installation.
62
58
 
@@ -111,14 +107,6 @@ Lets you run redis server instance for cache storage and job queueing.
111
107
  $ smartmachine grid redis up
112
108
  $ smartmachine grid redis down
113
109
 
114
- #### 6. Scheduler Grid - Coming Soon
115
- Lets you setup scheduling services like database backups, etc.
116
-
117
- $ smartmachine grid scheduler install
118
- $ smartmachine grid scheduler up
119
- $ smartmachine grid scheduler down
120
- $ smartmachine grid scheduler uninstall
121
-
122
110
  ### Setup Your Apps
123
111
 
124
112
  Create your apps and manage them.
@@ -26,6 +26,7 @@ module SmartMachine
26
26
  "--workdir /app",
27
27
  "--expose='3000'",
28
28
  "--volume='#{@home_dir}/smartmachine/config/environment.rb:#{@home_dir}/machine/config/environment.rb'",
29
+ "--volume='#{@home_dir}/smartmachine/apps/containers/#{@appname}/asdf:#{@home_dir}/.asdf'",
29
30
  "--volume='#{@home_dir}/smartmachine/apps/containers/#{@appname}/releases/#{@appversion}:/app'",
30
31
  "--volume='#{@home_dir}/smartmachine/apps/containers/#{@appname}/app/vendor/bundle:/app/vendor/bundle'",
31
32
  "--volume='#{@home_dir}/smartmachine/apps/containers/#{@appname}/app/public/assets:/app/public/assets'",
@@ -105,7 +105,7 @@ module SmartMachine
105
105
 
106
106
  def containerize_process!(name:, config:)
107
107
  container = SmartMachine::Apps::Container.new(name: name, appname: @appname, appversion: @appversion)
108
- if container.create!(using_command: config.dig(:command))
108
+ if container.create!(using_command: user_bash(config.dig(:command)))
109
109
  networks = config.dig(:networks)&.split(" ")
110
110
  networks.each do |network|
111
111
  container.connect_to_network!(network_name: network)
@@ -1,5 +1,6 @@
1
1
  require 'smart_machine/logger'
2
2
  require "active_support/inflector"
3
+ require 'active_support/core_ext/string/filters'
3
4
 
4
5
  module SmartMachine
5
6
  class Base
@@ -25,5 +26,10 @@ module SmartMachine
25
26
  machine = SmartMachine::Machine.new
26
27
  machine.run_on_machine(commands: ["which smartengine | grep -q '/smartengine'"])
27
28
  end
29
+
30
+ def user_bash(command)
31
+ remove_envs = %w(RUBY_MAJOR RUBY_VERSION RUBY_DOWNLOAD_SHA256 GEM_HOME BUNDLE_APP_CONFIG BUNDLE_SILENCE_ROOT_WARNING)
32
+ 'env -u ' + remove_envs.join(' -u ') + ' bash --login -c \'' + command + '\''
33
+ end
28
34
  end
29
35
  end
@@ -14,7 +14,7 @@ module SmartMachine
14
14
  "--build-arg SMARTMACHINE_VERSION=#{SmartMachine.version}",
15
15
  "--build-arg USER_UID=`id -u`",
16
16
  "--build-arg USER_NAME=`id -un`",
17
- "#{SmartMachine.config.gem_dir}/lib/smart_machine/buildpackers/rails"
17
+ "-<<'EOF'\n#{dockerfile_rails}EOF"
18
18
  ]
19
19
  if system(command.join(" "), out: File::NULL)
20
20
  puts "done"
@@ -53,6 +53,54 @@ module SmartMachine
53
53
  "smartmachine/buildpackers/rails:#{SmartMachine.version}"
54
54
  end
55
55
 
56
+ def dockerfile_rails
57
+ file = <<~'DOCKERFILE'
58
+ ARG SMARTMACHINE_VERSION
59
+
60
+ FROM smartmachine/smartengine:$SMARTMACHINE_VERSION
61
+ LABEL maintainer="plainsource <plainsource@humanmind.me>"
62
+
63
+ RUN apt-get update && \
64
+ apt-get install -y --no-install-recommends \
65
+ # dependencies for ruby from https://github.com/rbenv/ruby-build/wiki#ubuntudebianmint
66
+ autoconf \
67
+ bison \
68
+ patch \
69
+ build-essential \
70
+ rustc \
71
+ libssl-dev \
72
+ libyaml-dev \
73
+ libreadline6-dev \
74
+ zlib1g-dev \
75
+ libgmp-dev \
76
+ libncurses5-dev \
77
+ libffi-dev \
78
+ libgdbm6 \
79
+ libgdbm-dev \
80
+ libdb-dev \
81
+ uuid-dev && \
82
+ # ruby on rails
83
+ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
84
+ echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
85
+ apt-get update && \
86
+ apt-get install -y --no-install-recommends \
87
+ tzdata \
88
+ nodejs \
89
+ yarn \
90
+ libmariadb-dev \
91
+ libvips42 \
92
+ ffmpeg \
93
+ mupdf \
94
+ mupdf-tools \
95
+ poppler-utils && \
96
+ rm -rf /var/lib/apt/lists/*
97
+
98
+ CMD ["smartmachine", "buildpacker", "packer", "rails"]
99
+ DOCKERFILE
100
+
101
+ format(file)
102
+ end
103
+
56
104
  # These swapfile methods can be used (after required modification), when you need to make swapfile for more memory.
57
105
  # def self.create_swapfile
58
106
  # # Creating swapfile for bundler to work properly
@@ -42,6 +42,7 @@ module SmartMachine
42
42
  FileUtils.mkdir_p("#{@container_path}/app/public/packs")
43
43
  FileUtils.mkdir_p("#{@container_path}/app/node_modules")
44
44
  FileUtils.mkdir_p("#{@container_path}/app/storage")
45
+ FileUtils.mkdir_p("#{@container_path}/asdf")
45
46
  FileUtils.mkdir_p("#{@container_path}/releases/#{@appversion}/vendor/bundle")
46
47
  FileUtils.mkdir_p("#{@container_path}/releases/#{@appversion}/public/assets")
47
48
  FileUtils.mkdir_p("#{@container_path}/releases/#{@appversion}/public/packs")
@@ -62,13 +63,15 @@ module SmartMachine
62
63
  def packer
63
64
  set_logger_formatter_arrow
64
65
 
66
+ # TODO: The exec of final process should be done only in the Manager#containerize_process! and should be removed from here.
67
+ # This method should only pack a fully functioning container and do nothing else.
65
68
  if File.exist? "tmp/smartmachine/packed"
66
69
  begin
67
70
  pid = File.read('tmp/smartmachine/packed').to_i
68
71
  Process.kill('QUIT', pid)
69
72
  rescue Errno::ESRCH # No such process
70
73
  end
71
- exec "bundle", "exec", "puma", "--config", "config/puma.rb"
74
+ exec(user_bash("bundle exec puma --config config/puma.rb"))
72
75
  else
73
76
  if initial_setup? && bundle_install? && precompile_assets? && db_migrate? && test_web_server?
74
77
  logger.formatter = nil
@@ -89,18 +92,90 @@ module SmartMachine
89
92
  def initial_setup?
90
93
  logger.info "Performing initial setup ..."
91
94
 
92
- exit_status = nil
95
+ set_logger_formatter_tabs
93
96
 
94
97
  # Fix for mysql2 gem to support sha256_password, until it is fixed in main mysql2 gem.
95
98
  # https://github.com/brianmario/mysql2/issues/1023
96
- exit_status = system("mkdir -p ./lib/mariadb && ln -s /usr/lib/mariadb/plugin ./lib/mariadb/plugin")
99
+ unless system("mkdir -p ./lib/mariadb && ln -s /usr/lib/mariadb/plugin ./lib/mariadb/plugin")
100
+ logger.error "Could not setup fix for mysql2 mariadb folders."
101
+ return false
102
+ end
97
103
 
98
- if exit_status
99
- return true
100
- else
101
- logger.error "Could not complete initial setup."
104
+ # Install asdf
105
+ system("echo '\n# asdf version manager\nif [ -f \"$HOME/.asdf/asdf.sh\" ]; then\n . \"$HOME/.asdf/asdf.sh\"\nfi\nif [ -f \"$HOME/.asdf/completions/asdf.bash\" ]; then\n . \"$HOME/.asdf/completions/asdf.bash\"\nfi' >> ~/.profile", out: File::NULL)
106
+ unless system(user_bash("asdf --version"), [:out, :err] => File::NULL)
107
+ asdf_version = `git -c 'versionsort.suffix=-' ls-remote --exit-code --refs --sort='version:refname' --tags https://github.com/asdf-vm/asdf.git '*.*.*' | tail --lines=1 | cut --delimiter='/' --fields=3`.strip
108
+ logger.info "Installing asdf #{asdf_version}...\n"
109
+
110
+ # Clear all files inside .asdf dir including dot files.
111
+ system("rm -rf ~/.asdf/..?* ~/.asdf/.[!.]* ~/.asdf/*")
112
+ Open3.popen2e(user_bash("git -c advice.detachedHead=false clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch #{asdf_version}")) do |stdin, stdout_and_stderr, wait_thr|
113
+ stdout_and_stderr.each { |line| logger.info "#{line}" }
114
+ end
115
+
116
+ unless system(user_bash("asdf --version"), [:out, :err] => File::NULL)
117
+ logger.error "Could not install asdf.\n"
118
+ return false
119
+ end
120
+ end
121
+ logger.info "Using asdf " + `#{user_bash("asdf --version")}`.strip + "\n"
122
+
123
+ # Install ruby
124
+ ruby_version = `sed -n '/RUBY VERSION/{n;p}' Gemfile.lock`.strip.split(" ").last&.split("p")&.first
125
+ if ruby_version.nil? || ruby_version.empty?
126
+ logger.error "Could not find ruby version. Have you specified it explicitly in Gemfile and run bundle install?\n"
127
+ return false
128
+ end
129
+
130
+ unless `#{user_bash('ruby -e "puts RUBY_VERSION"')}`.strip == ruby_version
131
+ logger.info "Installing ruby v#{ruby_version}\n"
132
+
133
+ Open3.popen2e(user_bash("asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git")) do |stdin, stdout_and_stderr, wait_thr|
134
+ stdout_and_stderr.each { |line| logger.info "#{line}" }
135
+ end
136
+ Open3.popen2e(user_bash("asdf plugin update ruby")) do |stdin, stdout_and_stderr, wait_thr|
137
+ stdout_and_stderr.each { |line| logger.info "#{line}" }
138
+ end
139
+ Open3.popen2e(user_bash("asdf install ruby #{ruby_version}")) do |stdin, stdout_and_stderr, wait_thr|
140
+ stdout_and_stderr.each { |line| logger.info "#{line}" }
141
+ end
142
+ Open3.popen2e(user_bash("asdf local ruby #{ruby_version}")) do |stdin, stdout_and_stderr, wait_thr|
143
+ stdout_and_stderr.each { |line| logger.info "#{line}" }
144
+ end
145
+
146
+ unless `#{user_bash('ruby -e "puts RUBY_VERSION"')}`.strip == ruby_version
147
+ logger.error "Could not install ruby with version #{ruby_version}. Please try another valid version that asdf supports.\n"
148
+ return false
149
+ end
150
+ end
151
+ logger.info "Using ruby v" + `#{user_bash('ruby -e "puts RUBY_VERSION"')}`.strip + "\n"
152
+
153
+ # Install bundler
154
+ bundler_version = `sed -n '/BUNDLED WITH/{n;p}' Gemfile.lock`.strip
155
+ if bundler_version.nil? || bundler_version.empty?
156
+ logger.error "Could not find bundler version. Please ensure BUNDLED_WITH section is present in your Gemfile.lock.\n"
102
157
  return false
103
158
  end
159
+
160
+ unless system(user_bash("gem list -i '^bundler$' --version #{bundler_version}"), out: File::NULL)
161
+ logger.info "Installing bundler v#{bundler_version}\n"
162
+
163
+ Open3.popen2e(user_bash("gem install --no-document bundler -v #{bundler_version}")) do |stdin, stdout_and_stderr, wait_thr|
164
+ stdout_and_stderr.each { |line| logger.info "#{line}" }
165
+ end
166
+
167
+ unless system(user_bash("gem list -i '^bundler$' --version #{bundler_version}"), out: File::NULL)
168
+ logger.error "Could not install bundler with version #{bundler_version}.\n"
169
+ return false
170
+ end
171
+ end
172
+ system("alias bundle='bundle _#{bundler_version}_'")
173
+ system("alias bundler='bundler _#{bundler_version}_'")
174
+ logger.info "Using bundler v" + bundler_version + "\n"
175
+
176
+ set_logger_formatter_arrow
177
+
178
+ return true
104
179
  end
105
180
 
106
181
  # Perform bundle install
@@ -109,13 +184,13 @@ module SmartMachine
109
184
 
110
185
  set_logger_formatter_tabs
111
186
 
112
- unless system("bundle config set deployment 'true' && bundle config set clean 'true'")
187
+ unless system(user_bash("bundle config set --local deployment 'true' && bundle config set --local clean 'true'"))
113
188
  logger.error "Could not complete bundle config setting."
114
189
  return false
115
190
  end
116
191
 
117
192
  exit_status = nil
118
- Open3.popen2e("bundle", "install") do |stdin, stdout_and_stderr, wait_thr|
193
+ Open3.popen2e(user_bash("bundle install")) do |stdin, stdout_and_stderr, wait_thr|
119
194
  stdout_and_stderr.each { |line| logger.info "#{line}" }
120
195
  exit_status = wait_thr.value.success?
121
196
  end
@@ -135,7 +210,7 @@ module SmartMachine
135
210
 
136
211
  set_logger_formatter_tabs
137
212
  exit_status = nil
138
- Open3.popen2e("bundle", "exec", "rails", "assets:precompile") do |stdin, stdout_and_stderr, wait_thr|
213
+ Open3.popen2e(user_bash("bundle exec rails assets:precompile")) do |stdin, stdout_and_stderr, wait_thr|
139
214
  stdout_and_stderr.each { |line| logger.info "#{line}" }
140
215
  exit_status = wait_thr.value.success?
141
216
  end
@@ -157,7 +232,7 @@ module SmartMachine
157
232
 
158
233
  set_logger_formatter_tabs
159
234
  exit_status = nil
160
- Open3.popen2e("bundle", "exec", "rails", "db:migrate") do |stdin, stdout_and_stderr, wait_thr|
235
+ Open3.popen2e(user_bash("bundle exec rails db:migrate")) do |stdin, stdout_and_stderr, wait_thr|
161
236
  stdout_and_stderr.each { |line| logger.info "#{line}" }
162
237
  exit_status = wait_thr.value.success?
163
238
  end
@@ -181,7 +256,7 @@ module SmartMachine
181
256
  FileUtils.rm_f("tmp/smartmachine/packed")
182
257
 
183
258
  # Spawn Process
184
- pid = Process.spawn("bundle", "exec", "puma", "--config", "config/puma.rb", out: File::NULL)
259
+ pid = Process.spawn(user_bash("bundle exec puma --config config/puma.rb"), out: File::NULL)
185
260
  Process.detach(pid)
186
261
 
187
262
  # Sleep
@@ -2,9 +2,11 @@ require 'smart_machine/commands/grid_commands/sub_thor'
2
2
  require 'smart_machine/commands/grid_commands/elasticsearch'
3
3
  require 'smart_machine/commands/grid_commands/minio'
4
4
  require 'smart_machine/commands/grid_commands/mysql'
5
+ require 'smart_machine/commands/grid_commands/nextcloud'
5
6
  require 'smart_machine/commands/grid_commands/nginx'
6
7
  require 'smart_machine/commands/grid_commands/prereceiver'
7
8
  require 'smart_machine/commands/grid_commands/redis'
9
+ require 'smart_machine/commands/grid_commands/terminal'
8
10
 
9
11
  module SmartMachine
10
12
  module Commands
@@ -20,6 +22,9 @@ module SmartMachine
20
22
  desc "mysql", "Run mysql grid commands"
21
23
  subcommand "mysql", GridCommands::Mysql
22
24
 
25
+ desc "nextcloud", "Run nextcloud grid commands"
26
+ subcommand "nextcloud", GridCommands::Nextcloud
27
+
23
28
  desc "nginx", "Run nginx grid commands"
24
29
  subcommand "nginx", GridCommands::Nginx
25
30
 
@@ -28,6 +33,9 @@ module SmartMachine
28
33
 
29
34
  desc "redis", "Run redis grid commands"
30
35
  subcommand "redis", GridCommands::Redis
36
+
37
+ desc "terminal", "Run terminal grid commands"
38
+ subcommand "terminal", GridCommands::Terminal
31
39
  end
32
40
  end
33
41
  end
@@ -11,7 +11,6 @@ module SmartMachine
11
11
  with_docker_running do
12
12
  machine = SmartMachine::Machine.new
13
13
  name_option = options[:name] ? " --name=#{options[:name]}" : ""
14
- machine.run_on_machine commands: "echo 'vm.max_map_count=262144' | sudo tee /etc/sysctl.d/60-smartmachine-elasticsearch.conf && sudo sysctl --system"
15
14
  machine.run_on_machine commands: "smartengine grid elasticsearch uper#{name_option}"
16
15
  end
17
16
  end
@@ -25,8 +24,6 @@ module SmartMachine
25
24
  machine = SmartMachine::Machine.new
26
25
  name_option = options[:name] ? " --name=#{options[:name]}" : ""
27
26
  machine.run_on_machine commands: "smartengine grid elasticsearch downer#{name_option}"
28
- # NOTE: sysctl does not reset this setting until restart of system even after sudo sysctl --system is run.
29
- machine.run_on_machine commands: "test $(docker ps -aq --filter label=smartmachine.elasticsearch.name | wc -l) -eq 0 && test -f /etc/sysctl.d/60-smartmachine-elasticsearch.conf && sudo rm /etc/sysctl.d/60-smartmachine-elasticsearch.conf && sudo sysctl --system"
30
27
  end
31
28
  end
32
29
  end
@@ -0,0 +1,65 @@
1
+ module SmartMachine
2
+ module Commands
3
+ module GridCommands
4
+ class Nextcloud < SubThor
5
+ include Utilities
6
+
7
+ desc "up", "Take UP the nextcloud grid"
8
+ option :name, type: :string
9
+ def up
10
+ inside_machine_dir do
11
+ with_docker_running do
12
+ machine = SmartMachine::Machine.new
13
+ name_option = options[:name] ? " --name=#{options[:name]}" : ""
14
+ machine.run_on_machine commands: "smartengine grid nextcloud uper#{name_option}"
15
+ end
16
+ end
17
+ end
18
+
19
+ desc "down", "Take DOWN the nextcloud grid"
20
+ option :name, type: :string
21
+ def down
22
+ inside_machine_dir do
23
+ with_docker_running do
24
+ machine = SmartMachine::Machine.new
25
+ name_option = options[:name] ? " --name=#{options[:name]}" : ""
26
+ machine.run_on_machine commands: "smartengine grid nextcloud downer#{name_option}"
27
+ end
28
+ end
29
+ end
30
+
31
+ desc "uper", "Nextcloud grid uper", hide: true
32
+ option :name, type: :string
33
+ def uper
34
+ inside_engine_machine_dir do
35
+ if options[:name]
36
+ nextcloud = SmartMachine::Grids::Nextcloud.new(name: options[:name])
37
+ nextcloud.uper
38
+ else
39
+ SmartMachine.config.grids.nextcloud.each do |name, config|
40
+ nextcloud = SmartMachine::Grids::Nextcloud.new(name: name.to_s)
41
+ nextcloud.uper
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ desc "downer", "Nextcloud grid downer", hide: true
48
+ option :name, type: :string
49
+ def downer
50
+ inside_engine_machine_dir do
51
+ if options[:name]
52
+ nextcloud = SmartMachine::Grids::Nextcloud.new(name: options[:name])
53
+ nextcloud.downer
54
+ else
55
+ SmartMachine.config.grids.nextcloud.each do |name, config|
56
+ nextcloud = SmartMachine::Grids::Nextcloud.new(name: name.to_s)
57
+ nextcloud.downer
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,107 @@
1
+ module SmartMachine
2
+ module Commands
3
+ module GridCommands
4
+ class Terminal < SubThor
5
+ include Utilities
6
+
7
+ desc "install", "Install terminal grid"
8
+ def install
9
+ inside_machine_dir do
10
+ with_docker_running do
11
+ puts "-----> Installing Terminal"
12
+ machine = SmartMachine::Machine.new
13
+ machine.run_on_machine commands: "smartengine grid terminal installer"
14
+ puts "-----> Terminal Installation Complete"
15
+ end
16
+ end
17
+ end
18
+
19
+ desc "uninstall", "Uninstall terminal grid"
20
+ def uninstall
21
+ inside_machine_dir do
22
+ with_docker_running do
23
+ puts "-----> Uninstalling Terminal"
24
+ machine = SmartMachine::Machine.new
25
+ machine.run_on_machine commands: "smartengine grid terminal uninstaller"
26
+ puts "-----> Terminal Uninstallation Complete"
27
+ end
28
+ end
29
+ end
30
+
31
+ desc "up", "Take UP the terminal grid"
32
+ option :name, type: :string
33
+ def up
34
+ inside_machine_dir do
35
+ with_docker_running do
36
+ machine = SmartMachine::Machine.new
37
+ name_option = options[:name] ? " --name=#{options[:name]}" : ""
38
+ machine.run_on_machine commands: "smartengine grid terminal uper#{name_option}"
39
+ end
40
+ end
41
+ end
42
+
43
+ desc "down", "Take DOWN the terminal grid"
44
+ option :name, type: :string
45
+ def down
46
+ inside_machine_dir do
47
+ with_docker_running do
48
+ machine = SmartMachine::Machine.new
49
+ name_option = options[:name] ? " --name=#{options[:name]}" : ""
50
+ machine.run_on_machine commands: "smartengine grid terminal downer#{name_option}"
51
+ end
52
+ end
53
+ end
54
+
55
+ desc "installer", "Terminal grid installer", hide: true
56
+ def installer
57
+ inside_engine_machine_dir do
58
+ name, config = SmartMachine.config.grids.terminal.first
59
+ terminal = SmartMachine::Grids::Terminal.new(name: name.to_s)
60
+ terminal.installer
61
+ end
62
+ end
63
+
64
+ desc "uninstaller", "Terminal grid uninstaller", hide: true
65
+ def uninstaller
66
+ inside_engine_machine_dir do
67
+ name, config = SmartMachine.config.grids.terminal.first
68
+ terminal = SmartMachine::Grids::Terminal.new(name: name.to_s)
69
+ terminal.uninstaller
70
+ end
71
+ end
72
+
73
+ desc "uper", "Terminal grid uper", hide: true
74
+ option :name, type: :string
75
+ def uper
76
+ inside_engine_machine_dir do
77
+ if options[:name]
78
+ terminal = SmartMachine::Grids::Terminal.new(name: options[:name])
79
+ terminal.uper
80
+ else
81
+ SmartMachine.config.grids.terminal.each do |name, config|
82
+ terminal = SmartMachine::Grids::Terminal.new(name: name.to_s)
83
+ terminal.uper
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ desc "downer", "Terminal grid downer", hide: true
90
+ option :name, type: :string
91
+ def downer
92
+ inside_engine_machine_dir do
93
+ if options[:name]
94
+ terminal = SmartMachine::Grids::Terminal.new(name: options[:name])
95
+ terminal.downer
96
+ else
97
+ SmartMachine.config.grids.terminal.each do |name, config|
98
+ terminal = SmartMachine::Grids::Terminal.new(name: name.to_s)
99
+ terminal.downer
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
@@ -3,6 +3,14 @@ module SmartMachine
3
3
  class Machine < Thor
4
4
  include Utilities
5
5
 
6
+ desc "setup", "Initial setup of the machine"
7
+ def setup
8
+ inside_machine_dir do
9
+ machine = SmartMachine::Machine.new
10
+ machine.setup
11
+ end
12
+ end
13
+
6
14
  desc "ssh", "SSH into the machine"
7
15
  def ssh
8
16
  inside_machine_dir do
@@ -14,7 +14,7 @@ module SmartMachine
14
14
  private
15
15
 
16
16
  def grids
17
- @grids ||= OpenStruct.new(elasticsearch: elasticsearch, minio: minio, mysql: mysql, prereceiver: prereceiver, redis: redis)
17
+ @grids ||= OpenStruct.new(elasticsearch: elasticsearch, minio: minio, mysql: mysql, nextcloud: nextcloud, prereceiver: prereceiver, redis: redis, terminal: terminal)
18
18
  end
19
19
 
20
20
  def elasticsearch
@@ -50,6 +50,17 @@ module SmartMachine
50
50
  end
51
51
  end
52
52
 
53
+ def nextcloud
54
+ # Once the SmartMachine.config assignments in smart_machine.rb file has been removed, then this file exist condition can be removed to ensure that config/nextcloud.yml always exists
55
+ if File.exist? "config/nextcloud.yml"
56
+ deserialize(IO.binread("config/nextcloud.yml")).deep_symbolize_keys
57
+ elsif File.exist? "#{File.expand_path('~')}/machine/config/nextcloud.yml"
58
+ deserialize(IO.binread("#{File.expand_path('~')}/machine/config/nextcloud.yml")).deep_symbolize_keys
59
+ else
60
+ {}
61
+ end
62
+ end
63
+
53
64
  def prereceiver
54
65
  # Once the SmartMachine.config assignments in smart_machine.rb file has been removed, then this file exist condition can be removed to ensure that config/prereceiver.yml always exists
55
66
  if File.exist? "config/prereceiver.yml"
@@ -72,6 +83,17 @@ module SmartMachine
72
83
  end
73
84
  end
74
85
 
86
+ def terminal
87
+ # Once the SmartMachine.config assignments in smart_machine.rb file has been removed, then this file exist condition can be removed to ensure that config/terminal.yml always exists
88
+ if File.exist? "config/terminal.yml"
89
+ deserialize(IO.binread("config/terminal.yml")).deep_symbolize_keys
90
+ elsif File.exist? "#{File.expand_path('~')}/machine/config/terminal.yml"
91
+ deserialize(IO.binread("#{File.expand_path('~')}/machine/config/terminal.yml")).deep_symbolize_keys
92
+ else
93
+ {}
94
+ end
95
+ end
96
+
75
97
  def deserialize(config)
76
98
  YAML.load(ERB.new(config).result).presence || {}
77
99
  end
@@ -66,6 +66,15 @@ module SmartMachine
66
66
  database_name: #{SecureRandom.hex(8)}
67
67
  redisone:
68
68
  password: #{SecureRandom.hex(16)}
69
+ nextcloudone:
70
+ admin_user: #{SecureRandom.hex(8)}
71
+ admin_password: #{SecureRandom.hex(16)}
72
+ mysql_user: #{SecureRandom.hex(8)}
73
+ mysql_password: #{SecureRandom.hex(16)}
74
+ mysql_database_name: #{SecureRandom.hex(8)}
75
+ terminalone:
76
+ username: #{SecureRandom.hex(8)}
77
+ password: #{SecureRandom.hex(16)}
69
78
  YAML
70
79
  end
71
80
 
@@ -47,13 +47,14 @@ module SmartMachine
47
47
  def install_on_linuxos(distro_name:, arch:)
48
48
 
49
49
  commands = [
50
- "sudo apt-get -y update",
51
- "sudo apt-get -y install apt-transport-https ca-certificates curl gnupg-agent software-properties-common",
52
- "curl -fsSL https://download.docker.com/linux/#{distro_name}/gpg | sudo apt-key add -",
53
- "sudo apt-key fingerprint 0EBFCD88",
54
- "sudo add-apt-repository \"deb [arch=#{arch}] https://download.docker.com/linux/#{distro_name} $(lsb_release -cs) stable\"",
55
- "sudo apt-get -y update",
56
- "sudo apt-get -y install docker-ce docker-ce-cli containerd.io",
50
+ "sudo apt-get update",
51
+ "sudo apt-get install -y ca-certificates curl gnupg lsb-release",
52
+ "sudo mkdir -p /etc/apt/keyrings",
53
+ "sudo rm -f /etc/apt/keyrings/docker.gpg",
54
+ "curl -fsSL https://download.docker.com/linux/#{distro_name}/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg",
55
+ "echo \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/#{distro_name} $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null",
56
+ "sudo apt-get update",
57
+ "sudo apt-get install -y docker-ce docker-ce-cli containerd.io",
57
58
  "sudo usermod -aG docker $USER",
58
59
  "docker run --rm hello-world",
59
60
  "docker rmi hello-world"
@@ -95,8 +96,8 @@ module SmartMachine
95
96
  def uninstall_on_linuxos(distro_name:, arch:)
96
97
 
97
98
  commands = [
98
- "sudo apt-get purge docker-ce docker-ce-cli containerd.io",
99
- "sudo apt-get autoremove",
99
+ "sudo apt-get purge -y docker-ce docker-ce-cli containerd.io",
100
+ "sudo apt-get autoremove -y",
100
101
  "sudo rm -rf /var/lib/docker",
101
102
  "sudo rm -rf /var/lib/containerd"
102
103
  ]