Class: DPL::Provider::Packagecloud
- Inherits:
-
DPL::Provider
- Object
- DPL::Provider
- DPL::Provider::Packagecloud
- Defined in:
- lib/dpl/provider/packagecloud.rb
Instance Method Summary collapse
- #check_auth ⇒ Object
- #dist_required?(filename) ⇒ Boolean
- #error_if_dist_required(filename) ⇒ Object
- #get_distro(query) ⇒ Object
- #get_source_files_for(orig_filename) ⇒ Object
- #is_source_package?(filename) ⇒ Boolean
- #is_supported_package?(filename) ⇒ Boolean
- #needs_key? ⇒ Boolean
- #push_app ⇒ Object
- #setup_auth ⇒ Object
Instance Method Details
#check_auth ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/dpl/provider/packagecloud.rb', line 6 def check_auth setup_auth = { connect_timeout: ([:connect_timeout] || 60).to_i, read_timeout: ([:read_timeout] || 60).to_i, write_timeout: ([:write_timeout] || 180.to_i) } connection = ::Packagecloud::Connection.new("https", "packagecloud.io", "443", ) begin log "Timeout configuration: #{.inspect}" @client = ::Packagecloud::Client.new(@creds, "travis-ci dpl #{DPL::VERSION}", connection) rescue ::Packagecloud::UnauthenticatedException error "Could not authenticate to https://packagecloud.io, please check credentials" end end |
#dist_required?(filename) ⇒ Boolean
53 54 55 56 57 58 59 |
# File 'lib/dpl/provider/packagecloud.rb', line 53 def dist_required?(filename) ext = File.extname(filename).gsub!('.','') if ext.nil? error "filename: #{filename} has no extension!" end ["rpm", "deb", "dsc", "whl", "egg", "egg-info", "gz", "zip", "tar", "bz2", "z", "tgz"].include?(ext.downcase) end |
#error_if_dist_required(filename) ⇒ Object
61 62 63 64 65 |
# File 'lib/dpl/provider/packagecloud.rb', line 61 def error_if_dist_required(filename) if dist_required?(filename) && @dist.nil? error "Distribution needed for rpm, deb, python, and dsc packages, example --dist='ubuntu/breezy'" end end |
#get_distro(query) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/dpl/provider/packagecloud.rb', line 35 def get_distro(query) distro = nil begin distro = @client.find_distribution_id(query) rescue ArgumentError => exception error "Error: #{exception.}" end if distro.nil? error "Could not find distribution named #{query}" end distro end |
#get_source_files_for(orig_filename) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/dpl/provider/packagecloud.rb', line 72 def get_source_files_for(orig_filename) source_files = {} glob_args = ["**/*"] package = ::Packagecloud::Package.new(:file => orig_filename) result = @client.package_contents(@repo, package, get_distro(@dist)) if result.succeeded package_contents_files = result.response["files"].map { |x| x["filename"] } Dir.chdir(.fetch(:local_dir, Dir.pwd)) do Dir.glob(*glob_args) do |filename| unless File.directory?(filename) basename = File.basename(filename) if package_contents_files.include?(basename) log "Found source fragment: #{basename} for #{orig_filename}" source_files = source_files.merge({basename => open(filename)}) end end end end else error "Error: #{result.response}" end source_files end |
#is_source_package?(filename) ⇒ Boolean
67 68 69 70 |
# File 'lib/dpl/provider/packagecloud.rb', line 67 def is_source_package?(filename) ext = File.extname(filename).gsub!('.','') ext == 'dsc' end |
#is_supported_package?(filename) ⇒ Boolean
48 49 50 51 |
# File 'lib/dpl/provider/packagecloud.rb', line 48 def is_supported_package?(filename) ext = File.extname(filename).gsub!('.','') ::Packagecloud::SUPPORTED_EXTENSIONS.include?(ext) end |
#needs_key? ⇒ Boolean
22 23 24 |
# File 'lib/dpl/provider/packagecloud.rb', line 22 def needs_key? false end |
#push_app ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/dpl/provider/packagecloud.rb', line 96 def push_app forced = .fetch(:force, nil) packages = [] glob_args = Array(.fetch(:package_glob, '**/*')) Dir.chdir(.fetch(:local_dir, Dir.pwd)) do Dir.glob(*glob_args) do |filename| unless File.directory?(filename) if is_supported_package?(filename) log "Detected supported package: #{filename}" error_if_dist_required(filename) if is_source_package?(filename) log "Processing source package: #{filename}" source_files = get_source_files_for(filename) packages << ::Packagecloud::Package.new(:file => filename, :source_files => source_files) else packages << ::Packagecloud::Package.new(:file => filename) end end end end end packages.each do |package| if forced log "Deleting package: #{package.filename}" distro, distro_release = @dist.split("/") result = @client.delete_package(@repo, distro, distro_release, package.filename) if result.succeeded log "Successfully deleted #{package.filename} on #{@dist}" else error "Error #{result.response}" end end log "Pushing package: #{package.filename}" if dist_required?(package.filename) result = @client.put_package(@repo, package, get_distro(@dist)) else result = @client.put_package(@repo, package) end if result.succeeded log "Successfully pushed #{package.filename} to #{@username}/#{@repo}" else error "Error #{result.response}" end end if packages.empty? error "Error: No supported packages found! Perhaps try skip_cleanup: true" end end |
#setup_auth ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/dpl/provider/packagecloud.rb', line 26 def setup_auth @username = option(:username) @token = option(:token) @repo = option(:repository) @dist = option(:dist) if [:dist] @creds = ::Packagecloud::Credentials.new(@username, @token) log "Logging into https://packagecloud.io with #{@username}:#{@token[-4..-1].rjust(20, '*')}" end |