2015-10-13 04:47:07 +02:00
|
|
|
# docker run magrathea without tty
|
|
|
|
monad-run()
|
|
|
|
{
|
|
|
|
monad-docker-run "--attach STDOUT --attach STDERR" $*
|
|
|
|
}
|
|
|
|
|
|
|
|
# docker run magrathea with interactive tty
|
|
|
|
monad-tty()
|
|
|
|
{
|
|
|
|
monad-docker-run "--interactive --tty" $*
|
|
|
|
}
|
|
|
|
|
|
|
|
# runs ephemeral andschwa/magrathea docker container with local
|
2015-10-13 22:36:35 +02:00
|
|
|
# directory mounted to /opt and workdir set to /opt/scripts
|
2015-10-13 04:47:07 +02:00
|
|
|
monad-docker-run()
|
|
|
|
{
|
|
|
|
local CONSOLE=$1
|
|
|
|
shift 1
|
|
|
|
docker run --rm \
|
2015-10-13 22:36:35 +02:00
|
|
|
--volume $(dirname $(pwd))/:/opt \
|
|
|
|
--workdir /opt/scripts \
|
2015-10-13 04:47:07 +02:00
|
|
|
$CONSOLE \
|
|
|
|
andschwa/magrathea:latest \
|
2015-10-14 17:58:01 +02:00
|
|
|
bash -c "$(monad-impersonate) bash -c '$*'"
|
2015-10-13 04:47:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# creates new user in container matching the local user so that
|
|
|
|
# artifacts will be owned by the local user; set IMPERSONATE to false
|
|
|
|
# to disable and run as root, defaults to true
|
|
|
|
if [[ ! $IMPERSONATE ]]; then IMPERSONATE=true; fi
|
|
|
|
monad-impersonate()
|
|
|
|
{
|
|
|
|
if ! $IMPERSONATE; then return; fi
|
|
|
|
local CUID=$(id -u)
|
|
|
|
local CUSER=$(id -un)
|
|
|
|
local CGID=$(id -g)
|
|
|
|
local CGROUP=$(id -gn)
|
|
|
|
echo \
|
|
|
|
groupadd -g $CGID $CGROUP '&&' \
|
|
|
|
useradd -u $CUID -g $CGID -d /opt $CUSER '&&' \
|
2015-10-14 17:58:01 +02:00
|
|
|
sudo --set-home -u $CUSER -g $CGROUP --
|
2015-10-13 04:47:07 +02:00
|
|
|
}
|