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

Add fallback to default url #433

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

uberzzr
Copy link

@uberzzr uberzzr commented Mar 3, 2023

When BAZELISK_BASE_URL is set and bazelisk fails to download Bazel from that URL, it would either throw an HTTPError or exit with 22. It should instead fallback to the default releases.bazel.build url.
Fixes #431

@brentleyjones
Copy link

This could lead to non-deterministic versions of bazel being used, right?

@uberzzr
Copy link
Author

uberzzr commented Mar 3, 2023

This could lead to non-deterministic versions of bazel being used, right?

The fallback will use the same version as the version in failed downloading

@brentleyjones
Copy link

But the binary could be different? Unless I'm misreading and it does the same sha check at both locations, then disregard my comments.

@uberzzr
Copy link
Author

uberzzr commented Mar 3, 2023

But the binary could be different? Unless I'm misreading and it does the same sha check at both locations, then disregard my comments.

Yeah, I see what you mean. I have updated the code, do you think it is correct this time? I assume the bazel file downloaded from the default url will not be corrupted.

expected_hash, actual_hash
)
)
# Exiting with a special exit code not used by Bazel, so the calling process may retry based on that.
# https://docs.bazel.build/versions/0.21.0/guide.html#what-exit-code-will-i-get
sys.exit(22)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this exit code? It seems like we need it in case the caller retries on this exit code

@@ -324,16 +338,22 @@ def download_bazel_into_directory(version, is_commit, directory):
sha256_hash.update(byte_block)
actual_hash = sha256_hash.hexdigest()
if actual_hash != expected_hash:
os.remove(destination_path)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why keep the destination_path folder? Doesn't this mean the binary binary downloaded is corrupted?
We should probably remove the folder and create it again to download the fallback URL

download(fallback_url+".sha256", sha256_path)
os.remove(destination_path)
download(fallback_url,destination_path)
os.chmod(destination_path, 0o755)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the download fails for the exit URL, we should probably exit with code 22.

bazelisk.py Outdated
Comment on lines 324 to 326
download(fallback_url+".sha256", sha256_path)
os.remove(destination_path)
download(fallback_url,destination_path)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the fallback URL download fail? Should we have a try catch to raise an exception as well?

bazelisk.py Outdated Show resolved Hide resolved
bazelisk.py Outdated Show resolved Hide resolved
bazelisk.py Outdated Show resolved Hide resolved
@uberzzr
Copy link
Author

uberzzr commented Apr 5, 2023

@brentleyjones Can you please review this PR?

@brentleyjones
Copy link

@fweikert

bazelisk.py Outdated
@@ -306,6 +306,8 @@ def download_bazel_into_directory(version, is_commit, directory):

sha256_path = destination_path + ".sha256"
expected_hash = ""
matcher=re.compile(r"(\d*\.\d*(?:\.\d*)?)(rc\d+)?")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please format the changes? I think running black should work.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have run black to reformat. Can you please take a look? Thanks!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fweikert Hi, is there anything else I need to do for this PR? Appreciate a lot if could be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add fallback to default releases.bazel.build url
5 participants