Sha256: 40fcab163180cd0026e5ebdf53147f3c13be58b85511ad54c4127f323adf7d96

Contents?: true

Size: 1.72 KB

Versions: 4

Compression:

Stored size: 1.72 KB

Contents

module Jets::Remote
  class Download < Base
    delegate :s3_bucket, to: "Jets.project"

    def initialize(command)
      @command = command
    end

    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

    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

    def download_templates
      clean_all_templates
      download_all_templates
    end

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

    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

    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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jets-6.0.5 lib/jets/remote/download.rb
jets-6.0.4 lib/jets/remote/download.rb
jets-6.0.3 lib/jets/remote/download.rb
jets-6.0.2 lib/jets/remote/download.rb