Class: Indocker::BuildContext
- Inherits:
-
Object
- Object
- Indocker::BuildContext
- Defined in:
- lib/indocker/build_context.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#helper ⇒ Object
readonly
Returns the value of attribute helper.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
- #build_image(image, build_dir, args: []) ⇒ Object
- #busy? ⇒ Boolean
- #close_session ⇒ Object
- #exec!(command) ⇒ Object
- #image_compiled?(image) ⇒ Boolean
-
#initialize(configuration:, build_server:, logger:) ⇒ BuildContext
constructor
A new instance of BuildContext.
- #set_busy(flag) ⇒ Object
- #set_compiled(image) ⇒ Object
Constructor Details
#initialize(configuration:, build_server:, logger:) ⇒ BuildContext
Returns a new instance of BuildContext.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/indocker/build_context.rb', line 6 def initialize(configuration:, build_server:, logger:) @configuration = configuration @logger = logger @helper = Indocker::BuildContextHelper.new(@configuration, @build_server) @server = build_server if build_server @session = Indocker::SshSession.new( host: build_server.host, user: build_server.user, port: build_server.port, logger: @logger ) end @compiled_images = Hash.new(false) end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
4 5 6 |
# File 'lib/indocker/build_context.rb', line 4 def configuration @configuration end |
#helper ⇒ Object (readonly)
Returns the value of attribute helper.
4 5 6 |
# File 'lib/indocker/build_context.rb', line 4 def helper @helper end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
4 5 6 |
# File 'lib/indocker/build_context.rb', line 4 def logger @logger end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
4 5 6 |
# File 'lib/indocker/build_context.rb', line 4 def server @server end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
4 5 6 |
# File 'lib/indocker/build_context.rb', line 4 def session @session end |
Instance Method Details
#build_image(image, build_dir, args: []) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/indocker/build_context.rb', line 48 def build_image(image, build_dir, args: []) image_name = image.image_name registry = image.registry tag = image.tag FileUtils.cd(build_dir) do if @logger.debug? @logger.debug("#{"Docker image content:".yellow}") Dir[File.join(build_dir, '*')] .map {|path| file = path.gsub(build_dir, '') @logger.debug(" .#{file}".yellow) } .join("\n") end if !@logger.debug? args = args.push('-q') end build_args = args.join(' ') res = Indocker::Docker.build(image.local_registry_url, build_args) if res.exit_status != 0 @logger.error("image compilation :#{image.name} failed") @logger.error(res.stdout) exit 1 end Indocker::Docker.tag(image.local_registry_url, image.registry_url) Indocker::Docker.tag(image.local_registry_url, image.local_registry_url) if !image.registry.is_local? Indocker::Docker.push(image.registry_url) end end end |
#busy? ⇒ Boolean
40 41 42 |
# File 'lib/indocker/build_context.rb', line 40 def busy? !!@busy end |
#close_session ⇒ Object
28 29 30 |
# File 'lib/indocker/build_context.rb', line 28 def close_session @session.close if @session end |
#exec!(command) ⇒ Object
24 25 26 |
# File 'lib/indocker/build_context.rb', line 24 def exec!(command) @session.exec!(command) end |
#image_compiled?(image) ⇒ Boolean
32 33 34 |
# File 'lib/indocker/build_context.rb', line 32 def image_compiled?(image) @compiled_images[image] end |
#set_busy(flag) ⇒ Object
36 37 38 |
# File 'lib/indocker/build_context.rb', line 36 def set_busy(flag) @busy = !!flag end |
#set_compiled(image) ⇒ Object
44 45 46 |
# File 'lib/indocker/build_context.rb', line 44 def set_compiled(image) @compiled_images[image] = true end |