Class: SmartMachine::Machine
Instance Method Summary collapse
-
#create(name:, dev:) ⇒ Object
Create a new smartmachine.
-
#initialize ⇒ Machine
constructor
A new instance of Machine.
- #run_on_machine(commands:) ⇒ Object
- #setup ⇒ Object
Methods inherited from Base
#machine_has_engine_installed?, #platform_on_machine?, #user_bash
Methods included from Logger
configure_logger_for, included, #logger, logger_for
Constructor Details
#initialize ⇒ Machine
Returns a new instance of Machine.
6 7 |
# File 'lib/smart_machine/machine.rb', line 6 def initialize end |
Instance Method Details
#create(name:, dev:) ⇒ Object
Create a new smartmachine
Example:
>> Machine.create("qw21334q")
=> "New machine qw21334q has been created."
Arguments:
name: (String)
dev: (Boolean)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/smart_machine/machine.rb', line 18 def create(name:, dev:) raise "Please specify a machine name" if name.blank? pathname = File. "./#{name}" if Dir.exist?(pathname) puts "A machine with this name already exists. Please use a different name." return end FileUtils.mkdir pathname FileUtils.cp_r "#{SmartMachine.config.gem_dir}/lib/smart_machine/templates/dotsmartmachine/.", pathname FileUtils.chdir pathname do credentials = SmartMachine::Credentials.new credentials.create File.write("Gemfile", File.open("Gemfile",&:read).gsub("replace_ruby_version", "#{SmartMachine.ruby_version}")) File.write(".ruby-version", SmartMachine.ruby_version) if dev File.write("Gemfile", File.open("Gemfile",&:read).gsub("\"~> replace_smartmachine_version\"", "path: \"../\"")) else File.write("Gemfile", File.open("Gemfile",&:read).gsub("replace_smartmachine_version", "#{SmartMachine.version}")) end system("mv gitignore-template .gitignore") # Here BUNDLE_GEMFILE is needed as it may be already set due to usage of bundle exec (which may not be correct in this case) bundle_gemfile = "#{pathname}/Gemfile" system("BUNDLE_GEMFILE='#{bundle_gemfile}' bundle install && BUNDLE_GEMFILE='#{bundle_gemfile}' bundle binstubs smartmachine") system("git init && git add . && git commit -m 'initial commit by SmartMachine #{SmartMachine.version}'") end puts "New machine #{name} has been created." end |
#run_on_machine(commands:) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/smart_machine/machine.rb', line 53 def run_on_machine(commands:) commands = Array(commands).flatten ssh = SmartMachine::SSH.new status = ssh.run commands status[:exit_code] == 0 end |
#setup ⇒ Object
61 62 63 64 65 |
# File 'lib/smart_machine/machine.rb', line 61 def setup getting_started securing_your_server setup_services end |