Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,3 @@ jobs:
run: git clone --depth 1 --branch v1.10.0 https://github.com/bats-core/bats-core.git bats
- name: Run tests
run: PATH="./bats/bin:$PATH" script/test
- name: Verify download URL checksums
if: github.event_name == 'pull_request'
run: ./script/mirror verify "$COMMIT_RANGE"
env:
COMMIT_RANGE: ${{ github.event.pull_request.base.sha }}..
30 changes: 0 additions & 30 deletions .github/workflows/mirror.yml

This file was deleted.

12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,15 @@ See the next section for more information on how to author checksums.

#### Package Mirrors

To speed up downloads, ruby-build fetches package files from a mirror hosted on
Amazon CloudFront. To benefit from this, the packages must specify their checksum:
You may specify a custom mirror by setting `RUBY_BUILD_MIRROR_URL`. When set,
ruby-build will first attempt to download packages from the mirror before falling
back to the original URL.

```sh
# example:
export RUBY_BUILD_MIRROR_URL="https://my-mirror.example.com"
install_package "ruby-2.6.5" "https://ruby-lang.org/ruby-2.6.5.tgz#<SHA2>"
# Will first try: https://my-mirror.example.com/<SHA2>
```

ruby-build will first try to fetch this package from `$RUBY_BUILD_MIRROR_URL/<SHA2>`
Expand All @@ -164,15 +167,10 @@ will fall back to downloading the package from the original location if:
- no tool is available to calculate the checksum; or
- `RUBY_BUILD_SKIP_MIRROR` is enabled.

You may specify a custom mirror by setting `RUBY_BUILD_MIRROR_URL`.

If a mirror site doesn't conform to the above URL format, you can specify the
complete URL by setting `RUBY_BUILD_MIRROR_PACKAGE_URL`. It behaves the same as
`RUBY_BUILD_MIRROR_URL` except being a complete URL.

The default ruby-build download mirror is sponsored by
[Basecamp](https://basecamp.com/).

#### Keeping the build directory after installation

Both `ruby-build` and `rbenv install` accept the `-k` or `--keep` flag, which
Expand Down
10 changes: 2 additions & 8 deletions bin/ruby-build
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,7 @@ fetch_tarball() {
package_url="${package_url%%#*}"

if [ -n "$RUBY_BUILD_MIRROR_URL" ]; then
if [[ -z "$RUBY_BUILD_DEFAULT_MIRROR" || $package_url != */cache.ruby-lang.org/* ]]; then
mirror_url="${RUBY_BUILD_MIRROR_URL}/$checksum"
fi
mirror_url="${RUBY_BUILD_MIRROR_URL}/$checksum"
elif [ -n "$RUBY_BUILD_MIRROR_PACKAGE_URL" ]; then
mirror_url="$RUBY_BUILD_MIRROR_PACKAGE_URL"
fi
Expand Down Expand Up @@ -1579,12 +1577,8 @@ else
unset RUBY_BUILD_CACHE_PATH
fi

if [ -z "$RUBY_BUILD_MIRROR_URL" ] && [ -z "$RUBY_BUILD_MIRROR_PACKAGE_URL" ]; then
RUBY_BUILD_MIRROR_URL="https://dqw8nmjcqpjn7.cloudfront.net"
RUBY_BUILD_DEFAULT_MIRROR=1
else
if [ -n "$RUBY_BUILD_MIRROR_URL" ]; then
RUBY_BUILD_MIRROR_URL="${RUBY_BUILD_MIRROR_URL%/}"
RUBY_BUILD_DEFAULT_MIRROR=
fi

if [ -n "$RUBY_BUILD_SKIP_MIRROR" ] || ! has_checksum_support compute_sha2; then
Expand Down
128 changes: 0 additions & 128 deletions script/mirror

This file was deleted.

6 changes: 3 additions & 3 deletions test/cache.bats
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ export RUBY_BUILD_CACHE_PATH="$TMP/cache"
}


@test "cached package with invalid checksum falls back to mirror and updates cache" {
@test "cached package with invalid checksum falls back to original URL and updates cache" {
export RUBY_BUILD_SKIP_MIRROR=
export RUBY_BUILD_MIRROR_URL=
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"

stub shasum true "echo invalid" "echo $checksum"
stub curl "-*I* : true" \
"-q -fL -o * https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$4"
stub curl "-q -fL -o * http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$4"

mkdir -p "$RUBY_BUILD_CACHE_PATH"
touch "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz"
Expand Down
23 changes: 2 additions & 21 deletions test/mirror.bats
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,12 @@ export RUBY_BUILD_MIRROR_URL=http://mirror.example.com
}


@test "default mirror URL" {
@test "no default mirror URL" {
export RUBY_BUILD_MIRROR_URL=
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"

stub shasum true "echo $checksum"
stub curl "-*I* : true" \
"-q -fL -o * https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$4" \
stub curl "-q -fL -o * http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$4"

install_fixture definitions/with-checksum

Expand All @@ -107,24 +106,6 @@ export RUBY_BUILD_MIRROR_URL=http://mirror.example.com
}


@test "package URL with ruby-lang CDN with default mirror URL will bypasses mirror" {
export RUBY_BUILD_MIRROR_URL=
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"

stub shasum true "echo $checksum"
stub curl "-q -fL -o * https://cache.ruby-lang.org/* : cp $FIXTURE_ROOT/\${5##*/} \$4"

run_inline_definition <<DEF
install_package "package-1.0.0" "https://cache.ruby-lang.org/packages/package-1.0.0.tar.gz#ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" copy
DEF

assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]

unstub curl
unstub shasum
}


@test "package is fetched from complete mirror URL" {
export RUBY_BUILD_MIRROR_URL=
Expand Down