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 set -ex
run() { run() {
local gid=$(id -g) \ local target=$1
group=$(id -g -n) \
target=$1 \
uid=$(id -u) \
user=$(id -u -n)
echo $target 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 build -t $target ci/docker/$target
docker run \ docker run \
--rm \ --rm \
--user $(id -u):$(id -g) \
-e CARGO_HOME=/cargo \ -e CARGO_HOME=/cargo \
-e CARGO_TARGET_DIR=/target \ -e CARGO_TARGET_DIR=/target \
-v $HOME/.cargo:/cargo \ -v $HOME/.cargo:/cargo \
@ -22,12 +24,7 @@ run() {
-v `rustc --print sysroot`:/rust:ro \ -v `rustc --print sysroot`:/rust:ro \
-w /checkout \ -w /checkout \
-it $target \ -it $target \
sh -c " sh -c "PATH=\$PATH:/rust/bin ci/run.sh $target"
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
"
} }
if [ -z "$1" ]; then if [ -z "$1" ]; then