From 4336cbe664198d8d1bb5f93ae2ba655d75422dfc Mon Sep 17 00:00:00 2001 From: "Francisco R. Del Roio" Date: Sat, 26 Aug 2017 00:27:03 -0300 Subject: [PATCH] Changes: * Added script installation process * Added the SDK download to the cache * Added a function to detect if a .csproj file is a valid web project - It uses python3 (installed by default into heroku) - Currently this function isn't used --- .gitattributes | 2 ++ bin/compile | 11 ++++------- lib/utils | 40 ++++++++++++++++++++++++++++++++-------- 3 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..6f9ecaf2 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Preventing Windows related problems (i.e. when testing under docker) +* eol=lf diff --git a/bin/compile b/bin/compile index b3c3b92a..943454a6 100755 --- a/bin/compile +++ b/bin/compile @@ -7,11 +7,6 @@ set -o pipefail # don't ignore exit codes when piping output set -o nounset # fail on unset variables unset GIT_DIR # Avoid GIT_DIR leak from previous build steps -if [ "$STACK" != "heroku-16" ]; then - echo "Need heroku-16 stack" - exit 1 -fi - ### Configure directories BUILD_DIR=${1:-} CACHE_DIR=${2:-} @@ -23,17 +18,17 @@ cp $BP_DIR/profile/* $BUILD_DIR/.profile.d/ ### Load dependencies source $BP_DIR/lib/utils +topic "Building ASP.Net core application ..." export_env_dir $ENV_DIR echo "Installing the dependencies" apt_install libunwind8 gettext -echo "Installing dotnet" install_dotnet $BUILD_DIR export PATH="/app/dotnet:${PATH}" -export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}" + cd $BUILD_DIR dotnet --info @@ -47,6 +42,8 @@ dotnet restore $PROJECT_FILE --runtime ubuntu.16.04-x64 echo "publish ${PROJECT_FILE}" dotnet publish $PROJECT_FILE --output ${BUILD_DIR}/heroku_output --configuration Release --runtime ubuntu.16.04-x64 + + cat << EOT >> ${BUILD_DIR}/Procfile web: cd \$HOME/heroku_output && ASPNETCORE_URLS='http://+:\$PORT' dotnet "./${PROJECT_NAME}.dll" --server.urls http://+:\$PORT EOT \ No newline at end of file diff --git a/lib/utils b/lib/utils index 226ffeb1..5d81d202 100755 --- a/lib/utils +++ b/lib/utils @@ -2,11 +2,30 @@ function install_dotnet() { local BUILD_DIR="$1" + local CORE_CHANNEL="${2:-2.0}" + local INSTALL_SCRIPT="$CACHE_DIR/dotnet-install.sh" + local INSTALL_DIR="$CACHE_DIR/dotnet" - # https://github.com/dotnet/core/blob/master/release-notes/download-archives/2.0.0-download.md - curl -sSL -o dotnet.tar.gz https://download.microsoft.com/download/1/B/4/1B4DE605-8378-47A5-B01B-2C79D6C55519/dotnet-sdk-2.0.0-linux-x64.tar.gz - mkdir -p ${BUILD_DIR}/dotnet && tar zxf dotnet.tar.gz -C ${BUILD_DIR}/dotnet - ln -s ${BUILD_DIR}/dotnet /app + topic "Installing .NET Core SDK" + if [ ! -d "$INSTALL_DIR" ]; then + if [ ! -d $CACHE_DIR ]; then + mkdir -p $CACHE_DIR + fi + + # Get the installer + curl -sSL -o $INSTALL_SCRIPT https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.sh + + # And made it executable + chmod +x $INSTALL_SCRIPT + + export DOTNET_INSTALL_SKIP_PREREQS=1 + $INSTALL_SCRIPT --install-dir $INSTALL_DIR --channel $CORE_CHANNEL + fi + + # Copy it to the app directory + cp -R $INSTALL_DIR $BUILD_DIR/dotnet + + ln -s $BUILD_DIR/dotnet /app } # https://github.com/ddollar/heroku-buildpack-apt @@ -62,10 +81,10 @@ function apt_install(){ export LD_LIBRARY_PATH="$BUILD_DIR/.apt/usr/lib/x86_64-linux-gnu:$BUILD_DIR/.apt/usr/lib/i386-linux-gnu:$BUILD_DIR/.apt/usr/lib:${LD_LIBRARY_PATH-}" export LIBRARY_PATH="$BUILD_DIR/.apt/usr/lib/x86_64-linux-gnu:$BUILD_DIR/.apt/usr/lib/i386-linux-gnu:$BUILD_DIR/.apt/usr/lib:${LIBRARY_PATH-}" export INCLUDE_PATH="$BUILD_DIR/.apt/usr/include:${INCLUDE_PATH-}" - export CPATH="${INCLUDE_PATH-}" - export CPPPATH="${INCLUDE_PATH-}" + export CPATH="$INCLUDE_PATH" + export CPPPATH="$INCLUDE_PATH" export PKG_CONFIG_PATH="$BUILD_DIR/.apt/usr/lib/x86_64-linux-gnu/pkgconfig:$BUILD_DIR/.apt/usr/lib/i386-linux-gnu/pkgconfig:$BUILD_DIR/.apt/usr/lib/pkgconfig:${PKG_CONFIG_PATH-}" - echo "APT packages Installled" + echo "APT packages Installed" } export_env_dir() { @@ -81,4 +100,9 @@ export_env_dir() { done fi fi -} \ No newline at end of file +} + +function valid_project() { + SDK_TYPE=`python3 -c "from xml.etree.ElementTree import ElementTree;import io;print(ElementTree(file=io.FileIO('$1')).getroot().attrib['Sdk'])"` + [ "$SDK_TYPE" = "Microsoft.NET.Sdk.Web" ] +}