Class: Jets::Remote::Download

Inherits:
Base
  • Object
show all
Defined in:
lib/jets/remote/download.rb

Instance Method Summary collapse

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!

Constructor Details

#initialize(command) ⇒ Download

Returns a new instance of Download.



5
6
7
# File 'lib/jets/remote/download.rb', line 5

def initialize(command)
  @command = command
end

Instance Method Details

#clean_all_templatesObject



40
41
42
# File 'lib/jets/remote/download.rb', line 40

def clean_all_templates
  FileUtils.rm_rf("#{Jets.build_root}/templates")
end

#download_all_templatesObject



44
45
46
47
48
49
50
# File 'lib/jets/remote/download.rb', line 44

def download_all_templates
  s3.list_objects(bucket: s3_bucket, prefix: "jets/sigs/#{sig}/templates/").each do |resp|
    resp.contents.each do |object|
      download_template(object.key)
    end
  end
end

#download_builtObject



9
10
11
12
13
14
15
16
17
# File 'lib/jets/remote/download.rb', line 9

def download_built
  # build deploy ci:build ci:deploy waf:build waf:deploy
  subcommand = @command.split(":").last
  case subcommand
  when "build", "deploy", "dockerfile"
    download_templates
    download_dockerfile
  end
end

#download_dockerfileObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jets/remote/download.rb', line 19

def download_dockerfile
  s3_key = "jets/sigs/#{sig}/docker/Dockerfile"
  object = s3_resource.bucket(s3_bucket).object(s3_key)
  # Can not exists for: jets build --templates
  if object.exists?
    dest = "#{Jets.build_root}/docker/Dockerfile"
    FileUtils.mkdir_p(File.dirname(dest))
    object.download_file(dest)
    if @command.split(":").last == "dockerfile"
      log.info "Dockerfile at: #{dest}"
    else
      log.debug "Download: #{dest}"
    end
  end
end

#download_template(s3_key) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/jets/remote/download.rb', line 52

def download_template(s3_key)
  object = s3_resource.bucket(s3_bucket).object(s3_key)
  path = object.key.sub("jets/sigs/#{sig}/templates/", "")
  dest = "#{Jets.build_root}/templates/#{path}"
  log.debug "Download: #{dest}"
  FileUtils.mkdir_p(File.dirname(dest))
  object.download_file(dest)
end

#download_templatesObject



35
36
37
38
# File 'lib/jets/remote/download.rb', line 35

def download_templates
  clean_all_templates
  download_all_templates
end

#sigObject



61
62
63
# File 'lib/jets/remote/download.rb', line 61

def sig
  Jets::Remote::Runner.sig
end