Class: Jets::CLI::Ci::Base

Inherits:
Base
  • Object
show all
Defined in:
lib/jets/cli/ci/base.rb

Direct Known Subclasses

Build, Delete, Deploy, Info, Logs, Start, Status, Stop, Stop

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#initialize, #paginate, #paging_params, rescue_api_error

Methods included from Util::Logging

#log

Methods included from AwsServices

#apigateway, #aws_options, #cfn, #codebuild, #dynamodb, #lambda_client, #logs, #s3, #s3_resource, #sns, #sqs, #ssm, #sts, #wafv2

Methods included from AwsServices::StackStatus

#output_value, #stack_exists?

Methods included from AwsServices::GlobalMemoist

included, #reset_cache!

Methods included from Api

#api, #api_key

Constructor Details

This class inherits a constructor from Jets::CLI::Base

Instance Method Details

#build_idObject



28
29
30
31
# File 'lib/jets/cli/ci/base.rb', line 28

def build_id
  return @options[:build_id] if @options[:build_id]
  find_build
end

#check_build_id!Object



42
43
44
45
46
# File 'lib/jets/cli/ci/base.rb', line 42

def check_build_id!
  return if build_id
  puts "WARN: No builds found for #{project_name.color(:green)} project"
  exit
end

#find_buildObject



34
35
36
37
38
39
40
# File 'lib/jets/cli/ci/base.rb', line 34

def find_build
  resp = codebuild.list_builds_for_project(project_name: project_name)
  resp.ids.first # most recent build_id
rescue Aws::CodeBuild::Errors::ResourceNotFoundException => e
  logger.error "ERROR: #{e.class} #{e.message}".color(:red)
  exit 1
end

#run_with_exception_handlingObject



8
9
10
11
12
13
14
15
# File 'lib/jets/cli/ci/base.rb', line 8

def run_with_exception_handling
  yield
rescue Aws::CodeBuild::Errors::ResourceNotFoundException => e
  puts "ERROR: #{e.class}: #{e.message}".color(:red)
  puts "CodeBuild project #{project_name} not found."
rescue Aws::CodeBuild::Errors::InvalidInputException => e
  puts "ERROR: #{e.class}: #{e.message}".color(:red)
end

#show_console_log_url(build_id) ⇒ Object



48
49
50
51
52
# File 'lib/jets/cli/ci/base.rb', line 48

def show_console_log_url(build_id)
  log.info "Console Log Url:"
  build_id = build_id.split(":").last
  log.info "https://#{Jets.aws.region}.console.aws.amazon.com/codesuite/codebuild/projects/#{project_name}/build/#{project_name}%3A#{build_id}/log"
end

#stack_nameObject Also known as: project_name



3
4
5
# File 'lib/jets/cli/ci/base.rb', line 3

def stack_name
  "#{Jets.project.namespace}-ci"
end

#stop_buildObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/jets/cli/ci/base.rb', line 17

def stop_build
  build = codebuild.batch_get_builds(ids: [build_id]).builds.first
  if build.build_status == "IN_PROGRESS"
    codebuild.stop_build(id: build_id)
    true
  else
    log.info "Not in progress. Status is #{build.build_status}. Cannot stop: #{build_id}"
    false
  end
end