Class: MRubyPortable::Docker
- Inherits:
-
Object
- Object
- MRubyPortable::Docker
- Defined in:
- lib/mruby_portable/docker.rb
Constant Summary collapse
- IMAGE_REPOSITORY =
"mruby-portable-builder"
Instance Attribute Summary collapse
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
Instance Method Summary collapse
- #available? ⇒ Boolean
- #build_image ⇒ Object
- #build_image_command ⇒ Object
- #ensure_image! ⇒ Object
- #image_exists? ⇒ Boolean
-
#initialize(runner: Runner.new, image: "#{IMAGE_REPOSITORY}:#{VERSION}") ⇒ Docker
constructor
A new instance of Docker.
- #run_build(workspace) ⇒ Object
- #run_build_command(workspace) ⇒ Object
Constructor Details
#initialize(runner: Runner.new, image: "#{IMAGE_REPOSITORY}:#{VERSION}") ⇒ Docker
Returns a new instance of Docker.
9 10 11 12 |
# File 'lib/mruby_portable/docker.rb', line 9 def initialize(runner: Runner.new, image: "#{IMAGE_REPOSITORY}:#{VERSION}") @runner = runner @image = image end |
Instance Attribute Details
#image ⇒ Object (readonly)
Returns the value of attribute image.
7 8 9 |
# File 'lib/mruby_portable/docker.rb', line 7 def image @image end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
7 8 9 |
# File 'lib/mruby_portable/docker.rb', line 7 def runner @runner end |
Instance Method Details
#available? ⇒ Boolean
14 15 16 |
# File 'lib/mruby_portable/docker.rb', line 14 def available? runner.success?(["docker", "version"]) end |
#build_image ⇒ Object
28 29 30 |
# File 'lib/mruby_portable/docker.rb', line 28 def build_image runner.run!(build_image_command) end |
#build_image_command ⇒ Object
36 37 38 |
# File 'lib/mruby_portable/docker.rb', line 36 def build_image_command ["docker", "build", "-t", image, Paths.template("docker")] end |
#ensure_image! ⇒ Object
22 23 24 25 26 |
# File 'lib/mruby_portable/docker.rb', line 22 def ensure_image! raise Error, "Docker is not available" unless available? build_image unless image_exists? end |
#image_exists? ⇒ Boolean
18 19 20 |
# File 'lib/mruby_portable/docker.rb', line 18 def image_exists? runner.success?(["docker", "image", "inspect", image]) end |
#run_build(workspace) ⇒ Object
32 33 34 |
# File 'lib/mruby_portable/docker.rb', line 32 def run_build(workspace) runner.run!(run_build_command(workspace)) end |
#run_build_command(workspace) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mruby_portable/docker.rb', line 40 def run_build_command(workspace) script = [ "if [ -f app_bundle.rb ]; then /usr/local/mruby/build/host/bin/mrbc -B mruby_portable_app_irep -o generated_irep.c app_bundle.rb; fi", "cmake -S . -B build -DMRUBY_BUILD_DIR=/usr/local/mruby/build/psp_without_gems", "cmake --build build" ].join(" && ") [ "docker", "run", "--rm", "-v", "#{File.(workspace)}:/workspace", "-w", "/workspace", image, "bash", "-lc", script ] end |