Skip to content

Commit

Permalink
Reduce amount of script needed dotnet#1
Browse files Browse the repository at this point in the history
  • Loading branch information
Attila Hajdrik committed Nov 6, 2017
1 parent becac74 commit 2cff724
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 155 deletions.
60 changes: 23 additions & 37 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,33 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

# Some things depend on HOME and it may not be set. We should fix those things, but until then, we just patch a value in
if [ -z "$HOME" ]; then
export HOME=$DIR/artifacts/home

[ ! -d "$HOME" ] || rm -Rf $HOME
mkdir -p $HOME
fi

args=( "$@" )

while [[ $# > 0 ]]; do
lowerI="$(echo $1 | awk '{print tolower($0)}')"
case $lowerI in
--docker)
export BUILD_IN_DOCKER=1
export DOCKER_IMAGENAME=$2
# remove docker args
args=( "${args[@]/$1}" )
args=( "${args[@]/$2}" )
shift
;;
*)
esac
shift
done
cd "$DIR/.."

DOCKER_IMAGENAME=microsoft/dotnet/2.0-sdk-2.0.2

# $args array may have empty elements in it.
# The easiest way to remove them is to cast to string and back to array.
# This will actually break quoted arguments, arguments like
# This will actually break quoted arguments, arguments like
# -test "hello world" will be broken into three arguments instead of two, as it should.
temp="${args[@]}"
args=($temp)

dockerbuild()
{
BUILD_COMMAND=/opt/code/run-build.sh $DIR/scripts/dockerrun.sh --non-interactive "$@"
}

# Check if we need to build in docker
if [ ! -z "$BUILD_IN_DOCKER" ]; then
dockerbuild "${args[@]}"
else
$DIR/run-build.sh "${args[@]}"
fi
BUILD_COMMAND=/opt/code/run-build.sh $DIR/scripts/dockerrun.sh --non-interactive "${args[@]}"

[ -z "$DOCKER_HOST_SHARE_DIR" ] && DOCKER_HOST_SHARE_DIR=$(pwd)

# Make container names CI-specific if we're running in CI
# Jenkins
[ ! -z "$BUILD_TAG" ] && DOTNET_BUILD_CONTAINER_NAME="$BUILD_TAG"
# VSO
[ ! -z "$BUILD_BUILDID" ] && DOTNET_BUILD_CONTAINER_NAME="$BUILD_BUILDID"

# Run the build in the container
echo "Launching build in Docker Container"
echo "Running command: $BUILD_COMMAND"
echo "Using code from: $DOCKER_HOST_SHARE_DIR"

docker run -t --rm --sig-proxy=true \
--name $DOCKER_IMAGENAME \
-v $DOCKER_HOST_SHARE_DIR:/opt/code \
$BUILD_COMMAND "$@"
121 changes: 3 additions & 118 deletions run-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,6 @@

set -e

machine_has() {
hash "$1" > /dev/null 2>&1
return $?
}

check_min_reqs() {
if ! machine_has "curl"; then
echo "run-build: Error: curl is required to download dotnet. Install curl to proceed." >&2
return 1
fi
return 0
}

# args:
# remote_path - $1
# [out_path] - $2 - stdout if not provided
download() {
eval $invocation

local remote_path=$1
local out_path=${2:-}

local failed=false
if [ -z "$out_path" ]; then
curl --retry 10 -sSL --create-dirs $remote_path || failed=true
else
curl --retry 10 -sSL --create-dirs -o $out_path $remote_path || failed=true
fi

if [ "$failed" = true ]; then
echo "run-build: Error: Download failed" >&2
return 1
fi
}

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
Expand All @@ -50,14 +15,10 @@ done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
REPOROOT="$DIR"

ARCHITECTURE="x64"
source "$REPOROOT/scripts/common/_prettyprint.sh"

BUILD=1

LINUX_PORTABLE_INSTALL_ARGS=
CUSTOM_BUILD_ARGS=

# Set nuget package cache under the repo
[ -z $NUGET_PACKAGES ] && export NUGET_PACKAGES="$REPOROOT/.nuget/packages"

