class Drunker::Executor::Builder
Constants
- FAILED
- IN_PROGRESS
- PHASE_ACCESS_DENIED
- RETRY_LIMIT
- STOPPED
- SUCCEEDED
- TIMED_OUT
Attributes
artifact[R]
build_id[R]
client[R]
config[R]
logger[R]
project_name[R]
retry_count[R]
targets[R]
Public Class Methods
new(project_name:, targets:, artifact:, config:, logger:)
click to toggle source
# 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
Public Instance Methods
access_denied?()
click to toggle source
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.
# 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
errors()
click to toggle source
# 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?()
click to toggle source
# File lib/drunker/executor/builder.rb, line 62 def failed? ran? && status == FAILED end
ran?()
click to toggle source
# File lib/drunker/executor/builder.rb, line 54 def ran? !!build_id end
refresh()
click to toggle source
# File lib/drunker/executor/builder.rb, line 70 def refresh @result = nil end
retriable?()
click to toggle source
# File lib/drunker/executor/builder.rb, line 33 def retriable? retry_count < RETRY_LIMIT end
retry()
click to toggle source
# File lib/drunker/executor/builder.rb, line 37 def retry logger.info("Retrying build: #{build_id}") @retry_count += 1 run end
run()
click to toggle source
# 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?()
click to toggle source
# File lib/drunker/executor/builder.rb, line 58 def running? ran? && status == IN_PROGRESS end
success?()
click to toggle source
# File lib/drunker/executor/builder.rb, line 66 def success? ran? && status == SUCCEEDED end
Private Instance Methods
access_denied_message_included?(message)
click to toggle source
# File lib/drunker/executor/builder.rb, line 123 def access_denied_message_included?(message) message.include?("is not authorized to perform") || message.include?("Not authorized to perform") end
buildspec()
click to toggle source
# File lib/drunker/executor/builder.rb, line 106 def buildspec commands = interpolate_commands stdout = artifact.stdout stderr = artifact.stderr exit_status = artifact.exit_status ERB.new(config.buildspec).result(binding) end
interpolate_commands()
click to toggle source
# File lib/drunker/executor/builder.rb, line 115 def interpolate_commands variables = %w(FILES) config.commands.map do |command| variables.include?(command) ? targets : command end.flatten end
result()
click to toggle source
# File lib/drunker/executor/builder.rb, line 98 def result @result ||= client.batch_get_builds(ids: [build_id]) end
status()
click to toggle source
# File lib/drunker/executor/builder.rb, line 102 def status result.builds[0].build_status end