2015-09-11 19:20:28 +00:00
|
|
|
# Pushes all deb and rpm files from ./repos to PackageCloud.
|
|
|
|
|
|
|
|
packagecloud_user = ENV["PACKAGECLOUD_USER"] || "github"
|
|
|
|
packagecloud_token = ENV["PACKAGECLOUD_TOKEN"] || begin
|
|
|
|
puts "PACKAGECLOUD_TOKEN env required"
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
2015-10-27 15:30:41 +00:00
|
|
|
require "json"
|
|
|
|
|
2016-06-06 22:35:49 +00:00
|
|
|
packagecloud_ruby_minimum_version = "1.0.4"
|
2015-09-11 19:20:28 +00:00
|
|
|
begin
|
2016-06-06 22:35:49 +00:00
|
|
|
gem "packagecloud-ruby", ">=#{packagecloud_ruby_minimum_version}"
|
2015-09-11 19:20:28 +00:00
|
|
|
require "packagecloud"
|
2016-06-06 22:35:49 +00:00
|
|
|
puts "Using packagecloud-ruby:#{Gem.loaded_specs["packagecloud-ruby"].version}"
|
2015-09-11 19:20:28 +00:00
|
|
|
rescue LoadError
|
2016-06-06 22:35:49 +00:00
|
|
|
puts "Requires packagecloud-ruby >=#{packagecloud_ruby_minimum_version}"
|
2015-09-11 19:20:28 +00:00
|
|
|
puts %(gem install packagecloud-ruby)
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
credentials = Packagecloud::Credentials.new(packagecloud_user, packagecloud_token)
|
|
|
|
$client = Packagecloud::Client.new(credentials)
|
|
|
|
|
2015-11-18 21:24:04 +00:00
|
|
|
# matches package directories built by docker to one or more packagecloud distros
|
|
|
|
# https://packagecloud.io/docs#os_distro_version
|
2015-09-11 19:20:28 +00:00
|
|
|
$distro_name_map = {
|
2016-02-10 18:16:24 +00:00
|
|
|
"centos/5" => %w(
|
|
|
|
el/5
|
|
|
|
),
|
|
|
|
"centos/6" => %w(
|
|
|
|
el/6
|
|
|
|
),
|
|
|
|
"centos/7" => %w(
|
|
|
|
el/7
|
|
|
|
fedora/22
|
|
|
|
fedora/23
|
2016-11-18 18:22:16 +00:00
|
|
|
fedora/24
|
2016-12-22 22:48:12 +00:00
|
|
|
fedora/25
|
2016-02-10 18:16:24 +00:00
|
|
|
),
|
|
|
|
"debian/7" => %w(
|
|
|
|
debian/wheezy
|
|
|
|
ubuntu/precise
|
|
|
|
),
|
|
|
|
"debian/8" => %w(
|
|
|
|
debian/jessie
|
2016-07-20 16:39:34 +00:00
|
|
|
linuxmint/sarah
|
2016-03-15 05:58:49 +00:00
|
|
|
linuxmint/rebecca
|
|
|
|
linuxmint/rafaela
|
|
|
|
linuxmint/rosa
|
2016-02-10 18:16:24 +00:00
|
|
|
ubuntu/trusty
|
|
|
|
ubuntu/vivid
|
|
|
|
ubuntu/wily
|
2016-04-22 09:23:49 +00:00
|
|
|
ubuntu/xenial
|
2016-02-10 18:16:24 +00:00
|
|
|
),
|
2015-09-11 19:20:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# caches distro id lookups
|
|
|
|
$distro_id_map = {}
|
|
|
|
|
2015-11-18 21:24:04 +00:00
|
|
|
def distro_names_for(filename)
|
|
|
|
$distro_name_map.each do |pattern, distros|
|
|
|
|
return distros if filename.include?(pattern)
|
2015-09-11 19:20:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
raise "no distro for #{filename.inspect}"
|
|
|
|
end
|
|
|
|
|
2016-02-05 22:34:06 +00:00
|
|
|
package_files = Dir.glob("repos/**/*.rpm") + Dir.glob("repos/**/*.deb")
|
|
|
|
package_files.each do |full_path|
|
|
|
|
next if full_path =~ /repo-release/
|
|
|
|
pkg = Packagecloud::Package.new(:file => full_path)
|
|
|
|
distro_names = distro_names_for(full_path)
|
2015-11-18 21:24:04 +00:00
|
|
|
distro_names.map do |distro_name|
|
|
|
|
distro_id = $distro_id_map[distro_name] ||= $client.find_distribution_id(distro_name)
|
|
|
|
if !distro_id
|
|
|
|
raise "no distro id for #{distro_name.inspect}"
|
|
|
|
end
|
2015-09-11 19:20:28 +00:00
|
|
|
|
2016-02-05 22:34:06 +00:00
|
|
|
puts "pushing #{full_path} to #{$distro_id_map.key(distro_id).inspect}"
|
2016-03-22 07:13:36 +00:00
|
|
|
result = $client.put_package("git-lfs", pkg, distro_id)
|
|
|
|
result.succeeded || begin
|
|
|
|
raise "packagecloud put_package failed, error: #{result.response}"
|
|
|
|
end
|
2015-11-18 21:24:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
package_files.each do |full_path|
|
|
|
|
next if full_path.include?("SRPM") || full_path.include?("i386") || full_path.include?("i686")
|
|
|
|
next unless full_path =~ /\/git-lfs[-|_]\d/
|
|
|
|
os, distro = case full_path
|
|
|
|
when /debian\/7/ then ["Debian 7", "debian/wheezy"]
|
|
|
|
when /debian\/8/ then ["Debian 8", "debian/jessie"]
|
|
|
|
when /centos\/5/ then ["RPM RHEL 5/CentOS 5", "el/5"]
|
|
|
|
when /centos\/6/ then ["RPM RHEL 6/CentOS 6", "el/6"]
|
|
|
|
when /centos\/7/ then ["RPM RHEL 7/CentOS 7", "el/7"]
|
|
|
|
end
|
|
|
|
|
|
|
|
next unless os
|
|
|
|
|
2016-03-22 09:53:48 +00:00
|
|
|
puts "[#{os}](https://packagecloud.io/#{packagecloud_user}/git-lfs/packages/#{distro}/#{File.basename(full_path)}/download)"
|
2015-09-11 19:20:28 +00:00
|
|
|
end
|