3 ##############################################################################
4 # Copyright (c) 2015 Ericsson AB and others.
5 # stefan.k.berg@ericsson.com
6 # jonas.bjurel@ericsson.com
7 # All rights reserved. This program and the accompanying materials
8 # are made available under the terms of the Apache License, Version 2.0
9 # which accompanies this distribution, and is available at
10 # http://www.apache.org/licenses/LICENSE-2.0
11 ##############################################################################
14 ############################################################################
15 # BEGIN of Exit handlers
22 docker kill $CID > /dev/null 2>&1
23 docker rm -f $CID > /dev/null 2>&1
24 docker rmi -f $IID > /dev/null 2>&1
29 # End of Exit handlers
30 ############################################################################
33 trap do_exit SIGINT SIGTERM EXIT
39 res=`docker build -q --force-rm - <<EOF
41 $(env | egrep -i 'proxy|rsync' | sed 's/^/ENV /' | sed 's/=/ /')
43 RUN /root/setcontext $USER $UID $GID $HOME
45 GITROOT=`git rev-parse --show-toplevel`
46 IID=`echo $res | sed 's/.* //'`
48 CID_FILE=`mktemp -u -t runcontext.XXXXXXXXXX`
50 # Handle proxy settings passed to the context
51 if env | grep -iq .*proxy; then
52 envfile="$(readlink -f $(dirname $0)/..)/environment.mk"
54 test -n "$HTTP_PROXY" && my_http_proxy=$HTTP_PROXY
55 test -n "$http_proxy" && my_http_proxy=$http_proxy
57 test -n "$HTTPS_PROXY" && my_https_proxy=$HTTPS_PROXY
58 test -n "$https_proxy" && my_https_proxy=$https_proxy
60 test -n "$NO_PROXY" && my_no_proxy=$NO_PROXY
61 test -n "$no_proxy" && my_no_proxy=$no_proxy
63 # Make sure to add the Docker socket in no_proxy
64 if [ -n "$my_no_proxy" ]; then
65 my_no_proxy+=",/var/run/docker.sock"
67 my_no_proxy="/var/run/docker.sock"
70 echo "Creating $envfile"
71 echo "# This file is automatically generated by runcontext, do not edit!" > $envfile
72 test -n "$my_http_proxy" && echo "export http_proxy=$my_http_proxy" >> $envfile
73 test -n "$my_https_proxy" && echo "export https_proxy=$my_https_proxy" >> $envfile
74 test -n "$my_no_proxy" && echo "export no_proxy=$my_no_proxy" >> $envfile
75 test -n "$RSYNC_PROXY" && echo "export RSYNC_PROXY=$RSYNC_PROXY" >> $envfile
76 test -n "$RSYNC_CONNECT_PROG" && echo "export RSYNC_CONNECT_PROG=$RSYNC_CONNECT_PROG" >> $envfile
77 echo "export npm_config_registry=http://registry.npmjs.org/" >> $envfile
79 echo "No need to generate environment.mk"
83 # Evaluate the need for bind mounting the cache directory
84 if [ -n "$CACHEBASE" ]; then
85 if echo $CACHEBASE | grep -q '^file://'; then
86 CACHEMOUNT="-v $(echo $CACHEBASE | sed 's;file://;;'):$(echo $CACHEBASE | sed 's;file://;;')"
90 RUN_CONTEXT_OPT="--cidfile $CID_FILE --privileged=true --rm -e HOME=$HOME -e CACHEDEBUG -e CACHETRANSPORT -e CACHEMAXAGE -e CACHEBASE -u $USER -w $PWD -v ${HOME}/.ssh:${HOME}/.ssh -v $GITROOT:$GITROOT $CACHEMOUNT"
92 # Passing "debug" puts up an interactive bash shell
93 if [ "$1" == "debug" ]; then
94 echo command: docker run ${RUN_CONTEXT_OPT} $IID $@
95 docker run -i -t ${RUN_CONTEXT_OPT} $IID bash
97 echo command: docker run ${RUN_CONTEXT_OPT} $IID $@
98 docker run -t ${RUN_CONTEXT_OPT} $IID $@