use `docker run --user` instead of manually creating a user

This commit is contained in:
Jorge Aparicio 2016-09-30 18:37:41 -05:00
parent d2036122f1
commit b60d2515ff
1 changed files with 8 additions and 11 deletions

View File

@ -4,16 +4,18 @@
set -ex
run() {
local gid=$(id -g) \
group=$(id -g -n) \
target=$1 \
uid=$(id -u) \
user=$(id -u -n)
local target=$1
echo $target
# This directory needs to exist before calling docker, otherwise docker will create it but it
# will be owned by root
mkdir -p target
docker build -t $target ci/docker/$target
docker run \
--rm \
--user $(id -u):$(id -g) \
-e CARGO_HOME=/cargo \
-e CARGO_TARGET_DIR=/target \
-v $HOME/.cargo:/cargo \
@ -22,12 +24,7 @@ run() {
-v `rustc --print sysroot`:/rust:ro \
-w /checkout \
-it $target \
sh -c "
groupadd -g $gid $group
useradd -m -g $gid -u $uid $user
chown $user /cargo /target
su -c 'PATH=\$PATH:/rust/bin ci/run.sh $target' $user
"
sh -c "PATH=\$PATH:/rust/bin ci/run.sh $target"
}
if [ -z "$1" ]; then