Class: Rum::Manifest
- Inherits:
-
Object
- Object
- Rum::Manifest
- Extended by:
- Forwardable
- Includes:
- Rake::DSL
- Defined in:
- lib/rumrunner/manifest.rb
Overview
Rum Runner Manifest for managing Docker commands.
Instance Attribute Summary collapse
-
#image ⇒ Object
readonly
Access Docker image object.
Instance Method Summary collapse
-
#application ⇒ Object
Get application.
-
#artifact(*args, &block) ⇒ Object
Defines docker run task for redirecting a file from a running instance of the dependent stage’s container to the local file system.
-
#build(*args, &block) ⇒ Object
Defines generic docker build task.
-
#default(*args, &block) ⇒ Object
Defines the default task for
rum
executable. -
#initialize(name:, root: nil, &block) ⇒ Manifest
constructor
Initialize new manifest with name and root path for caching build digests.
-
#install ⇒ Object
Install any remaining tasks for the manifest.
-
#run(*args, &block) ⇒ Object
Defines generic docker run task.
-
#shell(*args, &block) ⇒ Object
Defines docker run task for shelling into the given stage.
-
#stage(*args, &block) ⇒ Object
Defines docker build task for the given stage.
Constructor Details
#initialize(name:, root: nil, &block) ⇒ Manifest
Initialize new manifest with name and root path for caching build digests. Evaluates &block
if given.
Example:
Manifest.new(name: "my_image", root: ".docker")
27 28 29 30 31 32 33 |
# File 'lib/rumrunner/manifest.rb', line 27 def initialize(name:, root:nil, &block) @name = name @root = root || :".docker" @image = Docker::Image.parse(name) @env = [] instance_eval(&block) if block_given? end |
Instance Attribute Details
#image ⇒ Object (readonly)
Access Docker image object.
14 15 16 |
# File 'lib/rumrunner/manifest.rb', line 14 def image @image end |
Instance Method Details
#application ⇒ Object
Get application
37 38 39 |
# File 'lib/rumrunner/manifest.rb', line 37 def application Rake.application end |
#artifact(*args, &block) ⇒ Object
Defines docker run task for redirecting a file from a running instance of the dependent stage’s container to the local file system.
Example:
artifact :name => [:stage]
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/rumrunner/manifest.rb', line 131 def artifact(*args, &block) name, _, deps = Rake.application.resolve_args(args) target = deps.first image = Docker::Image.parse("#{@image}-#{target}") iidfile = File.join(root, *image) path = File.split(name).first deps = [iidfile] unless path == "." directory path deps << path end artifact_file name, deps, iidfile, &block artifact_clobber name, path end |
#build(*args, &block) ⇒ Object
Defines generic docker build task.
Example:
build :name
build :name => [:deps]
60 61 62 63 64 65 |
# File 'lib/rumrunner/manifest.rb', line 60 def build(*args, &block) name, _, deps = Rake.application.resolve_args(args) task name => deps do sh Docker::Build.new(options: , &block).to_s end end |
#default(*args, &block) ⇒ Object
Defines the default task for rum
executable.
Example:
default :task_or_file
default :task_or_file => [:deps]
48 49 50 51 |
# File 'lib/rumrunner/manifest.rb', line 48 def default(*args, &block) name = Rake.application.resolve_args(args).first task :default => name end |
#install ⇒ Object
Install any remaining tasks for the manifest.
177 178 179 180 181 |
# File 'lib/rumrunner/manifest.rb', line 177 def install install_clean self end |
#run(*args, &block) ⇒ Object
Defines generic docker run task.
Example:
run :name
run :name => [:deps]
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rumrunner/manifest.rb', line 74 def run(*args, &block) name, _, deps = Rake.application.resolve_args(args) images = deps.map{|dep| Docker::Image.parse("#{@image}-#{dep}") } iidfiles = images.map{|image| File.join(root, *image) } task name => iidfiles do image = iidfiles.empty? ? to_s : File.read(iidfiles.first) sh Docker::Run.new(options: , image: image, &block).to_s end end |
#shell(*args, &block) ⇒ Object
Defines docker run task for shelling into the given stage.
Example:
shell :stage
shell :stage => [:deps]
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/rumrunner/manifest.rb', line 157 def shell(*args, &block) target = Rake.application.resolve_args(args).first name = task_name shell: target image = Docker::Image.parse("#{@image}-#{target}") iidfile = File.join(root, *image) Rake::Task[name].clear if Rake::Task.task_defined?(name) desc "Shell into `#{target}` stage" task name, [:shell] => iidfile do |t,args| digest = File.read(iidfile) shell = args.any? ? args.to_a.join(" ") : "/bin/sh" run = Docker::Run.new(options: , image: digest, &block) run.with_defaults(entrypoint: shell, interactive:true, rm: true, tty: true) sh run.to_s end end |
#stage(*args, &block) ⇒ Object
Defines docker build task for the given stage.
Example:
stage :name
stage :name => [:deps]
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/rumrunner/manifest.rb', line 93 def stage(*args, &block) name, _, deps = Rake.application.resolve_args(args) # Assemble image/iidfile from manifest/stage name image = Docker::Image.parse("#{@image}-#{name}") iidfile = File.join(root, *image) iidpath = File.split(iidfile).first # Ensure path to iidfile exists iiddeps = if deps.empty? directory iidpath iidpath else images = deps.map{|x| Docker::Image.parse("#{@image}-#{x}") } images.map{|x| File.join(root, *x) } end # Build stage and save digest in iidfile stage_file iidfile, iiddeps, tag: image, target: name, &block # Shortcut to build stage by name stage_task name, iidfile # Shell into stage stage_shell name, iidfile # Clean stage stage_clean name, iidfile, deps end |