Class: Kuby::Docker::Dockerfile
- Inherits:
-
Object
- Object
- Kuby::Docker::Dockerfile
- Defined in:
- lib/kuby/docker/dockerfile.rb
Defined Under Namespace
Classes: Arg, Cmd, Command, Copy, Env, Expose, From, Run, Workdir
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
T::Sig::WithoutRuntime.sig { returns(T::Array) }.
-
#cursor ⇒ Object
readonly
T::Sig::WithoutRuntime.sig { returns(Integer) }.
Instance Method Summary collapse
-
#arg(*args) ⇒ Object
T::Sig::WithoutRuntime.sig { params(args: String).void }.
-
#checksum ⇒ Object
T::Sig::WithoutRuntime.sig { returns(String) }.
-
#cmd(*args) ⇒ Object
T::Sig::WithoutRuntime.sig { params(args: String).void }.
-
#copy(source, dest, from: nil) ⇒ Object
T::Sig::WithoutRuntime.sig { params(source: String, dest: String, from: T.nilable(String)).void }.
-
#current_workdir ⇒ Object
T::Sig::WithoutRuntime.sig { returns(T.nilable(String)) }.
-
#env(*args) ⇒ Object
T::Sig::WithoutRuntime.sig { params(args: String).void }.
-
#expose(port) ⇒ Object
T::Sig::WithoutRuntime.sig { params(port: Integer).void }.
-
#exposed_ports ⇒ Object
T::Sig::WithoutRuntime.sig { returns(T::Array) }.
-
#from(image_url, as: nil) ⇒ Object
T::Sig::WithoutRuntime.sig { params(image_url: String, as: T.nilable(String)).void }.
-
#initialize ⇒ Dockerfile
constructor
T::Sig::WithoutRuntime.sig { void }.
-
#insert_at(pos, &block) ⇒ Object
T::Sig::WithoutRuntime.sig { params(pos: Integer, block: T.proc.void).void }.
-
#run(*args) ⇒ Object
T::Sig::WithoutRuntime.sig { params(args: String).void }.
-
#to_s ⇒ Object
T::Sig::WithoutRuntime.sig { returns(String) }.
-
#workdir(*args) ⇒ Object
T::Sig::WithoutRuntime.sig { params(args: String).void }.
Constructor Details
#initialize ⇒ Dockerfile
T::Sig::WithoutRuntime.sig { void }
111 112 113 114 |
# File 'lib/kuby/docker/dockerfile.rb', line 111 def initialize @commands = [] @cursor = 0 end |
Instance Attribute Details
#commands ⇒ Object (readonly)
T::Sig::WithoutRuntime.sig { returns(T::Array) }
105 106 107 |
# File 'lib/kuby/docker/dockerfile.rb', line 105 def commands @commands end |
#cursor ⇒ Object (readonly)
T::Sig::WithoutRuntime.sig { returns(Integer) }
108 109 110 |
# File 'lib/kuby/docker/dockerfile.rb', line 108 def cursor @cursor end |
Instance Method Details
#arg(*args) ⇒ Object
T::Sig::WithoutRuntime.sig { params(args: String).void }
132 133 134 |
# File 'lib/kuby/docker/dockerfile.rb', line 132 def arg(*args) add Arg.new(args) end |
#checksum ⇒ Object
T::Sig::WithoutRuntime.sig { returns(String) }
163 164 165 |
# File 'lib/kuby/docker/dockerfile.rb', line 163 def checksum Digest::SHA256.hexdigest(to_s) end |
#cmd(*args) ⇒ Object
T::Sig::WithoutRuntime.sig { params(args: String).void }
152 153 154 |
# File 'lib/kuby/docker/dockerfile.rb', line 152 def cmd(*args) add Cmd.new(args) end |
#copy(source, dest, from: nil) ⇒ Object
T::Sig::WithoutRuntime.sig { params(source: String, dest: String, from: T.nilable(String)).void }
142 143 144 |
# File 'lib/kuby/docker/dockerfile.rb', line 142 def copy(source, dest, from: nil) add Copy.new(source, dest, from: from) end |
#current_workdir ⇒ Object
T::Sig::WithoutRuntime.sig { returns(T.nilable(String)) }
175 176 177 178 179 180 181 |
# File 'lib/kuby/docker/dockerfile.rb', line 175 def current_workdir found = commands.reverse_each.find do |command| command.is_a?(Kuby::Docker::Dockerfile::Workdir) end found.args.first if found end |
#env(*args) ⇒ Object
T::Sig::WithoutRuntime.sig { params(args: String).void }
127 128 129 |
# File 'lib/kuby/docker/dockerfile.rb', line 127 def env(*args) add Env.new(args) end |
#expose(port) ⇒ Object
T::Sig::WithoutRuntime.sig { params(port: Integer).void }
147 148 149 |
# File 'lib/kuby/docker/dockerfile.rb', line 147 def expose(port) add Expose.new([port]) end |
#exposed_ports ⇒ Object
T::Sig::WithoutRuntime.sig { returns(T::Array) }
168 169 170 171 172 |
# File 'lib/kuby/docker/dockerfile.rb', line 168 def exposed_ports commands .select { |c| c.is_a?(Expose) } .map { |c| c.args.first } end |
#from(image_url, as: nil) ⇒ Object
T::Sig::WithoutRuntime.sig { params(image_url: String, as: T.nilable(String)).void }
117 118 119 |
# File 'lib/kuby/docker/dockerfile.rb', line 117 def from(image_url, as: nil) add From.new(image_url, as: as) end |
#insert_at(pos, &block) ⇒ Object
T::Sig::WithoutRuntime.sig { params(pos: Integer, block: T.proc.void).void }
184 185 186 187 188 189 |
# File 'lib/kuby/docker/dockerfile.rb', line 184 def insert_at(pos, &block) @cursor = pos yield ensure @cursor = commands.size end |
#run(*args) ⇒ Object
T::Sig::WithoutRuntime.sig { params(args: String).void }
137 138 139 |
# File 'lib/kuby/docker/dockerfile.rb', line 137 def run(*args) add Run.new(args) end |
#to_s ⇒ Object
T::Sig::WithoutRuntime.sig { returns(String) }
157 158 159 160 |
# File 'lib/kuby/docker/dockerfile.rb', line 157 def to_s # ensure trailing newline "#{commands.map(&:to_s).join("\n")}\n" end |