Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub Packages cleanup #11034

Merged
merged 1 commit into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Library/Homebrew/download_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ class CurlGitHubPackagesDownloadStrategy < CurlDownloadStrategy

def initialize(url, name, version, **meta)
meta ||= {}
meta[:header] = ["Authorization: Bearer", "Accept: application/vnd.oci.image.index.v1+json"]
meta[:headers] ||= []
meta[:headers] << ["Authorization: Bearer"]
super(url, name, version, meta)
end

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/formula_auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def audit_glibc
return unless @core_tap

version = formula.version.to_s
return if version == "2.23"
return if version == OS::GLIBC_CI_VERSION

problem "The glibc version must be #{version}, as this is the version used by our CI on Linux. " \
"Glibc is for users who have a system Glibc with a lower version, " \
Expand Down
25 changes: 18 additions & 7 deletions Library/Homebrew/github_packages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def upload_bottles(bottles_hash, dry_run:)
HOMEBREW_PREFIX/"bin/skopeo",
].compact.first
unless skopeo.exist?
odie "no `skoepeo` and HOMEBREW_FORCE_HOMEBREW_ON_LINUX is set!" if Homebrew::EnvConfig.force_homebrew_on_linux?
odie "no `skopeo` and HOMEBREW_FORCE_HOMEBREW_ON_LINUX is set!" if Homebrew::EnvConfig.force_homebrew_on_linux?

ohai "Installing `skopeo` for upload..."
safe_system HOMEBREW_BREW_FILE, "install", "--formula", "skopeo"
Expand Down Expand Up @@ -206,7 +206,8 @@ def upload_bottle(user, token, skopeo, formula_full_name, bottle_hash, dry_run:)
"org.opencontainers.image.url" => bottle_hash["formula"]["homepage"],
"org.opencontainers.image.vendor" => org,
"org.opencontainers.image.version" => version,
}.compact
}
delete_blank_hash_values(formula_annotations_hash)

manifests = bottle_hash["bottle"]["tags"].map do |bottle_tag, tag_hash|
local_file = tag_hash["local_filename"]
Expand Down Expand Up @@ -239,15 +240,17 @@ def upload_bottle(user, token, skopeo, formula_full_name, bottle_hash, dry_run:)
os_version ||= "macOS #{MacOS::Version.from_symbol(bottle_tag)}"
when "linux"
os_version = (os_version || "Ubuntu 16.04.7").delete_suffix " LTS"
glibc_version = (tab["built_on"]["glibc_version"] if tab["built_on"].present?) || "2.23"
cpu_variant = tab["oldest_cpu_family"] || "core2"
glibc_version = (tab["built_on"]["glibc_version"] if tab["built_on"].present?) || OS::GLIBC_CI_VERSION
cpu_variant = tab["oldest_cpu_family"] || Hardware::CPU::INTEL_64BIT_OLDEST_CPU.to_s
end

platform_hash = {
architecture: architecture,
os: os,
"os.version" => os_version,
}.compact
}
delete_blank_hash_values(platform_hash)

tar_sha256 = Digest::SHA256.hexdigest(
Utils.safe_popen_read("gunzip", "--stdout", "--decompress", local_file),
)
Expand All @@ -265,15 +268,17 @@ def upload_bottle(user, token, skopeo, formula_full_name, bottle_hash, dry_run:)
"sh.brew.bottle.digest" => tar_gz_sha256,
"sh.brew.bottle.glibc.version" => glibc_version,
"sh.brew.tab" => tab.to_json,
}.compact
}
delete_blank_hash_values(descriptor_annotations_hash)

annotations_hash = formula_annotations_hash.merge(descriptor_annotations_hash).merge(
{
"org.opencontainers.image.created" => created_date,
"org.opencontainers.image.documentation" => documentation,
"org.opencontainers.image.title" => "#{formula_full_name} #{tag}",
},
).compact.sort.to_h
).sort.to_h
delete_blank_hash_values(annotations_hash)

image_manifest = {
schemaVersion: 2,
Expand Down Expand Up @@ -381,4 +386,10 @@ def write_hash(directory, hash, filename = nil)

[sha256, json.size]
end

def delete_blank_hash_values(hash)
hash.each do |key, value|
hash.delete(key) if value.blank?
end
end
end
4 changes: 3 additions & 1 deletion Library/Homebrew/hardware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class CPU
*ARM_64BIT_ARCHS,
].freeze

INTEL_64BIT_OLDEST_CPU = :core2

class << self
extend T::Sig

Expand Down Expand Up @@ -198,7 +200,7 @@ def cores_as_words
def oldest_cpu(_version = nil)
if Hardware::CPU.intel?
if Hardware::CPU.is_64_bit?
:core2
Hardware::CPU::INTEL_64BIT_OLDEST_CPU
else
:core
end
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/os.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def self.kernel_version

::OS_VERSION = ENV["HOMEBREW_OS_VERSION"]

GLIBC_CI_VERSION = "2.23"

if OS.mac?
require "os/mac"
# Don't tell people to report issues on unsupported configurations.
Expand Down
7 changes: 5 additions & 2 deletions Library/Homebrew/software_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ def initialize(formula, spec)

filename = Filename.create(formula, tag, spec.rebuild).bintray

# TODO: this will need adjusted when if we use GitHub Packages by default
path, resolved_basename = if spec.root_url.match?(GitHubPackages::URL_REGEX)
["#{@name}/blobs/sha256:#{checksum}", filename]
else
Expand Down Expand Up @@ -400,8 +401,10 @@ def github_packages_manifest_resource
version_rebuild = GitHubPackages.version_rebuild(@resource.version, rebuild)
resource.version(version_rebuild)

resource.url("#{@spec.root_url}/#{name}/manifests/#{version_rebuild}",
using: CurlGitHubPackagesDownloadStrategy)
resource.url("#{@spec.root_url}/#{name}/manifests/#{version_rebuild}", {
using: CurlGitHubPackagesDownloadStrategy,
headers: ["Accept: application/vnd.oci.image.index.v1+json"],
})
resource.downloader.resolved_basename = "#{name}-#{version_rebuild}.bottle_manifest.json"
resource
end
Expand Down