Skip to content

Commit f2fec8e

Browse files
committed
Fold process of building Dockerfile
1 parent 88364b1 commit f2fec8e

File tree

4 files changed

+114
-26
lines changed

4 files changed

+114
-26
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ script:
6464
*) DOCKER=$TARGET ;;
6565
esac;
6666
if [ -n "$DOCKER" ]; then
67-
sh ci/build-run-docker.sh "$DOCKER" "$TARGET" "$SKIP_TESTS";
67+
bash ci/build-run-docker.sh "$DOCKER" "$TARGET" "$SKIP_TESTS";
6868
else
69-
PATH="$HOME/rust/bin:$PATH" sh ci/run.sh;
69+
PATH="$HOME/rust/bin:$PATH" bash ci/run.sh;
7070
fi
7171
7272
before_deploy:

ci/build-run-docker.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
#!/bin/bash
22

3-
set -ex
3+
# Start loading environment before `set -x`
4+
script_dir=$(cd "$(dirname "$0")" && pwd)
5+
. "$script_dir/shared.bash"
6+
7+
set -e
8+
# Disable cause it makes helper script failed to work properly.
9+
# set -x
410

511
mkdir -p target
612

713
DOCKER="$1"
814
TARGET="$2"
915
SKIP_TESTS="$3"
1016

11-
bash ci/fetch-rust-docker.sh "$TARGET"
17+
travis_fold start "fetch.image.${TARGET}"
18+
travis_time_start
19+
travis_do_cmd bash ci/fetch-rust-docker.sh "$TARGET"
20+
travis_time_finish
21+
travis_fold end "fetch.image.${TARGET}"
22+
1223
if [ -f "ci/docker/$DOCKER/Dockerfile" ]; then
13-
docker build -t "$DOCKER" "ci/docker/$DOCKER/"
24+
travis_fold start "Build.Dockerfile.${DOCKER}"
25+
travis_time_start
26+
travis_do_cmd docker build -t "$DOCKER" "ci/docker/$DOCKER/"
27+
travis_time_finish
28+
travis_fold end "Build.Dockerfile.${DOCKER}"
1429
fi
1530

1631
docker run \

ci/fetch-rust-docker.sh

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,6 @@ TARGET="$1"
77
RUST_REPO="https://github.com/rust-lang/rust"
88
S3_BASE_URL="https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rustc-builds"
99

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-
3010
# Use images from rustc master
3111
case "$TARGET" in
3212
mips-unknown-linux-gnu) image=dist-mips-linux ;;
@@ -54,7 +34,7 @@ if ! docker tag "$digest" "rust-$TARGET"; then
5434
echo "Attempting to download $url"
5535
rm -f "$cache"
5636
set +e
57-
retry curl -y 30 -Y 10 --connect-timeout 30 -f -L -C - -o "$cache" "$url"
37+
travis_retry curl -y 30 -Y 10 --connect-timeout 30 -f -L -C - -o "$cache" "$url"
5838
docker load -i "$cache"
5939
set -e
6040
docker tag "$digest" "rust-$TARGET"

ci/shared.bash

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/false
2+
#
3+
# This file is intended to be sourced, hence the invalid shebang and
4+
# not being marked as an executable file in git.
5+
6+
# This is from
7+
# https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis_setup_env.bash
8+
travis_setup_env() {
9+
export ANSI_RED='\e[31;1m'
10+
export ANSI_GREEN='\e[32;1m'
11+
export ANSI_YELLOW='\e[33;1m'
12+
export ANSI_RESET='\e[0m'
13+
export ANSI_CLEAR='\e[0K'
14+
}
15+
16+
# This is from
17+
# https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis_fold.bash
18+
travis_fold() {
19+
local action="${1}"
20+
local name="${2}"
21+
printf 'travis_fold:%s:%s\r'"${ANSI_CLEAR}" "${action}" "${name}"
22+
}
23+
24+
# This is modified loop version of
25+
# https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis_retry.bash
26+
travis_retry() {
27+
local result=0
28+
local count=1
29+
local max=5
30+
while [ "${count}" -le "${max}" ]; do
31+
[ "${result}" -ne 0 ] && {
32+
printf "${ANSI_RED}"'The command "%s" failed. Retrying, %s of %s.'"${ANSI_RESET}"'\n' "${*}" "${count}" "${max}" >&2
33+
}
34+
"${@}" && { result=0 && break; } || result="${?}"
35+
((count++))
36+
sleep 1
37+
done
38+
39+
[ "${count}" -gt "${max}" ] && {
40+
printf "${ANSI_RED}"'The command "%s" failed %s times.'"${ANSI_RESET}"'\n' "${*}" "${max}" >&2
41+
}
42+
43+
return "${result}"
44+
}
45+
46+
# This is from
47+
# https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/
48+
travis_nanoseconds() {
49+
local cmd='date'
50+
local format='+%s%N'
51+
52+
if command -v gdate >/dev/null 2>&1; then
53+
cmd='gdate'
54+
elif [ "$(uname)" = Darwin ]; then
55+
format='+%s000000000'
56+
fi
57+
58+
"${cmd}" -u "${format}"
59+
}
60+
61+
travis_time_start() {
62+
TRAVIS_TIMER_ID="$(printf '%08x' $((RANDOM * RANDOM)))"
63+
TRAVIS_TIMER_START_TIME="$(travis_nanoseconds)"
64+
export TRAVIS_TIMER_ID TRAVIS_TIMER_START_TIME
65+
printf 'travis_time:start:%s\r'"${ANSI_CLEAR}" "${TRAVIS_TIMER_ID}"
66+
}
67+
68+
travis_time_finish() {
69+
travis_timer_end_time="$(travis_nanoseconds)"
70+
local duration="$((travis_timer_end_time - TRAVIS_TIMER_START_TIME))"
71+
printf '\ntravis_time:end:%s:start=%s,finish=%s,duration=%s\r'"${ANSI_CLEAR}" \
72+
"${TRAVIS_TIMER_ID}" "${TRAVIS_TIMER_START_TIME}" \
73+
"${travis_timer_end_time}" "${duration}"
74+
}
75+
76+
travis_do_cmd() {
77+
echo "$ ${*}"
78+
"${@}"
79+
local result="$?"
80+
export TRAVIS_TEST_RESULT=$((${TRAVIS_TEST_RESULT:-0} | $((result != 0))))
81+
82+
if [ "${result}" -eq 0 ]; then
83+
printf '%b' "${ANSI_GREEN}"
84+
else
85+
printf '%b' "${ANSI_RED}"
86+
fi
87+
printf 'The command "%s" exited with %d.'"${ANSI_RESET}"'\n' "${*}" "${result}"
88+
return "$result"
89+
}
90+
91+
travis_setup_env
92+
93+
export -f travis_retry travis_fold travis_time_start travis_time_finish travis_nanoseconds

0 commit comments

Comments
 (0)