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: fix OOM with large bottles #12949

Merged
merged 1 commit into from
Mar 4, 2022
Merged
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
15 changes: 11 additions & 4 deletions Library/Homebrew/github_packages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

require "utils/curl"
require "json"
require "zlib"

# GitHub Packages client.
#
Expand All @@ -21,6 +22,9 @@ class GitHubPackages

URL_REGEX = %r{(?:#{Regexp.escape(URL_PREFIX)}|#{Regexp.escape(DOCKER_PREFIX)})([\w-]+)/([\w-]+)}.freeze

GZIP_BUFFER_SIZE = 64 * 1024
private_constant :GZIP_BUFFER_SIZE

# Translate Homebrew tab.arch to OCI platform.architecture
TAB_ARCH_TO_PLATFORM_ARCHITECTURE = {
"arm64" => "arm64",
Expand Down Expand Up @@ -338,11 +342,14 @@ def upload_bottle(user, token, skopeo, formula_full_name, bottle_hash, keep_old:
"os.version" => os_version,
}.reject { |_, v| v.blank? }

tar_sha256 = Digest::SHA256.hexdigest(
Utils.safe_popen_read("gunzip", "--stdout", "--decompress", local_file),
)
tar_sha256 = Digest::SHA256.new
Zlib::GzipReader.open(local_file) do |gz|
while (data = gz.read(GZIP_BUFFER_SIZE))
tar_sha256 << data
end
end

config_json_sha256, config_json_size = write_image_config(platform_hash, tar_sha256, blobs)
config_json_sha256, config_json_size = write_image_config(platform_hash, tar_sha256.hexdigest, blobs)

formulae_dir = tag_hash["formulae_brew_sh_path"]
documentation = "https://formulae.brew.sh/#{formulae_dir}/#{formula_name}" if formula_core_tap
Expand Down