Class: SmartMachine::Buildpackers::Buildpacker

Inherits:
SmartMachine::Base show all
Defined in:
lib/smart_machine/buildpackers/buildpacker.rb

Instance Method Summary collapse

Methods inherited from SmartMachine::Base

#machine_has_engine_installed?, #platform_on_machine?, #user_bash

Methods included from Logger

configure_logger_for, included, #logger, logger_for

Constructor Details

#initialize(packname:) ⇒ Buildpacker

Returns a new instance of Buildpacker.



4
5
6
# File 'lib/smart_machine/buildpackers/buildpacker.rb', line 4

def initialize(packname:)
  @packname = packname
end

Instance Method Details

#installerObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/smart_machine/buildpackers/buildpacker.rb', line 8

def installer
  if @packname == "rails"
    unless system("docker image inspect #{rails_image_name}", [:out, :err] => File::NULL)
      print "-----> Creating image #{rails_image_name} ... "
      command = [
        "docker image build -t #{rails_image_name}",
        "--build-arg SMARTMACHINE_VERSION=#{SmartMachine.version}",
        "--build-arg USER_UID=`id -u`",
        "--build-arg USER_NAME=`id -un`",
        "-<<'EOF'\n#{dockerfile_rails}EOF"
      ]
      if system(command.join(" "), out: File::NULL)
        puts "done"
      end
    end
  else
    raise "Error: Pack with name #{name} not supported."
  end
end

#packerObject



41
42
43
44
45
46
47
48
# File 'lib/smart_machine/buildpackers/buildpacker.rb', line 41

def packer
  if @packname == "rails" && File.exist?("bin/rails")
    rails = SmartMachine::Buildpackers::Rails.new(appname: nil, appversion: nil)
    rails.packer
  else
    raise "Error: Pack with name #{@packname} not supported."
  end
end

#uninstallerObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/smart_machine/buildpackers/buildpacker.rb', line 28

def uninstaller
  if @packname == "rails"
    if system("docker image inspect #{rails_image_name}", [:out, :err] => File::NULL)
      print "-----> Removing image #{rails_image_name} ... "
      if system("docker image rm #{rails_image_name}", out: File::NULL)
        puts "done"
      end
    end
  else
    raise "Error: Pack with name #{name} not supported."
  end
end