Skip to content

Commit b60d251

Browse files
author
Jorge Aparicio
committed
use docker run --user instead of manually creating a user
1 parent d203612 commit b60d251

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

ci/run-docker.sh

+8-11
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44
set -ex
55

66
run() {
7-
local gid=$(id -g) \
8-
group=$(id -g -n) \
9-
target=$1 \
10-
uid=$(id -u) \
11-
user=$(id -u -n)
7+
local target=$1
128

139
echo $target
10+
11+
# This directory needs to exist before calling docker, otherwise docker will create it but it
12+
# will be owned by root
13+
mkdir -p target
14+
1415
docker build -t $target ci/docker/$target
1516
docker run \
1617
--rm \
18+
--user $(id -u):$(id -g) \
1719
-e CARGO_HOME=/cargo \
1820
-e CARGO_TARGET_DIR=/target \
1921
-v $HOME/.cargo:/cargo \
@@ -22,12 +24,7 @@ run() {
2224
-v `rustc --print sysroot`:/rust:ro \
2325
-w /checkout \
2426
-it $target \
25-
sh -c "
26-
groupadd -g $gid $group
27-
useradd -m -g $gid -u $uid $user
28-
chown $user /cargo /target
29-
su -c 'PATH=\$PATH:/rust/bin ci/run.sh $target' $user
30-
"
27+
sh -c "PATH=\$PATH:/rust/bin ci/run.sh $target"
3128
}
3229

3330
if [ -z "$1" ]; then

0 commit comments

Comments
 (0)