Expand All @@ -72,54 +33,12 @@ while [[ $# > 0 ]]; do
args=( "${args[@]/$2}" )
shift
;;
--nopackage)
export DOTNET_BUILD_SKIP_PACKAGING=1
args=( "${args[@]/$1}" )
;;
--skip-prereqs)
# Allow CI to disable prereqs check since the CI has the pre-reqs but not ldconfig it seems
export DOTNET_INSTALL_SKIP_PREREQS=1
args=( "${args[@]/$1}" )
;;
--nobuild)
BUILD=0
;;
--architecture)
ARCHITECTURE=$2
args=( "${args[@]/$1}" )
args=( "${args[@]/$2}" )
shift
;;
--runtime-id)
CUSTOM_BUILD_ARGS="/p:Rid=\"$2\""
args=( "${args[@]/$1}" )
args=( "${args[@]/$2}" )
shift
;;
# This is here just to eat away this parameter because CI still passes this in.
--targets)
--targets)
args=( "${args[@]/$1}" )
args=( "${args[@]/$2}" )
shift
;;
--linux-portable)
LINUX_PORTABLE_INSTALL_ARGS="--runtime-id linux-x64"
CUSTOM_BUILD_ARGS="/p:Rid=\"linux-x64\" /p:OSName=\"linux\" /p:IslinuxPortable=\"true\""
args=( "${args[@]/$1}" )
;;
--help)
echo "Usage: $0 [--configuration <CONFIGURATION>] [--targets <TARGETS...>] [--skip-prereqs] [--nopackage] [--docker <IMAGENAME>] [--help]"
echo ""
echo "Options:"
echo " --configuration <CONFIGURATION> Build the specified Configuration (Debug or Release, default: Debug)"
echo " --skip-prereqs Skip checks for pre-reqs in dotnet_install"
echo " --nopackage Skip packaging targets"
echo " --nobuild Skip building, showing the command that would be used to build"
echo " --docker <IMAGENAME> Build in Docker using the Dockerfile located in scripts/docker/IMAGENAME"
echo " --linux-portable Builds the Linux portable .NET Tools instead of a distro-specific version."
echo " --help Display this help message"
exit 0
;;
*)
break
;;
Expand All @@ -135,32 +54,6 @@ done
temp="${args[@]}"
args=($temp)

# Create an install directory for the stage 0 CLI
[ -z "$DOTNET_INSTALL_DIR" ] && export DOTNET_INSTALL_DIR=$REPOROOT/.dotnet_stage0/$ARCHITECTURE
[ -d "$DOTNET_INSTALL_DIR" ] || mkdir -p $DOTNET_INSTALL_DIR

# We also need to pull down a project.json based CLI that is used by some tests
# so create another directory for that.
[ -z "$DOTNET_INSTALL_DIR_PJ" ] && export DOTNET_INSTALL_DIR_PJ=$REPOROOT/.dotnet_stage0PJ/$ARCHITECTURE
[ -d "$DOTNET_INSTALL_DIR_PJ" ] || mkdir -p $DOTNET_INSTALL_DIR_PJ

export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1

# Don't resolve shared frameworks from user or global locations
export DOTNET_MULTILEVEL_LOOKUP=0

# Install a stage 0
(set -x ; "$REPOROOT/scripts/obtain/dotnet-install.sh" --channel "release/2.0.2" --install-dir "$DOTNET_INSTALL_DIR" --architecture "$ARCHITECTURE" $LINUX_PORTABLE_INSTALL_ARGS)

EXIT_CODE=$?
if [ $EXIT_CODE != 0 ]; then
echo "run-build: Error: installing stage0 with exit code $EXIT_CODE." >&2
exit $EXIT_CODE
fi

# Put stage 0 on the PATH (for this shell only)
PATH="$DOTNET_INSTALL_DIR:$PATH"

# Increases the file descriptors limit for this bash. It prevents an issue we were hitting during restore
FILE_DESCRIPTOR_LIMIT=$( ulimit -n )
if [ $FILE_DESCRIPTOR_LIMIT -lt 1024 ]
Expand All @@ -169,15 +62,7 @@ then
ulimit -n 1024
fi

# Disable first run since we want to control all package sources
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1

echo "${args[@]}"

if [ $BUILD -eq 1 ]; then
dotnet build OrleansCrossPlatform.sln
dotnet pack OrleansCrossPlatform.sln
else
echo "Not building due to --nobuild"
echo "Command that would be run is: 'dotnet msbuild build.proj /m /p:Architecture=$ARCHITECTURE $CUSTOM_BUILD_ARGS ${args[@]}'"
fi
dotnet build OrleansCrossPlatform.sln /p:Configuration=$CONFIGURATION ${args[@]}
dotnet pack OrleansCrossPlatform.sln /p:Configuration=$CONFIGURATION ${args[@]}

0 comments on commit 2cff724

Please sign in to comment.