Files
PowerShell/monad-docker.sh
T

54 lines
1.3 KiB
Bash
Raw Normal View History

2015-11-04 15:03:57 -08:00
# docker run magrathea with a non-interactive tty
2015-10-12 19:47:07 -07:00
monad-run()
{
2015-11-04 15:03:57 -08:00
monad-docker-run "--tty" $*
2015-10-12 19:47:07 -07:00
}
# docker run magrathea with interactive tty
2015-11-04 15:03:57 -08:00
monad-it()
2015-10-12 19:47:07 -07:00
{
monad-docker-run "--interactive --tty" $*
}
2015-11-04 15:03:57 -08:00
monad-attach()
{
monad-docker-run "--attach STDOUT --attach STDERR" $*
}
2015-10-12 19:47:07 -07:00
# runs ephemeral andschwa/magrathea docker container with local
# directory mounted and workdir set to /opt
2015-10-12 19:47:07 -07:00
monad-docker-run()
{
local CONSOLE=$1
shift 1
docker run --rm \
2015-11-13 13:55:13 -08:00
--volume $(pwd)/:/opt/src \
--workdir /opt/src \
2015-10-12 19:47:07 -07:00
$CONSOLE \
andschwa/magrathea:latest \
2015-10-14 08:58:01 -07:00
bash -c "$(monad-impersonate) bash -c '$*'"
2015-10-12 19:47:07 -07: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)
2015-11-07 23:52:35 -08:00
# default docker-machine VM does not change
if [[ $OSTYPE == darwin* ]]; then
CUID=1000
CUSER=docker
CGID=50
CGROUP=staff
fi
2015-10-12 19:47:07 -07:00
echo \
2015-11-07 23:52:35 -08:00
groupadd -o -f -g $CGID $CGROUP '&&' \
2015-11-16 11:03:23 -08:00
useradd -u $CUID -g $CGID -G sudo -d /opt $CUSER '&&' \
2015-10-14 08:58:01 -07:00
sudo --set-home -u $CUSER -g $CGROUP --
2015-10-12 19:47:07 -07:00
}