]> git.lizzy.rs Git - rust.git/blob - src/ci/docker/run.sh
ci: Don't use Travis caches for docker images
[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       set +e
40       loaded_images=$(curl $url | docker load | sed 's/.* sha/sha/')
41       set -e
42       echo "Downloaded containers:\n$loaded_images"
43     fi
44
45     dockerfile="$docker_dir/$image/Dockerfile"
46     if [ -x /usr/bin/cygpath ]; then
47         context="`cygpath -w $docker_dir`"
48         dockerfile="`cygpath -w $dockerfile`"
49     else
50         context="$docker_dir"
51     fi
52     retry docker \
53       build \
54       --rm \
55       -t rust-ci \
56       -f "$dockerfile" \
57       "$context"
58
59     if [ "$s3url" != "" ]; then
60       digest=$(docker inspect rust-ci --format '{{.Id}}')
61       echo "Built container $digest"
62       if ! grep -q "$digest" <(echo "$loaded_images"); then
63         echo "Uploading finished image to $s3url"
64         set +e
65         docker history -q rust-ci | \
66           grep -v missing | \
67           xargs docker save | \
68           gzip | \
69           aws s3 cp - $s3url
70         set -e
71       else
72         echo "Looks like docker image is the same as before, not uploading"
73       fi
74     fi
75 elif [ -f "$docker_dir/disabled/$image/Dockerfile" ]; then
76     if [ -n "$TRAVIS_OS_NAME" ]; then
77         echo Cannot run disabled images on travis!
78         exit 1
79     fi
80     # retry messes with the pipe from tar to docker. Not needed on non-travis
81     # Transform changes the context of disabled Dockerfiles to match the enabled ones
82     tar --transform 's#^./disabled/#./#' -C $docker_dir -c . | docker \
83       build \
84       --rm \
85       -t rust-ci \
86       -f "$image/Dockerfile" \
87       -
88 else
89     echo Invalid image: $image
90     exit 1
91 fi
92
93 travis_fold end build_docker
94 travis_time_finish
95
96 objdir=$root_dir/obj
97
98 mkdir -p $HOME/.cargo
99 mkdir -p $objdir/tmp
100
101 args=
102 if [ "$SCCACHE_BUCKET" != "" ]; then
103     args="$args --env SCCACHE_BUCKET"
104     args="$args --env SCCACHE_REGION"
105     args="$args --env AWS_ACCESS_KEY_ID"
106     args="$args --env AWS_SECRET_ACCESS_KEY"
107     args="$args --env SCCACHE_ERROR_LOG=/tmp/sccache/sccache.log"
108     args="$args --volume $objdir/tmp:/tmp/sccache"
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   --volume "$HOME/.cargo:/cargo" \
136   --volume "$HOME/rustsrc:$HOME/rustsrc" \
137   --init \
138   --rm \
139   rust-ci \
140   /checkout/src/ci/run.sh