Module: Dapp::Dimg::Build::Stage::Mod::Logging

Included in:
Base
Defined in:
lib/dapp/dimg/build/stage/mod/logging.rb

Instance Method Summary collapse

Instance Method Details

#ignore_log_commands?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/dapp/dimg/build/stage/mod/logging.rb', line 74

def ignore_log_commands?
  false
end

#image_should_be_introspected?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/dapp/dimg/build/stage/mod/logging.rb', line 82

def image_should_be_introspected?
  dimg.stage_should_be_introspected?(name) && !dimg.dapp.dry_run?
end

#log_buildObject



18
19
20
21
22
23
# File 'lib/dapp/dimg/build/stage/mod/logging.rb', line 18

def log_build
  dimg.dapp.with_log_indent do
    dimg.dapp.log_info dimg.dapp.t(code: 'image.signature', data: { signature: image_name })
    log_image_details unless empty?
  end
end

#log_image_buildObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/dapp/dimg/build/stage/mod/logging.rb', line 7

def log_image_build
  case
  when image.built?           then log_state(:using_cache)
  when should_be_not_present? then log_state(:not_present)
  when dimg.dapp.dry_run?     then log_state(:build, styles: { status: :success })
  else yield
  end
ensure
  log_build
end

#log_image_commandsObject



56
57
58
59
60
# File 'lib/dapp/dimg/build/stage/mod/logging.rb', line 56

def log_image_commands
  return if (bash_commands = image.send(:bash_commands)).empty?
  dimg.dapp.log_info dimg.dapp.t(code: 'image.commands')
  dimg.dapp.with_log_indent { dimg.dapp.log_info bash_commands.join("\n") }
end

#log_image_created_atObject



40
41
42
43
# File 'lib/dapp/dimg/build/stage/mod/logging.rb', line 40

def log_image_created_at
  dimg.dapp.log_info dimg.dapp.t(code: 'image.info.created_at',
                                 data: { value: Time.parse(image.created_at).localtime })
end

#log_image_detailsObject



25
26
27
28
29
30
31
32
# File 'lib/dapp/dimg/build/stage/mod/logging.rb', line 25

def log_image_details
  if image.tagged?
    log_image_created_at
    log_image_size
  end
  log_image_commands unless ignore_log_commands?
  log_image_instructions
end

#log_image_instructionsObject



34
35
36
37
38
# File 'lib/dapp/dimg/build/stage/mod/logging.rb', line 34

def log_image_instructions
  return if (instructions = image.prepare_instructions(image.send(:change_options))).empty?
  dimg.dapp.log_info dimg.dapp.t(code: 'image.instructions')
  dimg.dapp.with_log_indent { dimg.dapp.log_info instructions.join("\n") }
end

#log_image_sizeObject



45
46
47
48
49
50
51
52
53
54
# File 'lib/dapp/dimg/build/stage/mod/logging.rb', line 45

def log_image_size
  if !prev_stage.nil? && from_image.tagged?
    bytes = image.size - from_image.size
    code = 'image.info.difference'
  else
    bytes = image.size
    code = 'image.info.mb_size'
  end
  dimg.dapp.log_info dimg.dapp.t(code: code, data: { mb: (bytes / 1000 / 1000).round(3) })
end

#log_nameObject



62
63
64
# File 'lib/dapp/dimg/build/stage/mod/logging.rb', line 62

def log_name
  dimg.dapp.t(code: name, context: log_name_context)
end

#log_name_contextObject



66
67
68
# File 'lib/dapp/dimg/build/stage/mod/logging.rb', line 66

def log_name_context
  :stage
end

#log_state(state_code, styles: {}) ⇒ Object



70
71
72
# File 'lib/dapp/dimg/build/stage/mod/logging.rb', line 70

def log_state(state_code, styles: {})
  dimg.dapp.log_state(log_name, state: dimg.dapp.t(code: state_code, context: 'state'), styles: styles)
end

#should_not_be_detailed?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/dapp/dimg/build/stage/mod/logging.rb', line 78

def should_not_be_detailed?
  image.send(:bash_commands).empty?
end