|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -ex |
| 4 | + |
| 5 | +TARGET="$1" |
| 6 | + |
| 7 | +RUST_REPO="https://github.com/rust-lang/rust" |
| 8 | +S3_BASE_URL="https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rustc-builds" |
| 9 | + |
| 10 | +# See http://unix.stackexchange.com/questions/82598 |
| 11 | +# Duplicated from rust-lang/rust/src/ci/shared.sh |
| 12 | +function retry { |
| 13 | + echo "Attempting with retry:" "$@" |
| 14 | + local n=1 |
| 15 | + local max=5 |
| 16 | + while true; do |
| 17 | + "$@" && break || { |
| 18 | + if [[ $n -lt $max ]]; then |
| 19 | + sleep $n # don't retry immediately |
| 20 | + ((n++)) |
| 21 | + echo "Command failed. Attempt $n/$max:" |
| 22 | + else |
| 23 | + echo "The command has failed after $n attempts." |
| 24 | + return 1 |
| 25 | + fi |
| 26 | + } |
| 27 | + done |
| 28 | +} |
| 29 | + |
| 30 | +# Use images from rustc master |
| 31 | +case "$TARGET" in |
| 32 | + mips-unknown-linux-gnu) image=dist-mips-linux ;; |
| 33 | + mips64-unknown-linux-gnuabi64) image=dist-mips64-linux ;; |
| 34 | + mips64el-unknown-linux-gnuabi64) image=dist-mips64el-linux ;; |
| 35 | + mipsel-unknown-linux-gnu) image=dist-mipsel-linux ;; |
| 36 | + powerpc-unknown-linux-gnu) image=dist-powerpc-linux ;; |
| 37 | + powerpc64-unknown-linux-gnu) image=dist-powerpc64-linux ;; |
| 38 | + powerpc64le-unknown-linux-gnu) image=dist-powerpc64le-linux ;; |
| 39 | + s390x-unknown-linux-gnu) image=dist-s390x-linux ;; |
| 40 | + *) exit ;; |
| 41 | +esac |
| 42 | + |
| 43 | +master=$(git ls-remote "$RUST_REPO" refs/heads/master | cut -f1) |
| 44 | +image_url="$S3_BASE_URL/$master/image-$image.txt" |
| 45 | +info="/tmp/image-$image.txt" |
| 46 | + |
| 47 | +rm -f "$info" |
| 48 | +curl -o "$info" "$image_url" |
| 49 | +digest=$(grep -m1 ^sha "$info") |
| 50 | + |
| 51 | +if ! docker tag "$digest" "rust-$TARGET"; then |
| 52 | + url=$(grep -m1 ^https "$info") |
| 53 | + cache=/tmp/rustci_docker_cache |
| 54 | + echo "Attempting to download $url" |
| 55 | + rm -f "$cache" |
| 56 | + set +e |
| 57 | + retry curl -y 30 -Y 10 --connect-timeout 30 -f -L -C - -o "$cache" "$url" |
| 58 | + docker load -i "$cache" |
| 59 | + set -e |
| 60 | + docker tag "$digest" "rust-$TARGET" |
| 61 | +fi |
0 commit comments