Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
moustafarai authored Mar 25, 2019
2 parents 71bf200 + bd35bd1 commit 364d9a4
Show file tree
Hide file tree
Showing 13 changed files with 270 additions and 44 deletions.
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
# .NET Core Buildpack Changelog

## 2019-03-13

- Updated .NET Core 2.2.105

## 2019-02-13

- Updated .NET Core 2.2.104

## 2019-01-10

- Updated .NET Core 2.2.102

## 2018-12-06

- Updated .NET Core 2.2.100

## 2018-10-18

- Updated .NET Core 2.2.0-preview3

## 2018-11-14

- Updated .NET Core 2.1.500

## 2018-10-18

- Updated .NET Core 2.1.403

## 2018-09-13

- Updated .NET Core 2.1.402
- Updated .NET Core 2.2.0-preview2

## 2018-08-29

- Updated .NET Core 2.2.0-preview1

## 2018-08-22

- Updated .NET Core 2.1.401
Expand Down
59 changes: 41 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,75 @@ This is the [Heroku buildpack](https://devcenter.heroku.com/articles/buildpacks)

[![Build status](https://ci.appveyor.com/api/projects/status/5864d533m5d35nsa?svg=true)](https://ci.appveyor.com/project/jincod/dotnetcore-buildpack)


## Usage

.NET Core latest stable
The Buildpack will search through the repository's folders to locate a `Startup.cs` or `Program.cs` file. If found, the `.csproj` in the containing folder will be used in the `dotnet publish <project>.csproj` command.

```
heroku buildpacks:set https://github.com/jincod/dotnetcore-buildpack
```
If repository contains **multiple** Web Applications (multiple `Startup.cs`), `PROJECT_FILE` and `PROJECT_NAME` environment variables allow to choose project for publishing.

.NET Core 2.1.301
### .NET Core latest stable

```
heroku buildpacks:set https://github.com/jincod/dotnetcore-buildpack#v2.1.301
heroku buildpacks:set jincod/dotnetcore
```

.NET Core 2.1.300
### .NET Core edge

```
heroku buildpacks:set https://github.com/jincod/dotnetcore-buildpack#v2.1.300
heroku buildpacks:set https://github.com/jincod/dotnetcore-buildpack
```

.NET Core 2.1.200
### Previous releases

```
heroku buildpacks:set https://github.com/jincod/dotnetcore-buildpack#v2.1.200
heroku buildpacks:set https://github.com/jincod/dotnetcore-buildpack#version
```

.NET Core 1.1.5 (LTS)

```
heroku buildpacks:set https://github.com/jincod/dotnetcore-buildpack#v1.1.5
```
Available [releases](https://github.com/jincod/dotnetcore-buildpack/releases)

More info

- [Heroku Buildpack Registry](https://devcenter.heroku.com/articles/buildpack-registry)
- [Buildpack references](https://devcenter.heroku.com/articles/buildpacks#buildpack-references)

## Entity Framework Core Migrations

You cannot run migrations with the `dotnet ef` commands once the app is built. Alternatives include:

### Enabling Automatic Migrations

- Ensure the `ASPNETCORE_ENVIRONMENT` environment variable is set to `Production`. ASP.NET Core scaffolding tools may create files that explicitly set it to `Development`. Heroku config will override this (`heroku config:set ASPNETCORE_ENVIRONMENT=Production`).
- Configure your app to automatically run migrations at startup by adding the following to the `.csproj` file:

```xml
<Target Name="PrePublishTarget" AfterTargets="Publish">
<Exec Command="dotnet ef database update" />
</Target>
```

- Configure your connection string string appropriately, for example, for PostgreSQL:

`sslmode=Prefer;Trust Server Certificate=true`

### Manually Running Migration Scripts on the Database

- Manually run SQL scripts generated by Entity Framework Core in your app's database. For example, use PG Admin to connect your Heroku Postgres service.

## Node.js and NPM

```bash
heroku buildpacks:set https://github.com/jincod/dotnetcore-buildpack
heroku buildpacks:set jincod/dotnetcore
heroku buildpacks:add --index 1 heroku/nodejs
```

[Using Multiple Buildpacks for an App](https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app)

## Example

[ASP.NET Core Demo App](https://github.com/jincod/AspNet5DemoApp)
[ASP.NET Core Demo App](https://github.com/jincod/AspNet5DemoApp)

## Donation

If this project help you, you can give me a cup of coffee ☕

[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/jincod/5)
27 changes: 15 additions & 12 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -28,43 +28,46 @@ export_env_dir "$ENV_DIR"
export NUGET_XMLDOC_MODE=${NUGET_XMLDOC_MODE:-skip}
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=${DOTNET_SKIP_FIRST_TIME_EXPERIENCE:-1}
export DOTNET_CLI_TELEMETRY_OPTOUT=${DOTNET_CLI_TELEMETRY_OPTOUT:-1}
export NUGET_PACKAGES="${CACHE_DIR}/nuget/cache"

DOTNET_SDK_VERSION=${DOTNET_SDK_VERSION:-2.2.105}
DOTNET_RUNTIME_VERSION=${DOTNET_RUNTIME_VERSION:-2.2.3}
BUILD_CONFIGURATION=${BUILD_CONFIGURATION:-Release}

echo "Installing dotnet"
install_dotnet $BUILD_DIR $CACHE_DIR
install_dotnet $BUILD_DIR $CACHE_DIR $DOTNET_SDK_VERSION $DOTNET_RUNTIME_VERSION

export PATH="${BUILD_DIR}/.heroku/dotnet:${PATH}"

cd $BUILD_DIR

if [ -z ${PROJECT_FILE:-} ]; then
PROJECT_FILE=$(x=$(dirname $(find ${BUILD_DIR} -maxdepth 5 -iname Startup.cs | head -1)); while [[ "$x" =~ $BUILD_DIR ]] ; do find "$x" -maxdepth 1 -name *.csproj; x=`dirname "$x"`; done)
PROJECT_FILE=$(x=$(dirname $(find ${BUILD_DIR} -maxdepth 5 -iname Startup.cs -o -iname Program.cs | head -1)); while [[ "$x" =~ $BUILD_DIR ]] ; do find "$x" -maxdepth 1 -name *.csproj; x=`dirname "$x"`; done)
fi
if [ -z ${PROJECT_NAME:-} ]; then
PROJECT_NAME=$(basename ${PROJECT_FILE%.*})
fi
if [ -n "$(cat $PROJECT_FILE | grep 'netcoreapp2.0')" ]; then
topic "WARNING"
echo "For netcoreapp2.0 use https://github.com/jincod/dotnetcore-buildpack#v2.1.200" | indent
echo "More info https://github.com/jincod/dotnetcore-buildpack/issues/44" | indent
fi
export NUGET_PACKAGES="${CACHE_DIR}/nuget/cache"
sed -i "s/NUGETSELOGERLOGIN/${NUGETSELOGERLOGIN}/g" ${BUILD_DIR}/nuget.heroku
sed -i "s/NUGETSELOGERPASSWORD/${NUGETSELOGERPASSWORD}/g" ${BUILD_DIR}/nuget.heroku
rm -f ${BUILD_DIR}/nuget.config
mv ${BUILD_DIR}/nuget.heroku ${BUILD_DIR}/nuget.config
echo "publish ${PROJECT_FILE}"
dotnet publish $PROJECT_FILE --output ${BUILD_DIR}/heroku_output --configuration Release --runtime linux-x64
echo "publish ${PROJECT_FILE} for ${BUILD_CONFIGURATION}"
dotnet publish $PROJECT_FILE --output ${BUILD_DIR}/heroku_output --configuration ${BUILD_CONFIGURATION} --runtime linux-x64
if [ ! -f ${BUILD_DIR}/Procfile ]; then
if [ -f ${BUILD_DIR}/Procfile ] && grep -q '^web:' ${BUILD_DIR}/Procfile ; then
topic "WARNING"
echo "Be careful with custom Procfile" | indent
else
echo "Add web process to Procfile" | indent
cat << EOT >> ${BUILD_DIR}/Procfile
web: cd \$HOME/heroku_output && ./${PROJECT_NAME}
EOT
else
topic "WARNING"
echo "Be careful with custom Procfile" | indent
fi
2 changes: 2 additions & 0 deletions bin/detect
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

if [ -n "$(find $1 -maxdepth 5 -iname Startup.cs)" ]; then
echo "ASP.NET Core" && exit 0
elif [ -n "$(find $1 -maxdepth 5 -iname Program.cs)" ]; then
echo "Core .NET" && exit 0
else
echo "no" && exit 1
fi
42 changes: 28 additions & 14 deletions lib/utils
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
#!/usr/bin/env bash

function install_dotnet() {
local BUILD_DIR="$1"
local CACHE_DIR="$2"
local ZIP_NAME="dotnet-2.1.401.tar.gz"

if [ ! -f $CACHE_DIR/$ZIP_NAME ]; then
curl -sSL -o $CACHE_DIR/$ZIP_NAME https://download.microsoft.com/download/E/8/A/E8AF2EE0-5DDA-4420-A395-D1A50EEFD83E/dotnet-sdk-2.1.401-linux-x64.tar.gz
else
echo "$ZIP_NAME from cache folder"
fi

mkdir -p ${BUILD_DIR}/.heroku/dotnet && tar zxf $CACHE_DIR/$ZIP_NAME -C ${BUILD_DIR}/.heroku/dotnet
}

# https://github.com/ddollar/heroku-buildpack-apt
function topic() {
echo "-----> $*"
Expand All @@ -27,6 +13,34 @@ function indent() {
esac
}

function install_dotnet() {
local BUILD_DIR="$1"
local CACHE_DIR="$2"
local DOTNET_SDK_VERSION="$3"
local DOTNET_RUNTIME_VERSION="$4"

local DOTNET_CACHE_LOCATION=${CACHE_DIR}/dotnet/${DOTNET_SDK_VERSION}
if [ ! -d ${DOTNET_CACHE_LOCATION} ]; then
topic "Removing old cached .NET version"
rm -rf ${CACHE_DIR}/dotnet/* || true
mkdir -p ${DOTNET_CACHE_LOCATION}/{sdk,runtime}

topic "Fetching .NET SDK"
local DOTNET_SDK_DOWNLOAD_URL=https://dotnetcli.blob.core.windows.net/dotnet/Sdk/$DOTNET_SDK_VERSION/dotnet-sdk-$DOTNET_SDK_VERSION-linux-x64.tar.gz
curl -sSL ${DOTNET_SDK_DOWNLOAD_URL} | tar xz -C ${DOTNET_CACHE_LOCATION}/sdk
find ${DOTNET_CACHE_LOCATION}/sdk/sdk/${DOTNET_SDK_VERSION}/runtimes/* -maxdepth 0 ! -name unix -exec rm -r {} +
rm -f ${DOTNET_CACHE_LOCATION}/sdk/sdk/${DOTNET_SDK_VERSION}/nuGetPackagesArchive.lzma

topic "Fetching .NET Runtime"
local DOTNET_RUNTIME_DOWNLOAD_URL=https://dotnetcli.blob.core.windows.net/dotnet/Runtime/$DOTNET_RUNTIME_VERSION/dotnet-runtime-$DOTNET_RUNTIME_VERSION-linux-x64.tar.gz
curl -sSL ${DOTNET_RUNTIME_DOWNLOAD_URL} | tar xz -C ${DOTNET_CACHE_LOCATION}/runtime
fi

export PATH="${DOTNET_CACHE_LOCATION}/sdk:$PATH"
mkdir -p ${BUILD_DIR}/.heroku/dotnet
cp -r ${DOTNET_CACHE_LOCATION}/runtime ${BUILD_DIR}/.heroku/dotnet
}

export_env_dir() {
local env_dir=$1
if [ -d "$env_dir" ]; then
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/custom-procfile/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: ./hello
25 changes: 25 additions & 0 deletions test/fixtures/dotnetcore-2.1/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace dotnetcore_2_1
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}
31 changes: 31 additions & 0 deletions test/fixtures/dotnetcore-2.1/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

namespace dotnetcore_2_1
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
}
}
}
11 changes: 11 additions & 0 deletions test/fixtures/dotnetcore-2.1/dotnetcore-2.1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.6" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions test/fixtures/dotnetcore-2.2/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace dotnetcore_2_2
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}
31 changes: 31 additions & 0 deletions test/fixtures/dotnetcore-2.2/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

namespace dotnetcore_2_2
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
}
}
}
Loading

0 comments on commit 364d9a4

Please sign in to comment.