|
125 | 125 | # goes ahead and sets it for all builders.
|
126 | 126 | args="$args --privileged"
|
127 | 127 |
|
128 |
| -exec docker \ |
| 128 | +# Things get a little weird if this script is already running in a docker |
| 129 | +# container. If we're already in a docker container then we assume it's set up |
| 130 | +# to do docker-in-docker where we have access to a working `docker` command. |
| 131 | +# |
| 132 | +# If this is the case (we check via the presence of `/.dockerenv`) |
| 133 | +# then we can't actually use the `--volume` argument. Typically we use |
| 134 | +# `--volume` to efficiently share the build and source directory between this |
| 135 | +# script and the container we're about to spawn. If we're inside docker already |
| 136 | +# though the `--volume` argument maps the *host's* folder to the container we're |
| 137 | +# about to spawn, when in fact we want the folder in this container itself. To |
| 138 | +# work around this we use a recipe cribbed from |
| 139 | +# https://circleci.com/docs/2.0/building-docker-images/#mounting-folders to |
| 140 | +# create a temporary container with a volume. We then copy the entire source |
| 141 | +# directory into this container, and then use that copy in the container we're |
| 142 | +# about to spawn. Finally after the build finishes we re-extract the object |
| 143 | +# directory. |
| 144 | +# |
| 145 | +# Note that none of this is necessary if we're *not* in a docker-in-docker |
| 146 | +# scenario. If this script is run on a bare metal host then we share a bunch of |
| 147 | +# data directories to share as much data as possible. Note that we also use |
| 148 | +# `LOCAL_USER_ID` (recognized in `src/ci/run.sh`) to ensure that files are all |
| 149 | +# read/written as the same user as the bare-metal user. |
| 150 | +if [ -f /.dockerenv ]; then |
| 151 | + docker create -v /checkout --name checkout alpine:3.4 /bin/true |
| 152 | + docker cp . checkout:/checkout |
| 153 | + args="$args --volumes-from checkout" |
| 154 | +else |
| 155 | + args="$args --volume $root_dir:/checkout:ro" |
| 156 | + args="$args --volume $objdir:/checkout/obj" |
| 157 | + args="$args --volume $HOME/.cargo:/cargo" |
| 158 | + args="$args --volume $HOME/rustsrc:$HOME/rustsrc" |
| 159 | + args="$args --env LOCAL_USER_ID=`id -u`" |
| 160 | +fi |
| 161 | + |
| 162 | +docker \ |
129 | 163 | run \
|
130 |
| - --volume "$root_dir:/checkout:ro" \ |
131 |
| - --volume "$objdir:/checkout/obj" \ |
132 | 164 | --workdir /checkout/obj \
|
133 | 165 | --env SRC=/checkout \
|
134 | 166 | $args \
|
135 | 167 | --env CARGO_HOME=/cargo \
|
136 | 168 | --env DEPLOY \
|
137 | 169 | --env DEPLOY_ALT \
|
138 |
| - --env LOCAL_USER_ID=`id -u` \ |
139 | 170 | --env CI \
|
140 | 171 | --env TF_BUILD \
|
141 | 172 | --env BUILD_SOURCEBRANCHNAME \
|
142 | 173 | --env TOOLSTATE_REPO_ACCESS_TOKEN \
|
143 | 174 | --env TOOLSTATE_REPO \
|
144 | 175 | --env CI_JOB_NAME="${CI_JOB_NAME-$IMAGE}" \
|
145 |
| - --volume "$HOME/.cargo:/cargo" \ |
146 |
| - --volume "$HOME/rustsrc:$HOME/rustsrc" \ |
147 | 176 | --init \
|
148 | 177 | --rm \
|
149 | 178 | rust-ci \
|
150 | 179 | /checkout/src/ci/run.sh
|
| 180 | + |
| 181 | +if [ -f /.dockerenv ]; then |
| 182 | + rm -rf $objdir |
| 183 | + docker cp checkout:/checkout/obj $objdir |
| 184 | +fi |
0 commit comments