2015-10-22 06:41:38 +00:00
#!/usr/bin/env bash
#
# Prerequisites:
# Git Bash (http://www.git-scm.com/downloads)
# Docker Toolbox (https://www.docker.com/docker-toolbox)
# Ensure Hyper-V is disabled!
SOURCE = " ${ BASH_SOURCE [0] } "
while [ -h " $SOURCE " ] ; do # resolve $SOURCE until the file is no longer a symlink
DIR = " $( cd -P " $( dirname " $SOURCE " ) " && pwd ) "
SOURCE = " $( readlink " $SOURCE " ) "
[ [ $SOURCE != /* ] ] && SOURCE = " $DIR / $SOURCE " # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR = " $( cd -P " $( dirname " $SOURCE " ) " && pwd ) "
2015-10-22 17:23:47 +00:00
# This function is necessary to bypass POSIX Path Conversion in Git Bash
# http://www.mingw.org/wiki/Posix_path_conversion
2015-10-22 06:41:38 +00:00
_convert_path( ) {
local path = $1
path = $( echo " $path " | sed -r 's/[\/]+/\\/g' )
path = ${ path # \\ }
path = //$path
echo $path
}
# Bypass Msys path conversion
REPO_ROOT = $( readlink -f $DIR /..)
REPO_ROOT = $( _convert_path $REPO_ROOT )
VM_NAME = "dotnet"
VM_CODE_DIR = "/home/docker/code"
RESULTS_DIR = " $REPO_ROOT /artifacts "
execute( ) {
check_prereqs
echo "Setting up VM..."
2015-10-22 17:23:47 +00:00
create_or_start_vm
2015-10-22 06:41:38 +00:00
echo "Copying code from Host to VM"
eval $( docker-machine env --shell bash $VM_NAME )
copy_code_to_vm
echo "Running Build in Docker Container"
run_build
echo "Copying Results from VM to Hosts..."
copy_results_from_vm
}
check_prereqs( ) {
if ! which docker; then
echo "Error: Install docker toolbox (https://www.docker.com/docker-toolbox)"
exit 1
fi
if ! which docker-machine; then
echo "Error: Install docker toolbox (https://www.docker.com/docker-toolbox)"
exit 1
fi
}
create_or_start_vm( ) {
if [ [ $( docker-machine ls | grep $VM_NAME ) = = "" ] ] ; then
docker-machine create -d virtualbox $VM_NAME
else
docker-machine start $VM_NAME
fi
}
copy_code_to_vm( ) {
docker-machine ssh $VM_NAME " sudo rm -rf $VM_CODE_DIR "
docker-machine scp -r $REPO_ROOT $VM_NAME :$VM_CODE_DIR >> /dev/null 2>& 1
}
run_build( ) {
2015-10-22 17:13:05 +00:00
# These are env variables for dockerbuild.sh
export DOCKER_HOST_SHARE_DIR = " $( _convert_path $VM_CODE_DIR ) "
2015-10-22 22:12:49 +00:00
export BUILD_COMMAND = "//opt\\code\\build.sh"
2015-10-22 17:13:05 +00:00
$DIR /dockerbuild.sh
2015-10-22 06:41:38 +00:00
}
# This will duplicate the entire repo + any side effects from
# the operations in the docker container
copy_results_from_vm( ) {
T_RESULTS_DIR = $( echo " $RESULTS_DIR " | sed -r 's/[\\]+/\//g' )
T_RESULTS_DIR = ${ T_RESULTS_DIR #/ }
mkdir $T_RESULTS_DIR
2015-10-22 17:13:05 +00:00
docker-machine ssh $VM_NAME " sudo chmod -R a+rx $VM_CODE_DIR "
2015-10-22 17:23:47 +00:00
docker-machine scp -r $VM_NAME :$VM_CODE_DIR /artifacts $REPO_ROOT >> /dev/null 2>& 1
2015-10-22 06:41:38 +00:00
}
execute