software_spec: Add HOMEBREW_BOTTLE_DEFAULT_DOMAIN as a fallback option

Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
XuehaiPan 2021-02-26 11:23:33 +00:00 committed by Mike McQuaid
parent cb72872c83
commit d2533ff2a6
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
4 changed files with 21 additions and 4 deletions

View File

@ -46,8 +46,12 @@ module Homebrew
}, },
HOMEBREW_BOTTLE_DOMAIN: { HOMEBREW_BOTTLE_DOMAIN: {
description: "Use this URL as the download mirror for bottles. " \ description: "Use this URL as the download mirror for bottles. " \
"If bottles at that URL are temporarily unavailable, " \
"the default bottle domain will be used as a fallback mirror. " \
"For example, `HOMEBREW_BOTTLE_DOMAIN=http://localhost:8080` will cause all bottles to " \ "For example, `HOMEBREW_BOTTLE_DOMAIN=http://localhost:8080` will cause all bottles to " \
"download from the prefix `http://localhost:8080/`.", "download from the prefix `http://localhost:8080/`. " \
"If bottles are not available at `HOMEBREW_BOTTLE_DOMAIN` " \
"they will be downloaded from the default bottle domain.",
default_text: "macOS: `https://homebrew.bintray.com/`, " \ default_text: "macOS: `https://homebrew.bintray.com/`, " \
"Linux: `https://linuxbrew.bintray.com/`.", "Linux: `https://linuxbrew.bintray.com/`.",
default: HOMEBREW_BOTTLE_DEFAULT_DOMAIN, default: HOMEBREW_BOTTLE_DEFAULT_DOMAIN,

View File

@ -2,6 +2,7 @@
# frozen_string_literal: true # frozen_string_literal: true
require "resource" require "resource"
require "download_strategy"
require "checksum" require "checksum"
require "version" require "version"
require "options" require "options"
@ -292,7 +293,7 @@ class Bottle
attr_reader :name, :resource, :prefix, :cellar, :rebuild attr_reader :name, :resource, :prefix, :cellar, :rebuild
def_delegators :resource, :url, :fetch, :verify_download_integrity def_delegators :resource, :url, :verify_download_integrity
def_delegators :resource, :cached_download, :clear_cache def_delegators :resource, :cached_download, :clear_cache
def initialize(formula, spec) def initialize(formula, spec)
@ -314,6 +315,18 @@ class Bottle
@rebuild = spec.rebuild @rebuild = spec.rebuild
end end
def fetch(verify_download_integrity: true)
# add the default bottle domain as a fallback mirror
if @resource.download_strategy == CurlDownloadStrategy &&
@resource.url.start_with?(Homebrew::EnvConfig.bottle_domain)
fallback_url = @resource.url
.sub(/^#{Regexp.escape(Homebrew::EnvConfig.bottle_domain)}/,
HOMEBREW_BOTTLE_DEFAULT_DOMAIN)
@resource.mirror(fallback_url) if [@resource.url, *@resource.mirrors].exclude?(fallback_url)
end
@resource.fetch(verify_download_integrity: verify_download_integrity)
end
def compatible_locations? def compatible_locations?
@spec.compatible_locations? @spec.compatible_locations?
end end

View File

@ -1729,7 +1729,7 @@ example, run `export HOMEBREW_NO_INSECURE_REDIRECT=1` rather than just
<br>If set, use Bootsnap to speed up repeated `brew` calls. A no-op when using Homebrew's vendored, relocatable Ruby on macOS (as it doesn't work). <br>If set, use Bootsnap to speed up repeated `brew` calls. A no-op when using Homebrew's vendored, relocatable Ruby on macOS (as it doesn't work).
- `HOMEBREW_BOTTLE_DOMAIN` - `HOMEBREW_BOTTLE_DOMAIN`
<br>Use this URL as the download mirror for bottles. For example, `HOMEBREW_BOTTLE_DOMAIN=http://localhost:8080` will cause all bottles to download from the prefix `http://localhost:8080/`. <br>Use this URL as the download mirror for bottles. If bottles at that URL are temporarily unavailable, the default bottle domain will be used as a fallback mirror. For example, `HOMEBREW_BOTTLE_DOMAIN=http://localhost:8080` will cause all bottles to download from the prefix `http://localhost:8080/`. If bottles are not available at `HOMEBREW_BOTTLE_DOMAIN` they will be downloaded from the default bottle domain.
*Default:* macOS: `https://homebrew.bintray.com/`, Linux: `https://linuxbrew.bintray.com/`. *Default:* macOS: `https://homebrew.bintray.com/`, Linux: `https://linuxbrew.bintray.com/`.

View File

@ -2415,7 +2415,7 @@ If set, use Bootsnap to speed up repeated \fBbrew\fR calls\. A no\-op when using
\fBHOMEBREW_BOTTLE_DOMAIN\fR \fBHOMEBREW_BOTTLE_DOMAIN\fR
. .
.br .br
Use this URL as the download mirror for bottles\. For example, \fBHOMEBREW_BOTTLE_DOMAIN=http://localhost:8080\fR will cause all bottles to download from the prefix \fBhttp://localhost:8080/\fR\. Use this URL as the download mirror for bottles\. If bottles at that URL are temporarily unavailable, the default bottle domain will be used as a fallback mirror\. For example, \fBHOMEBREW_BOTTLE_DOMAIN=http://localhost:8080\fR will cause all bottles to download from the prefix \fBhttp://localhost:8080/\fR\. If bottles are not available at \fBHOMEBREW_BOTTLE_DOMAIN\fR they will be downloaded from the default bottle domain\.
. .
.IP .IP
\fIDefault:\fR macOS: \fBhttps://homebrew\.bintray\.com/\fR, Linux: \fBhttps://linuxbrew\.bintray\.com/\fR\. \fIDefault:\fR macOS: \fBhttps://homebrew\.bintray\.com/\fR, Linux: \fBhttps://linuxbrew\.bintray\.com/\fR\.