From e31f88d9e861ad8793efafcf4f67391d7f3f2b8f Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Wed, 3 Oct 2018 00:47:43 -0400 Subject: [PATCH] xfer to azure function --- .circleci/config.yml | 18 ---- .../.gitignore => .gitignore | 14 ++- .vscode/extensions.json | 6 ++ .vscode/launch.json | 54 +++--------- .vscode/settings.json | 7 ++ .vscode/tasks.json | 76 +++++++++++++--- aka.terribledev.io.sln | 39 --------- host.json | 8 ++ redirectFunction.csproj | 18 ++++ redirectFunctionTrig.cs | 54 ++++++++++++ src/aka.terribledev.io/Dockerfile | 16 ---- src/aka.terribledev.io/Program.cs | 24 ------ src/aka.terribledev.io/README.md | 1 - src/aka.terribledev.io/Routes.cs | 21 ----- src/aka.terribledev.io/Startup.cs | 81 ------------------ .../aka.terribledev.io.csproj | 14 --- src/aka.terribledev.io/appsettings.json | 13 --- src/aka.terribledev.io/favicon.ico | Bin 1150 -> 0 bytes 18 files changed, 170 insertions(+), 294 deletions(-) delete mode 100644 .circleci/config.yml rename src/aka.terribledev.io/.gitignore => .gitignore (97%) create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json delete mode 100644 aka.terribledev.io.sln create mode 100644 host.json create mode 100644 redirectFunction.csproj create mode 100644 redirectFunctionTrig.cs delete mode 100644 src/aka.terribledev.io/Dockerfile delete mode 100644 src/aka.terribledev.io/Program.cs delete mode 100644 src/aka.terribledev.io/README.md delete mode 100644 src/aka.terribledev.io/Routes.cs delete mode 100644 src/aka.terribledev.io/Startup.cs delete mode 100644 src/aka.terribledev.io/aka.terribledev.io.csproj delete mode 100644 src/aka.terribledev.io/appsettings.json delete mode 100644 src/aka.terribledev.io/favicon.ico diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index cb6d66c..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,18 +0,0 @@ -version: 2 -jobs: - build: - machine: true - steps: - - checkout - # start proprietary DB using private Docker image - # with credentials stored in the UI - - run: | - docker login -u $DOCKER_USER -p $DOCKER_PASS - - # build the application image - - run: docker build -t terribledev/public:redirect-latest src/aka.terribledev.io - - run: docker build -t terribledev/public:redirect-$CIRCLE_SHA1 src/aka.terribledev.io - - # deploy the image - - run: docker push terribledev/public:redirect-latest - - run: docker push terribledev/public:redirect-$CIRCLE_SHA1 \ No newline at end of file diff --git a/src/aka.terribledev.io/.gitignore b/.gitignore similarity index 97% rename from src/aka.terribledev.io/.gitignore rename to .gitignore index 1b86e7e..ff5b00c 100644 --- a/src/aka.terribledev.io/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. +# Azure Functions localsettings file +local.settings.json + # User-specific files *.suo *.user @@ -110,10 +113,6 @@ _TeamCity* # DotCover is a Code Coverage Tool *.dotCover -# Visual Studio code coverage results -*.coverage -*.coveragexml - # NCrunch _NCrunch_* .*crunch*.local.xml @@ -147,7 +146,7 @@ publish/ *.azurePubxml # TODO: Comment the next line if you want to checkin your web deploy settings # but database connection strings (with potential passwords) will be unencrypted -*.pubxml +#*.pubxml *.publishproj # Microsoft Azure Web App publish settings. Comment the next line if you want to @@ -262,7 +261,4 @@ paket-files/ # Python Tools for Visual Studio (PTVS) __pycache__/ -*.pyc - -# Cake - Uncomment if you are using it -# tools/ +*.pyc \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..3a030cc --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "ms-azuretools.vscode-azurefunctions", + "ms-vscode.csharp" + ] +} diff --git a/.vscode/launch.json b/.vscode/launch.json index 1c8e748..761e83b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,45 +1,11 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": ".NET Core Launch (web)", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build", - "program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/aka.terribledev.io.dll", - "args": [], - "cwd": "${workspaceFolder}", - "stopAtEntry": false, - "internalConsoleOptions": "openOnSessionStart", - "launchBrowser": { - "enabled": true, - "args": "${auto-detect-url}", - "windows": { - "command": "cmd.exe", - "args": "/C start ${auto-detect-url}" - }, - "osx": { - "command": "open" - }, - "linux": { - "command": "xdg-open" - } - }, - "env": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "sourceFileMap": { - "/Views": "${workspaceFolder}/Views" - } - }, - { - "name": ".NET Core Attach", - "type": "coreclr", - "request": "attach", - "processId": "${command:pickProcess}" - } - ] -} \ No newline at end of file + "version": "0.2.0", + "configurations": [ + { + "name": "Attach to C# Functions", + "type": "coreclr", + "request": "attach", + "processId": "${command:azureFunctions.pickProcess}" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..554e493 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "azureFunctions.projectRuntime": "~2", + "azureFunctions.projectLanguage": "C#", + "azureFunctions.templateFilter": "Verified", + "azureFunctions.deploySubpath": "bin/Release/netstandard2.0/publish", + "azureFunctions.preDeployTask": "publish" +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json index e4bcfc9..3a186ab 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,15 +1,63 @@ { - "version": "2.0.0", - "tasks": [ - { - "taskName": "build", - "command": "dotnet", - "type": "process", - "args": [ - "build", - "${workspaceFolder}/aka.terribledev.io.csproj" - ], - "problemMatcher": "$msCompile" - } - ] -} \ No newline at end of file + "version": "2.0.0", + "tasks": [ + { + "label": "clean", + "command": "dotnet clean", + "type": "shell", + "presentation": { + "reveal": "always" + }, + "problemMatcher": "$msCompile" + }, + { + "label": "build", + "command": "dotnet build", + "type": "shell", + "dependsOn": "clean", + "group": { + "kind": "build", + "isDefault": true + }, + "presentation": { + "reveal": "always" + }, + "problemMatcher": "$msCompile" + }, + { + "label": "clean release", + "command": "dotnet clean --configuration Release", + "type": "shell", + "presentation": { + "reveal": "always" + }, + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "identifier": "publish", + "command": "dotnet publish --configuration Release", + "type": "shell", + "dependsOn": "clean release", + "presentation": { + "reveal": "always" + }, + "problemMatcher": "$msCompile" + }, + { + "label": "Run Functions Host", + "identifier": "runFunctionsHost", + "type": "shell", + "dependsOn": "build", + "options": { + "cwd": "${workspaceFolder}/bin/Debug/netstandard2.0" + }, + "command": "func host start", + "isBackground": true, + "presentation": { + "reveal": "always" + }, + "problemMatcher": "$func-watch" + } + ] +} diff --git a/aka.terribledev.io.sln b/aka.terribledev.io.sln deleted file mode 100644 index 554cfca..0000000 --- a/aka.terribledev.io.sln +++ /dev/null @@ -1,39 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26124.0 -MinimumVisualStudioVersion = 15.0.26124.0 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{76B6E6E4-7CB3-41EC-9DD1-A15E689FE559}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "aka.terribledev.io", "src\aka.terribledev.io\aka.terribledev.io.csproj", "{823CD559-D111-4801-8E80-902407DED329}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {823CD559-D111-4801-8E80-902407DED329}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {823CD559-D111-4801-8E80-902407DED329}.Debug|Any CPU.Build.0 = Debug|Any CPU - {823CD559-D111-4801-8E80-902407DED329}.Debug|x64.ActiveCfg = Debug|Any CPU - {823CD559-D111-4801-8E80-902407DED329}.Debug|x64.Build.0 = Debug|Any CPU - {823CD559-D111-4801-8E80-902407DED329}.Debug|x86.ActiveCfg = Debug|Any CPU - {823CD559-D111-4801-8E80-902407DED329}.Debug|x86.Build.0 = Debug|Any CPU - {823CD559-D111-4801-8E80-902407DED329}.Release|Any CPU.ActiveCfg = Release|Any CPU - {823CD559-D111-4801-8E80-902407DED329}.Release|Any CPU.Build.0 = Release|Any CPU - {823CD559-D111-4801-8E80-902407DED329}.Release|x64.ActiveCfg = Release|Any CPU - {823CD559-D111-4801-8E80-902407DED329}.Release|x64.Build.0 = Release|Any CPU - {823CD559-D111-4801-8E80-902407DED329}.Release|x86.ActiveCfg = Release|Any CPU - {823CD559-D111-4801-8E80-902407DED329}.Release|x86.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {823CD559-D111-4801-8E80-902407DED329} = {76B6E6E4-7CB3-41EC-9DD1-A15E689FE559} - EndGlobalSection -EndGlobal diff --git a/host.json b/host.json new file mode 100644 index 0000000..ee90cba --- /dev/null +++ b/host.json @@ -0,0 +1,8 @@ +{ + "version": "2.0", + "extensions": { + "http": { + "routePrefix": "" + } + } +} diff --git a/redirectFunction.csproj b/redirectFunction.csproj new file mode 100644 index 0000000..8acbdf6 --- /dev/null +++ b/redirectFunction.csproj @@ -0,0 +1,18 @@ + + + netstandard2.0 + v2 + + + + + + + PreserveNewest + + + PreserveNewest + Never + + + \ No newline at end of file diff --git a/redirectFunctionTrig.cs b/redirectFunctionTrig.cs new file mode 100644 index 0000000..f96c087 --- /dev/null +++ b/redirectFunctionTrig.cs @@ -0,0 +1,54 @@ + +using System; +using System.IO; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Azure.WebJobs; +using Microsoft.Azure.WebJobs.Extensions.Http; +using Microsoft.AspNetCore.Http; +using Microsoft.Azure.WebJobs.Host; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using System.Collections.Generic; +using System.Linq; + +namespace TerribleDev +{ + public static class redirectFunction + { + public static Dictionary RoutesDictionary = new Dictionary() + { + ["docker101"] = "https://blog.terribledev.io/Getting-started-with-docker-containers/", + ["dockerfortran"] = "https://github.com/TerribleDev/Fortran-docker-mvc", + ["blog"] = "https://blog.terribledev.io", + ["github"] = "https://github.com/terribledev", + ["git-cheatsheet"] = "https://github.com/TerribleDev/Git-CheatSheet", + ["janus-intro"] = "https://janus-vistaprint.github.io/intro-deck/", + ["jenkins-groovy"] = "https://jenkinsci.github.io/job-dsl-plugin/", + ["feedback"] = "https://docs.google.com/forms/d/e/1FAIpQLSetozvuoSVTOb_lTH0CvQhYMzsXGggGQQdEEq041uQpJlOxVg/viewform?usp=sf_link", + ["wineodistro"] = "https://docs.google.com/forms/d/e/1FAIpQLSf7caM9mjS9H1graJ9BnT1sRkUV2cyGF1dJVUCnMV0f2NXu4A/viewform?usp=sf_link", + ["react-samples"] = "https://github.com/terribledev/react-samples", + ["react-sample"] = "https://github.com/terribledev/react-samples" + }; + + public static class redirectFunctionTrig + { + [FunctionName("redirectFunctionTrig")] + public static async Task Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "{path}")] + HttpRequest req, + ILogger log, + string path) + { + var name = path.ToString().TrimEnd('/'); + if (!RoutesDictionary.TryGetValue(name, out string result)) + { + return new NotFoundObjectResult("hello"); + } + else + { + return new RedirectResult(result); + } + } + } + } +} diff --git a/src/aka.terribledev.io/Dockerfile b/src/aka.terribledev.io/Dockerfile deleted file mode 100644 index 7b0e939..0000000 --- a/src/aka.terribledev.io/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM microsoft/dotnet:2.1-sdk AS build -WORKDIR /app - -# copy csproj and restore as distinct layers -COPY aka.terribledev.io.csproj . -RUN dotnet restore - -# copy everything else and build app -COPY . . -RUN dotnet publish -c Release -o out - - -FROM microsoft/dotnet:2.1-aspnetcore-runtime AS runtime -WORKDIR /app -COPY --from=build /app/out ./ -ENTRYPOINT ["dotnet", "aka.terribledev.io.dll"] \ No newline at end of file diff --git a/src/aka.terribledev.io/Program.cs b/src/aka.terribledev.io/Program.cs deleted file mode 100644 index e162352..0000000 --- a/src/aka.terribledev.io/Program.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.Configuration; -using Microsoft.AspNetCore; - -namespace aka.terribledev.io -{ - public class Program - { - public static void Main(string[] args) - { - CreateWebHostBuilder(args).Build().Run(); - } - - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup(); - } -} diff --git a/src/aka.terribledev.io/README.md b/src/aka.terribledev.io/README.md deleted file mode 100644 index 03388e7..0000000 --- a/src/aka.terribledev.io/README.md +++ /dev/null @@ -1 +0,0 @@ -Short urls...what else... diff --git a/src/aka.terribledev.io/Routes.cs b/src/aka.terribledev.io/Routes.cs deleted file mode 100644 index 6dc27fb..0000000 --- a/src/aka.terribledev.io/Routes.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Collections.Generic; - -namespace aka.terribledev.io -{ - public static class Routes - { - public static Dictionary RoutesDictionary = new Dictionary(){ - ["docker101"] = "https://blog.terribledev.io/Getting-started-with-docker-containers/", - ["dockerfortran"] = "https://github.com/TerribleDev/Fortran-docker-mvc", - ["blog"] = "https://blog.terribledev.io", - ["github"] = "https://github.com/terribledev", - ["git-cheatsheet"] = "https://github.com/TerribleDev/Git-CheatSheet", - ["janus-intro"] = "https://janus-vistaprint.github.io/intro-deck/", - ["jenkins-groovy"] = "https://jenkinsci.github.io/job-dsl-plugin/", - ["feedback"] = "https://docs.google.com/forms/d/e/1FAIpQLSetozvuoSVTOb_lTH0CvQhYMzsXGggGQQdEEq041uQpJlOxVg/viewform?usp=sf_link", - ["wineodistro"] = "https://docs.google.com/forms/d/e/1FAIpQLSf7caM9mjS9H1graJ9BnT1sRkUV2cyGF1dJVUCnMV0f2NXu4A/viewform?usp=sf_link", - ["react-samples"] = "https://github.com/terribledev/react-samples", - ["react-sample"] = "https://github.com/terribledev/react-samples" - }; - } -} diff --git a/src/aka.terribledev.io/Startup.cs b/src/aka.terribledev.io/Startup.cs deleted file mode 100644 index 9dbdc03..0000000 --- a/src/aka.terribledev.io/Startup.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.AspNetCore.Routing; -using Microsoft.AspNetCore.Http; -using System.Text; - -namespace aka.terribledev.io -{ - public class Startup - { - public static byte[] hello = System.Text.Encoding.UTF8.GetBytes("hello"); - public static byte[] fourOhFor = System.Text.Encoding.UTF8.GetBytes("404"); - public static int helloCount = hello.Count(); - public static byte[] favicon = System.IO.File.ReadAllBytes("favicon.ico"); - public static int faviconByteCount = favicon.Count(); - public Startup(IHostingEnvironment env) - { - var builder = new ConfigurationBuilder() - .SetBasePath(env.ContentRootPath) - .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) - .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) - .AddEnvironmentVariables(); - Configuration = builder.Build(); - } - - public IConfigurationRoot Configuration { get; } - - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { - services.AddApplicationInsightsTelemetry(); - services.AddRouting(); - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) - { - loggerFactory.AddConsole(Configuration.GetSection("Logging")); - loggerFactory.AddDebug(); - app.UseRouter(a=>{ - a.MapGet("favicon.ico", b=> - { - b.Response.StatusCode = 200; - return b.Response.Body.WriteAsync(favicon, 0, faviconByteCount); - }); - a.MapGet("links", b=> - { - b.Response.StatusCode = 200; - var resultString = String.Join(Environment.NewLine, Routes.RoutesDictionary.Select(c=> $"/{c.Key} -> {c.Value}")); - return b.Response.WriteAsync(resultString); - }); - foreach(var route in Routes.RoutesDictionary) - { - a.MapGet(route.Key, handler: async b=>{ - b.Response.Redirect(route.Value, true); - }); - } - - a.MapVerb("HEAD", "", async b =>{ - b.Response.StatusCode = 200; - }); - a.MapVerb("GET", "", async b => { - b.Response.StatusCode = 200; - await b.Response.Body.WriteAsync(Startup.hello, 0, helloCount); - }); - }); - app.Use(async (context, next)=>{ - context.Response.StatusCode = 404; - await context.Response.Body.WriteAsync(fourOhFor, 0, fourOhFor.Count()); - }); - - } - } -} diff --git a/src/aka.terribledev.io/aka.terribledev.io.csproj b/src/aka.terribledev.io/aka.terribledev.io.csproj deleted file mode 100644 index c641a9a..0000000 --- a/src/aka.terribledev.io/aka.terribledev.io.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - netcoreapp2.1 - aka.terribledev.io - aka.terribledev.io - - - - - - - - - \ No newline at end of file diff --git a/src/aka.terribledev.io/appsettings.json b/src/aka.terribledev.io/appsettings.json deleted file mode 100644 index 01c25ba..0000000 --- a/src/aka.terribledev.io/appsettings.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "Logging": { - "IncludeScopes": false, - "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information" - } - }, - "ApplicationInsights": { - "InstrumentationKey": "c65d5477-68f6-4c5d-ac58-36ff3be6c8d5" - } -} \ No newline at end of file diff --git a/src/aka.terribledev.io/favicon.ico b/src/aka.terribledev.io/favicon.ico deleted file mode 100644 index 1e7aaf56c0fdc1feeb49108559367fbeef4c57e6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1150 zcmZQzU<5(|0R|wcz>vYhz#zuJz@P!dKp~(AL>x#lFaYJy!TFFt)FkwO- zIsWVF>M8<;)n5<>nvqY68GU_y`B1(8fiwvJoiu4uHZf*^)S>AGo594y^mp2{Y3caP zShQ$S6i6M^PMFACeBeVjW6hd10WdX$ z=nWe-_)?;O)22;6==$Hhc_W1GekCQPy9x>l_mJHqA|mn%!do;h>I2%FxaD+WxUz!U<*|LPeS{@61x{E%m0 T_`uJ=@PHi^f9yx71?d3*)tQP?