Class: Kuby::Docker::Dockerfile
- Inherits:
-
Object
- Object
- Kuby::Docker::Dockerfile
show all
- Extended by:
- T::Sig
- Defined in:
- lib/kuby/docker/dockerfile.rb
Defined Under Namespace
Classes: Arg, Cmd, Command, Copy, Env, Expose, From, Run, Workdir
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Dockerfile.
111
112
113
114
|
# File 'lib/kuby/docker/dockerfile.rb', line 111
def initialize
@commands = T.let([], T::Array[Command])
@cursor = T.let(0, Integer)
end
|
Instance Attribute Details
#commands ⇒ Object
Returns the value of attribute commands.
105
106
107
|
# File 'lib/kuby/docker/dockerfile.rb', line 105
def commands
@commands
end
|
#cursor ⇒ Object
Returns the value of attribute cursor.
108
109
110
|
# File 'lib/kuby/docker/dockerfile.rb', line 108
def cursor
@cursor
end
|
Instance Method Details
#arg(*args) ⇒ Object
132
133
134
|
# File 'lib/kuby/docker/dockerfile.rb', line 132
def arg(*args)
add Arg.new(args)
end
|
#checksum ⇒ Object
163
164
165
|
# File 'lib/kuby/docker/dockerfile.rb', line 163
def checksum
Digest::SHA256.hexdigest(to_s)
end
|
#cmd(*args) ⇒ Object
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
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
|
#env(*args) ⇒ Object
127
128
129
|
# File 'lib/kuby/docker/dockerfile.rb', line 127
def env(*args)
add Env.new(args)
end
|
#expose(port) ⇒ Object
147
148
149
|
# File 'lib/kuby/docker/dockerfile.rb', line 147
def expose(port)
add Expose.new([port])
end
|
#exposed_ports ⇒ Object
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| T.cast(c.args.first, Integer) }
end
|
#from(image_url, as: nil) ⇒ Object
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
175
176
177
178
179
180
|
# File 'lib/kuby/docker/dockerfile.rb', line 175
def insert_at(pos, &block)
@cursor = pos
yield
ensure
@cursor = commands.size
end
|
#run(*args) ⇒ Object
137
138
139
|
# File 'lib/kuby/docker/dockerfile.rb', line 137
def run(*args)
add Run.new(args)
end
|
#to_s ⇒ Object
157
158
159
160
|
# File 'lib/kuby/docker/dockerfile.rb', line 157
def to_s
"#{commands.map(&:to_s).join("\n")}\n"
end
|
#workdir(*args) ⇒ Object
122
123
124
|
# File 'lib/kuby/docker/dockerfile.rb', line 122
def workdir(*args)
add Workdir.new(args)
end
|