Skip to content

Commit 5c96587

Browse files
committed
Support for specifying the runner user.
1 parent 9e4f648 commit 5c96587

File tree

4 files changed

+57
-56
lines changed

4 files changed

+57
-56
lines changed

runner/Dockerfile.arch

+1-8
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@ RUN pacman -Suy --noconfirm --needed \
1212
# clean-up
1313
&& find /var/cache/pacman/ -type f -delete
1414

15-
RUN useradd --create-home --shell /bin/bash --groups wheel pkgeval && \
16-
echo '%wheel ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
17-
18-
RUN mkdir /storage /cache && \
19-
chown pkgeval /storage /cache
20-
21-
WORKDIR /home/pkgeval
22-
USER pkgeval
15+
RUN mkdir /storage /cache
2316

2417
COPY ./entrypoint.sh /
2518
ENTRYPOINT ["/entrypoint.sh"]

runner/Dockerfile.ubuntu

+1-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
1414
# clean-up
1515
&& rm -rf /var/lib/apt/lists/*
1616

17-
RUN useradd --create-home --shell /bin/bash --groups sudo pkgeval && \
18-
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
19-
20-
RUN mkdir /storage /cache && \
21-
chown pkgeval /storage /cache
22-
23-
WORKDIR /home/pkgeval
24-
USER pkgeval
17+
RUN mkdir /storage /cache
2518

2619
COPY ./entrypoint.sh /
2720
ENTRYPOINT ["/entrypoint.sh"]

runner/entrypoint.sh

+32-15
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,40 @@
11
#!/bin/bash -ue
22

3-
DEPOT=$1
4-
shift
53

6-
mkdir $DEPOT
4+
# prepare the user
75

8-
mkdir -p /storage/artifacts
9-
ln -s /storage/artifacts $DEPOT/artifacts
6+
USER=$1
7+
USER_ID=$2
8+
GROUP=$3
9+
GROUP_ID=$4
10+
shift 4
11+
12+
groupadd --gid $GROUP_ID $GROUP
13+
echo "$GROUP ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
14+
15+
useradd --uid $USER_ID --gid $GROUP_ID --shell /bin/bash --no-create-home --no-user-group $USER
16+
# manual home creation because it might be mounted tmpfs already
17+
mkdir -p /home/$USER
18+
chown $USER:$GROUP /home/$USER
19+
20+
# make the storage and cache writable, in case we didn't mount one
21+
chown $USER /storage /cache
1022

11-
# allow identification of PkgEal
12-
export CI=true
13-
export PKGEVAL=true
14-
export JULIA_PKGEVAL=true
1523

16-
# disable system discovery of Python and R
17-
export PYTHON=""
18-
export R_HOME="*"
24+
# prepare the depot
25+
26+
mkdir /home/$USER/.julia
27+
chown $USER:$GROUP /home/$USER/.julia
28+
29+
mkdir -p /storage/artifacts
30+
ln -s /storage/artifacts /home/$USER/.julia/artifacts
31+
1932

20-
# no automatic precompilation
21-
export JULIA_PKG_PRECOMPILE_AUTO=0
33+
# run the command
2234

23-
exec "$@"
35+
cd /home/$USER
36+
sudo --user $USER --set-home \
37+
CI=true PKGEVAL=true JULIA_PKGEVAL=true \
38+
JULIA_PKG_PRECOMPILE_AUTO=0 \
39+
PYTHON="" R_HOME="*" \
40+
-- "$@"

src/run.jl

+23-25
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ end
4242
function runner_sandboxed_julia(install::String, args=``; interactive=true, tty=true,
4343
name=nothing, cpus::Vector{Int}=Int[], tmpfs::Bool=true,
4444
storage=nothing, cache=nothing, sysimage=nothing,
45-
depot="/home/pkgeval/.julia", install_dir="/opt/julia",
4645
xvfb::Bool=true, init::Bool=true,
47-
runner="ubuntu")
46+
runner="ubuntu", user="pkgeval", group="pkgeval",
47+
install_dir="/opt/julia")
4848
## Docker args
4949

5050
cmd = `docker run --rm`
@@ -61,7 +61,7 @@ function runner_sandboxed_julia(install::String, args=``; interactive=true, tty=
6161
@assert isdir(registry_path)
6262
cmd = ```$cmd --mount type=bind,source=$julia_path,target=$install_dir,readonly
6363
--mount type=bind,source=$registry_path,target=/usr/local/share/julia/registries,readonly
64-
--env JULIA_DEPOT_PATH="$depot:/usr/local/share/julia"
64+
--env JULIA_DEPOT_PATH="::/usr/local/share/julia"
6565
--env JULIA_PKG_SERVER
6666
```
6767

@@ -75,10 +75,7 @@ function runner_sandboxed_julia(install::String, args=``; interactive=true, tty=
7575

7676
# mount working directory in tmpfs
7777
if tmpfs
78-
cmd = `$cmd --tmpfs /home/pkgeval:exec,uid=1000,gid=1000`
79-
# FIXME: tmpfs mounts don't copy uid/gid back, so we need to correct this manually
80-
# https://github.com/opencontainers/runc/issues/1647
81-
# FIXME: this also breaks mounting artifacts in the depot directly
78+
cmd = `$cmd --tmpfs /home/$user:exec`
8279
end
8380

8481
# restrict resource usage
@@ -105,16 +102,32 @@ function runner_sandboxed_julia(install::String, args=``; interactive=true, tty=
105102
cmd = `$cmd newpkgeval:$runner`
106103

107104

105+
## Entrypoint script args
106+
107+
# use the current user and group ID to ensure cache and storage are writable
108+
uid = ccall(:getuid, Cint, ())
109+
gid = ccall(:getgid, Cint, ())
110+
if uid < 1000 || gid < 1000
111+
# system ids might conflict with groups/users in the container
112+
@warn "You are running PkgEval as a system user (with id $uid:$gid); this is not compatible with the container set-up.
113+
I will be using id 1000:1000, but that means the cache and storage on the host file system will not be owned by you."
114+
uid = 1000
115+
gid = 1000
116+
end
117+
118+
cmd = `$cmd $user $uid $group $gid`
119+
120+
108121
## Julia args
109122

110123
if sysimage !== nothing
111124
args = `--sysimage=$sysimage $args`
112125
end
113126

114127
if xvfb
115-
`$cmd $depot xvfb-run $install_dir/bin/julia $args`
128+
`$cmd xvfb-run $install_dir/bin/julia $args`
116129
else
117-
`$cmd $depot $install_dir/bin/julia $args`
130+
`$cmd $install_dir/bin/julia $args`
118131
end
119132
end
120133

@@ -443,7 +456,7 @@ function run_compiled_test(install::String, pkg; compile_time_limit=30*60, cache
443456
# in another path, etc)
444457
return run_sandboxed_test(install, pkg; runner="arch",
445458
cache=cache, sysimage=sysimage_path,
446-
depot="/home/pkgeval/.another_julia",
459+
user="user", group="group",
447460
install_dir="/usr/local/julia", kwargs...)
448461
end
449462

@@ -495,15 +508,6 @@ function run(configs::Vector{Configuration}, pkgs::Vector;
495508
storage = storage_dir()
496509
mkpath(storage)
497510

498-
# make sure data is writable
499-
for (config, (install,cache)) in instantiated_configs
500-
Base.run(```docker run --mount type=bind,source=$storage,target=/storage
501-
--mount type=bind,source=$cache,target=/cache
502-
--entrypoint=''
503-
newpkgeval:ubuntu
504-
sudo chown -R pkgeval:pkgeval /storage /cache```)
505-
end
506-
507511
# ensure we can use Docker's API
508512
info = let
509513
docker = connect("/var/run/docker.sock")
@@ -737,12 +741,6 @@ function run(configs::Vector{Configuration}, pkgs::Vector;
737741
# clean-up
738742
for (config, (install,cache)) in instantiated_configs
739743
rm(install; recursive=true)
740-
uid = ccall(:getuid, Cint, ())
741-
gid = ccall(:getgid, Cint, ())
742-
Base.run(```docker run --mount type=bind,source=$cache,target=/cache
743-
--entrypoint=''
744-
newpkgeval:ubuntu
745-
sudo chown -R $uid:$gid /cache```)
746744
rm(cache; recursive=true)
747745
end
748746
end

0 commit comments

Comments
 (0)