Skip to content

Commit

Permalink
Add HOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK
Browse files Browse the repository at this point in the history
This fits the use-case I've heard multiple times where people want to
rely exclusively on their artifact provider.

Co-authored-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
  • Loading branch information
MikeMcQuaid and carlocab committed May 14, 2024
1 parent 960b1eb commit a37864d
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Library/Homebrew/cmd/vendor-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ set_ruby_variables() {
if [[ -n "${HOMEBREW_ARTIFACT_DOMAIN}" ]]
then
ruby_URLs+=("${HOMEBREW_ARTIFACT_DOMAIN}/v2/homebrew/portable-ruby/portable-ruby/blobs/sha256:${ruby_SHA}")
if [[ -n "${HOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK}" ]]
then
ruby_URL="${ruby_URLs[0]}"
return
fi
fi
if [[ -n "${HOMEBREW_BOTTLE_DOMAIN}" ]]
then
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/download_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ def fetch(timeout: nil)

if (domain = Homebrew::EnvConfig.artifact_domain)
url = url.sub(%r{^https?://#{GitHubPackages::URL_DOMAIN}/}o, "#{domain.chomp("/")}/")
urls = [] if Homebrew::EnvConfig.artifact_domain_no_fallback?
end

ohai "Downloading #{url}"
Expand Down
6 changes: 6 additions & 0 deletions Library/Homebrew/env_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ module EnvConfig
"to instead be downloaded from " \
"`http://localhost:8080/v2/homebrew/core/gettext/manifests/0.21`",
},
HOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK: {
description: "If `HOMEBREW_ARTIFACT_DOMAIN` and `HOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK` are both set, " \
"if the request to `HOMEBREW_ARTIFACT_DOMAIN` fails then it Homebrew will error rather than " \
"trying any other/default URLs.",
boolean: true,
},
HOMEBREW_AUTO_UPDATE_SECS: {
description: "Run `brew update` once every `HOMEBREW_AUTO_UPDATE_SECS` seconds before some commands, " \
"e.g. `brew install`, `brew upgrade` and `brew tap`. Alternatively, " \
Expand Down
6 changes: 5 additions & 1 deletion Library/Homebrew/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,12 @@ def determine_url_mirrors
# glibc-bootstrap
if url.start_with?("https://github.com/Homebrew/glibc-bootstrap/releases/download")
if (artifact_domain = Homebrew::EnvConfig.artifact_domain.presence)
extra_urls << url.sub("https://github.com", artifact_domain)
artifact_url = url.sub("https://github.com", artifact_domain)
return [artifact_url] if Homebrew::EnvConfig.artifact_domain_no_fallback?

extra_urls << artifact_url

Check warning on line 243 in Library/Homebrew/resource.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/resource.rb#L243

Added line #L243 was not covered by tests
end

if Homebrew::EnvConfig.bottle_domain != HOMEBREW_BOTTLE_DEFAULT_DOMAIN
tag, filename = url.split("/").last(2)
extra_urls << "#{Homebrew::EnvConfig.bottle_domain}/glibc-bootstrap/#{tag}/#{filename}"
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions docs/Manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -3510,6 +3510,12 @@ command execution e.g. `$(cat file)`.
downloaded from
`http://localhost:8080/v2/homebrew/core/gettext/manifests/0.21`

`HOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK`

: If `HOMEBREW_ARTIFACT_DOMAIN` and `HOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK` are
both set, if the request to `HOMEBREW_ARTIFACT_DOMAIN` fails then it Homebrew
will error rather than trying any other/default URLs.

`HOMEBREW_AUTO_UPDATE_SECS`

: Run `brew update` once every `HOMEBREW_AUTO_UPDATE_SECS` seconds before some
Expand Down
3 changes: 3 additions & 0 deletions manpages/brew.1
Original file line number Diff line number Diff line change
Expand Up @@ -2244,6 +2244,9 @@ Linux only: Pass this value to a type name representing the compiler\[u2019]s \f
\fBHOMEBREW_ARTIFACT_DOMAIN\fP
Prefix all download URLs, including those for bottles, with this value\. For example, \fBHOMEBREW_ARTIFACT_DOMAIN=http://localhost:8080\fP will cause a formula with the URL \fBhttps://example\.com/foo\.tar\.gz\fP to instead download from \fBhttp://localhost:8080/https://example\.com/foo\.tar\.gz\fP\&\. Bottle URLs however, have their domain replaced with this prefix\. This results in e\.g\. \fBhttps://ghcr\.io/v2/homebrew/core/gettext/manifests/0\.21\fP to instead be downloaded from \fBhttp://localhost:8080/v2/homebrew/core/gettext/manifests/0\.21\fP
.TP
\fBHOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK\fP
If \fBHOMEBREW_ARTIFACT_DOMAIN\fP and \fBHOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK\fP are both set, if the request to \fBHOMEBREW_ARTIFACT_DOMAIN\fP fails then it Homebrew will error rather than trying any other/default URLs\.
.TP
\fBHOMEBREW_AUTO_UPDATE_SECS\fP
Run \fBbrew update\fP once every \fBHOMEBREW_AUTO_UPDATE_SECS\fP seconds before some commands, e\.g\. \fBbrew install\fP, \fBbrew upgrade\fP and \fBbrew tap\fP\&\. Alternatively, disable auto\-update entirely with \fBHOMEBREW_NO_AUTO_UPDATE\fP\&\.
.RS
Expand Down

0 comments on commit a37864d

Please sign in to comment.