Version 0.0.1 of /fuel-bild
[genesis.git] / fuel-build / docker / runcontext
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2015 Ericsson AB and others.
4 # stefan.k.berg@ericsson.com
5 # jonas.bjurel@ericsson.com
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11 #
12 context=$1
13 shift
14 GID=`id -g`
15 USER=`whoami`
16 res=`docker build -q --rm -  <<EOF
17 FROM $context
18 RUN echo "invalidate cache" && echo "done"
19 RUN /usr/sbin/groupadd --gid $GID $USER
20 RUN /usr/sbin/adduser --system --uid=$UID --gid=$GID --home $HOME --shell /bin/bash $USER
21 RUN /usr/sbin/usermod -a -G fuse $USER
22 RUN echo "export HOME=$HOME" >> /etc/bash.bashrc
23 RUN echo "$@" >> /etc/bash.bashrc
24 RUN echo 'exit \\$?' >> /etc/bash.bashrc
25 EOF`
26 CID=`echo $res | sed 's/.* //'`
27 docker run --privileged=true --rm -i -t -u $USER -w $PWD -v ${HOME}/.ssh:${HOME}/.ssh -v $PWD:$PWD $CID bash
28 rc=$?
29 docker rmi $CID > /dev/null
30 exit $rc