Class: Drunker::Executor::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/drunker/executor/builder.rb

Constant Summary collapse

IN_PROGRESS =
"IN_PROGRESS"
SUCCEEDED =
"SUCCEEDED"
FAILED =
"FAILED"
TIMED_OUT =
"TIMED_OUT"
STOPPED =
"STOPPED"
RETRY_LIMIT =
3
PHASE_ACCESS_DENIED =
"ACCESS_DENIED"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_name:, targets:, artifact:, config:, logger:) ⇒ Builder

Returns a new instance of Builder.



15
16
17
18
19
20
21
22
23
# File 'lib/drunker/executor/builder.rb', line 15

def initialize(project_name:, targets:, artifact:, config:, logger:)
  @project_name = project_name
  @targets = targets
  @artifact = artifact
  @config = config
  @client = Aws::CodeBuild::Client.new(config.aws_client_options)
  @retry_count = 0
  @logger = logger
end

Instance Attribute Details

#build_idObject (readonly)

Returns the value of attribute build_id.



13
14
15
# File 'lib/drunker/executor/builder.rb', line 13

def build_id
  @build_id
end

Instance Method Details

#access_denied?Boolean

Sometimes ‘* is not authorized to perform` or `Not authorized to perform` error occurs… It is judged that this is not a problem by user setting.

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
# File 'lib/drunker/executor/builder.rb', line 45

def access_denied?
  return false unless failed?
  result.builds[0].phases.any? do |phase|
    phase.contexts&.any? do |context|
      context.status_code == PHASE_ACCESS_DENIED && access_denied_message_included?(context.message)
    end
  end
end

#errorsObject



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/drunker/executor/builder.rb', line 74

def errors
  return unless failed?
  result.builds[0].phases.each_with_object([]) do |phase, results|
    phase.contexts&.each do |context|
      results << {
        phase_type: phase.phase_type,
        phase_status: phase.phase_status,
        status: context.status_code,
        message: context.message
      }
    end
  end
end

#failed?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/drunker/executor/builder.rb', line 62

def failed?
  ran? && status == FAILED
end

#ran?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/drunker/executor/builder.rb', line 54

def ran?
  !!build_id
end

#refreshObject



70
71
72
# File 'lib/drunker/executor/builder.rb', line 70

def refresh
  @result = nil
end

#retriable?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/drunker/executor/builder.rb', line 33

def retriable?
  retry_count < RETRY_LIMIT
end

#retryObject



37
38
39
40
41
# File 'lib/drunker/executor/builder.rb', line 37

def retry
  logger.info("Retrying build: #{build_id}")
  @retry_count += 1
  run
end

#runObject



25
26
27
28
29
30
31
# File 'lib/drunker/executor/builder.rb', line 25

def run
  @build_id = client.start_build(project_name: project_name, buildspec_override: buildspec).build.id
  refresh
  logger.info("Started build: #{build_id}")
  logger.debug("buildspec: #{buildspec}")
  build_id
end

#running?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/drunker/executor/builder.rb', line 58

def running?
  ran? && status == IN_PROGRESS
end

#success?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/drunker/executor/builder.rb', line 66

def success?
  ran? && status == SUCCEEDED
end