Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jyunderwood committed Dec 12, 2016
0 parents commit 89877f9
Show file tree
Hide file tree
Showing 17 changed files with 223 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
/bin
/obj
project.lock.json
19 changes: 19 additions & 0 deletions .vscode/launch.json
@@ -0,0 +1,19 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.1/HeroicHaiku.dll",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
]
}
16 changes: 16 additions & 0 deletions .vscode/tasks.json
@@ -0,0 +1,16 @@
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}/project.json"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}
21 changes: 21 additions & 0 deletions Controllers/HomeController.cs
@@ -0,0 +1,21 @@
using Microsoft.AspNetCore.Mvc;

namespace HeroicHaiku.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
public IActionResult About()
{
return View();
}

public IActionResult Error()
{
return View();
}
}
}
9 changes: 9 additions & 0 deletions Dockerfile
@@ -0,0 +1,9 @@
FROM microsoft/aspnetcore:1.1.0

RUN adduser --disabled-password deployuser
USER deployuser

WORKDIR /app
COPY . .

CMD ASPNETCORE_URLS=http://*:$PORT dotnet HeroicHaiku.dll
25 changes: 25 additions & 0 deletions Program.cs
@@ -0,0 +1,25 @@
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;

namespace HeroicHaiku
{
public class Program
{
public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.AddEnvironmentVariables(prefix: "ASPNETCORE_")
.Build();

var host = new WebHostBuilder()
.UseConfiguration(config)
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.Build();

host.Run();
}
}
}
11 changes: 11 additions & 0 deletions README.md
@@ -0,0 +1,11 @@
# ASP.NET Core MVC on Heroku

A barebones demo showing that an ASP.NET Core MVC app can run easily on Heroku via Docker.

Developed on a Mac with the .NET Core SDK v1.1. Please note, there is no IIS integration so this might not actually run in Visual Studio on Windows. Funny, isn't it?

# Requirements

- [.NET Core SDK v1.1](https://www.microsoft.com/net/download/core#/current)
- [Heroku Toolbelt](https://toolbelt.heroku.com/) (to authenticate with the Docker registry hosted by Heroku)
- [Docker Toolbox](https://docker.com/toolbox) (to build the images and push to a registry)
26 changes: 26 additions & 0 deletions Startup.cs
@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;

namespace HeroicHaiku
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});

app.UseStaticFiles();
}
}
}
8 changes: 8 additions & 0 deletions Tools/deploy
@@ -0,0 +1,8 @@
#!/usr/bin/env sh

dotnet publish
docker build bin/Debug/netcoreapp1.1/publish -t heroichaiku

docker login --username=_ --password=$(heroku auth:token) registry.heroku.com
docker tag heroichaiku registry.heroku.com/heroichaiku/web
docker push registry.heroku.com/heroichaiku/web
5 changes: 5 additions & 0 deletions Views/Home/About.cshtml
@@ -0,0 +1,5 @@
@{
ViewData["Title"] = "About";
}

<h2>@ViewData["Title"]</h2>
5 changes: 5 additions & 0 deletions Views/Home/Index.cshtml
@@ -0,0 +1,5 @@
@{
ViewData["Title"] = "Home";
}

<h2>@ViewData["Title"]</h2>
5 changes: 5 additions & 0 deletions Views/Shared/Error.cshtml
@@ -0,0 +1,5 @@
@{
ViewData["Title"] = "Error";
}

<h2>@ViewData["Title"]</h2>
27 changes: 27 additions & 0 deletions Views/Shared/_Layout.cshtml
@@ -0,0 +1,27 @@
<!DOCTYPE html>

<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"]</title>
<link rel="stylesheet" href="~/css/site.css">
</head>

<body>
<ul>
<li>
<a asp-area="" asp-controller="Home" asp-action="Index">
Home
</a>
</li>
<li>
<a asp-area="" asp-controller="Home" asp-action="About">
About
</a>
</li>
</ul>

@RenderBody()
</body>
</html>
2 changes: 2 additions & 0 deletions Views/_ViewImports.cshtml
@@ -0,0 +1,2 @@
@using HeroicHaiku
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
3 changes: 3 additions & 0 deletions Views/_ViewStart.cshtml
@@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}
35 changes: 35 additions & 0 deletions project.json
@@ -0,0 +1,35 @@
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.1.0",
"type": "platform"
},
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
"Microsoft.AspNetCore.StaticFiles": "1.1.0",
"Microsoft.AspNetCore.MVC": "1.1.0"
},

"frameworks": {
"netcoreapp1.1": { }
},

"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},

"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},

"publishOptions": {
"include": [
"**/*.cshtml",
"wwwroot",
"Dockerfile"
]
}
}
3 changes: 3 additions & 0 deletions wwwroot/css/site.css
@@ -0,0 +1,3 @@
html {
font-family: sans-serif;
}

0 comments on commit 89877f9

Please sign in to comment.