]> git.lizzy.rs Git - rust.git/blob - src/ci/docker/run.sh
Retry when downloading the Docker cache.
[rust.git] / src / ci / docker / run.sh
1 #!/usr/bin/env bash
2 # Copyright 2016 The Rust Project Developers. See the COPYRIGHT
3 # file at the top-level directory of this distribution and at
4 # http://rust-lang.org/COPYRIGHT.
5 #
6 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
7 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
9 # option. This file may not be copied, modified, or distributed
10 # except according to those terms.
11
12 set -e
13
14 export MSYS_NO_PATHCONV=1
15
16 script=`cd $(dirname $0) && pwd`/`basename $0`
17 image=$1
18
19 docker_dir="`dirname $script`"
20 ci_dir="`dirname $docker_dir`"
21 src_dir="`dirname $ci_dir`"
22 root_dir="`dirname $src_dir`"
23
24 source "$ci_dir/shared.sh"
25
26 travis_fold start build_docker
27 travis_time_start
28
29 if [ -f "$docker_dir/$image/Dockerfile" ]; then
30     if [ "$CI" != "" ]; then
31       cksum=$(find $docker_dir/$image $docker_dir/scripts -type f | \
32         sort | \
33         xargs cat | \
34         sha512sum | \
35         awk '{print $1}')
36       s3url="s3://$SCCACHE_BUCKET/docker/$cksum"
37       url="https://s3-us-west-1.amazonaws.com/$SCCACHE_BUCKET/docker/$cksum"
38       echo "Attempting to download $s3url"
39       rm -f /tmp/rustci_docker_cache
40       set +e
41       retry curl -f -L -C - -o /tmp/rustci_docker_cache "$url"
42       loaded_images=$(docker load -i /tmp/rustci_docker_cache | sed 's/.* sha/sha/')
43       set -e
44       echo "Downloaded containers:\n$loaded_images"
45     fi
46
47     dockerfile="$docker_dir/$image/Dockerfile"
48     if [ -x /usr/bin/cygpath ]; then
49         context="`cygpath -w $docker_dir`"
50         dockerfile="`cygpath -w $dockerfile`"
51     else
52         context="$docker_dir"
53     fi
54     retry docker \
55       build \
56       --rm \
57       -t rust-ci \
58       -f "$dockerfile" \
59       "$context"
60
61     if [ "$s3url" != "" ]; then
62       digest=$(docker inspect rust-ci --format '{{.Id}}')
63       echo "Built container $digest"
64       if ! grep -q "$digest" <(echo "$loaded_images"); then
65         echo "Uploading finished image to $s3url"
66         set +e
67         docker history -q rust-ci | \
68           grep -v missing | \
69           xargs docker save | \
70           gzip | \
71           aws s3 cp - $s3url
72         set -e
73       else
74         echo "Looks like docker image is the same as before, not uploading"
75       fi
76     fi
77 elif [ -f "$docker_dir/disabled/$image/Dockerfile" ]; then
78     if [ -n "$TRAVIS_OS_NAME" ]; then
79         echo Cannot run disabled images on travis!
80         exit 1
81     fi
82     # retry messes with the pipe from tar to docker. Not needed on non-travis
83     # Transform changes the context of disabled Dockerfiles to match the enabled ones
84     tar --transform 's#^./disabled/#./#' -C $docker_dir -c . | docker \
85       build \
86       --rm \
87       -t rust-ci \
88       -f "$image/Dockerfile" \
89       -
90 else
91     echo Invalid image: $image
92     exit 1
93 fi
94
95 travis_fold end build_docker
96 travis_time_finish
97
98 objdir=$root_dir/obj
99
100 mkdir -p $HOME/.cargo
101 mkdir -p $objdir/tmp
102
103 args=
104 if [ "$SCCACHE_BUCKET" != "" ]; then
105     args="$args --env SCCACHE_BUCKET"
106     args="$args --env SCCACHE_REGION"
107     args="$args --env AWS_ACCESS_KEY_ID"
108     args="$args --env AWS_SECRET_ACCESS_KEY"
109 else
110     mkdir -p $HOME/.cache/sccache
111     args="$args --env SCCACHE_DIR=/sccache --volume $HOME/.cache/sccache:/sccache"
112 fi
113
114 # Run containers as privileged as it should give them access to some more
115 # syscalls such as ptrace and whatnot. In the upgrade to LLVM 5.0 it was
116 # discovered that the leak sanitizer apparently needs these syscalls nowadays so
117 # we'll need `--privileged` for at least the `x86_64-gnu` builder, so this just
118 # goes ahead and sets it for all builders.
119 args="$args --privileged"
120
121 exec docker \
122   run \
123   --volume "$root_dir:/checkout:ro" \
124   --volume "$objdir:/checkout/obj" \
125   --workdir /checkout/obj \
126   --env SRC=/checkout \
127   $args \
128   --env CARGO_HOME=/cargo \
129   --env DEPLOY \
130   --env DEPLOY_ALT \
131   --env LOCAL_USER_ID=`id -u` \
132   --env TRAVIS \
133   --env TRAVIS_BRANCH \
134   --env TOOLSTATE_REPO_ACCESS_TOKEN \
135   --env CI_JOB_NAME="${CI_JOB_NAME-$IMAGE}" \
136   --volume "$HOME/.cargo:/cargo" \
137   --volume "$HOME/rustsrc:$HOME/rustsrc" \
138   --init \
139   --rm \
140   rust-ci \
141   /checkout/src/ci/run.sh