Class: Kuby::Docker::Dockerfile

Inherits:
Object
  • Object
show all
Defined in:
lib/kuby/docker/dockerfile.rb

Defined Under Namespace

Classes: Cmd, Command, Copy, Env, Expose, From, Run, Workdir

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDockerfile

Returns a new instance of Dockerfile.



70
71
72
73
# File 'lib/kuby/docker/dockerfile.rb', line 70

def initialize
  @commands = []
  @cursor = 0
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



68
69
70
# File 'lib/kuby/docker/dockerfile.rb', line 68

def commands
  @commands
end

#cursorObject (readonly)

Returns the value of attribute cursor.



68
69
70
# File 'lib/kuby/docker/dockerfile.rb', line 68

def cursor
  @cursor
end

Instance Method Details

#cmd(*args) ⇒ Object



99
100
101
# File 'lib/kuby/docker/dockerfile.rb', line 99

def cmd(*args)
  add Cmd.new(*args)
end

#copy(*args, **kwargs) ⇒ Object



91
92
93
# File 'lib/kuby/docker/dockerfile.rb', line 91

def copy(*args, **kwargs)
  add Copy.new(*args, **kwargs)
end

#env(*args) ⇒ Object



83
84
85
# File 'lib/kuby/docker/dockerfile.rb', line 83

def env(*args)
  add Env.new(*args)
end

#expose(*args) ⇒ Object



95
96
97
# File 'lib/kuby/docker/dockerfile.rb', line 95

def expose(*args)
  add Expose.new(*args)
end

#exposed_portsObject



107
108
109
110
111
# File 'lib/kuby/docker/dockerfile.rb', line 107

def exposed_ports
  commands
    .select { |c| c.is_a?(Expose) }
    .map { |c| c.args.first }
end

#from(*args, **kwargs) ⇒ Object



75
76
77
# File 'lib/kuby/docker/dockerfile.rb', line 75

def from(*args, **kwargs)
  add From.new(*args, **kwargs)
end

#insert_at(pos) ⇒ Object



113
114
115
116
117
118
# File 'lib/kuby/docker/dockerfile.rb', line 113

def insert_at(pos)
  @cursor = pos
  yield
ensure
  @cursor = commands.size
end

#run(*args) ⇒ Object



87
88
89
# File 'lib/kuby/docker/dockerfile.rb', line 87

def run(*args)
  add Run.new(*args)
end

#to_sObject



103
104
105
# File 'lib/kuby/docker/dockerfile.rb', line 103

def to_s
  commands.map(&:to_s).join("\n")
end

#workdir(*args) ⇒ Object



79
80
81
# File 'lib/kuby/docker/dockerfile.rb', line 79

def workdir(*args)
  add Workdir.new(*args)
end