From c9d2fafbbc5b4770ed772f6249a8a2fd16c52fef Mon Sep 17 00:00:00 2001 From: Jim Pelletier Date: Sun, 4 Dec 2016 13:32:11 +1100 Subject: [PATCH] add a dotnet core csharp template --- docker-compose.yml | 4 + lib/plugins/create/create.js | 1 + .../templates/aws-dotnet-csharp/.gitignore | 246 ++++++++++++++++++ .../aws-dotnet-csharp/AssemblyInfo.cs | 3 + .../templates/aws-dotnet-csharp/Handler.cs | 36 +++ .../templates/aws-dotnet-csharp/build.sh | 14 + .../templates/aws-dotnet-csharp/project.json | 33 +++ .../aws-dotnet-csharp/serverless.yml | 84 ++++++ tests/templates/test_all_templates | 1 + 9 files changed, 422 insertions(+) create mode 100644 lib/plugins/create/templates/aws-dotnet-csharp/.gitignore create mode 100644 lib/plugins/create/templates/aws-dotnet-csharp/AssemblyInfo.cs create mode 100755 lib/plugins/create/templates/aws-dotnet-csharp/Handler.cs create mode 100755 lib/plugins/create/templates/aws-dotnet-csharp/build.sh create mode 100755 lib/plugins/create/templates/aws-dotnet-csharp/project.json create mode 100644 lib/plugins/create/templates/aws-dotnet-csharp/serverless.yml diff --git a/docker-compose.yml b/docker-compose.yml index dbcb0b4c3..e625c61f2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,3 +32,7 @@ services: image: hseeberger/scala-sbt volumes: - ./tmp/serverless-integration-test-aws-scala-sbt:/app + aws-dotnet-csharp: + image: microsoft/dotnet:1.0.1-sdk-projectjson + volumes: + - ./tmp/serverless-integration-test-aws-dotnet-csharp:/app diff --git a/lib/plugins/create/create.js b/lib/plugins/create/create.js index e6984b49e..0c207400e 100644 --- a/lib/plugins/create/create.js +++ b/lib/plugins/create/create.js @@ -11,6 +11,7 @@ const validTemplates = [ 'aws-java-maven', 'aws-java-gradle', 'aws-scala-sbt', + 'aws-dotnet-csharp', 'plugin', ]; diff --git a/lib/plugins/create/templates/aws-dotnet-csharp/.gitignore b/lib/plugins/create/templates/aws-dotnet-csharp/.gitignore new file mode 100644 index 000000000..4dc157e7f --- /dev/null +++ b/lib/plugins/create/templates/aws-dotnet-csharp/.gitignore @@ -0,0 +1,246 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.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 +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Microsoft Azure ApplicationInsights config file +ApplicationInsights.config + +# Windows Store app package directory +AppPackages/ +BundleArtifacts/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe + +# FAKE - F# Make +.fake/ +*.orig + +# macOS +.DS_Store + +# JetBrains Rider C# IDE +.idea* + +# Serverless directories +.serverless diff --git a/lib/plugins/create/templates/aws-dotnet-csharp/AssemblyInfo.cs b/lib/plugins/create/templates/aws-dotnet-csharp/AssemblyInfo.cs new file mode 100644 index 000000000..59e636f29 --- /dev/null +++ b/lib/plugins/create/templates/aws-dotnet-csharp/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using Amazon.Lambda.Core; + +[assembly:LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] diff --git a/lib/plugins/create/templates/aws-dotnet-csharp/Handler.cs b/lib/plugins/create/templates/aws-dotnet-csharp/Handler.cs new file mode 100755 index 000000000..2b6f9728e --- /dev/null +++ b/lib/plugins/create/templates/aws-dotnet-csharp/Handler.cs @@ -0,0 +1,36 @@ +using System; + +namespace AwsDotnetCsharp +{ + public class Handler + { + public Response Hello(Request request) + { + return new Response("Go Serverless v1.0! Your function executed successfully!", request); + } + } + + public class Response + { + public string Message {get; set;} + public Request Request {get; set;} + + public Response(string message, Request request){ + Message = message; + Request = request; + } + } + + public class Request + { + public string Key1 {get; set;} + public string Key2 {get; set;} + public string Key3 {get; set;} + + public Request(string key1, string key2, string key3){ + Key1 = key1; + Key2 = key2; + Key3 = key3; + } + } +} diff --git a/lib/plugins/create/templates/aws-dotnet-csharp/build.sh b/lib/plugins/create/templates/aws-dotnet-csharp/build.sh new file mode 100755 index 000000000..c97689e0b --- /dev/null +++ b/lib/plugins/create/templates/aws-dotnet-csharp/build.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +#build handlers +dotnet restore +dotnet publish -c release + +#install zip +apt-get -qq update +apt-get -qq -y install zip + +#create deployment package +pushd bin/Release/netcoreapp1.0/publish +zip -r ./deploy-package.zip ./* +popd diff --git a/lib/plugins/create/templates/aws-dotnet-csharp/project.json b/lib/plugins/create/templates/aws-dotnet-csharp/project.json new file mode 100755 index 000000000..da4b806ad --- /dev/null +++ b/lib/plugins/create/templates/aws-dotnet-csharp/project.json @@ -0,0 +1,33 @@ +{ + "version": "1.0.0-*", + "buildOptions": { + "outputName": "CsharpHandlers" + }, + + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.1" + }, + + "Newtonsoft.Json": "9.0.1", + + "Amazon.Lambda.Core": "1.0.0*", + "Amazon.Lambda.Serialization.Json": "1.0.0", + + "Amazon.Lambda.Tools" : { + "type" :"build", + "version":"0.9.0-preview1" + } + }, + + "tools": { + "Amazon.Lambda.Tools" : "0.9.0-preview1" + }, + + "frameworks": { + "netcoreapp1.0": { + "imports": "dnxcore50" + } + } +} diff --git a/lib/plugins/create/templates/aws-dotnet-csharp/serverless.yml b/lib/plugins/create/templates/aws-dotnet-csharp/serverless.yml new file mode 100644 index 000000000..1d9c8320b --- /dev/null +++ b/lib/plugins/create/templates/aws-dotnet-csharp/serverless.yml @@ -0,0 +1,84 @@ +# Welcome to Serverless! +# +# This file is the main config file for your service. +# It's very minimal at this point and uses default values. +# You can always add more config options for more control. +# We've included some commented out config examples here. +# Just uncomment any of them to get that config option. +# +# For full config options, check the docs: +# docs.serverless.com +# +# Happy Coding! + +service: aws-dotnet-csharp # NOTE: update this with your service name + +# You can pin your service to only deploy with a specific Serverless version +# Check out our docs for more details +# frameworkVersion: "=X.X.X" + +provider: + name: aws + runtime: dotnetcore1.0 + +# you can overwrite defaults here +# stage: dev +# region: us-east-1 + +# you can add statements to the Lambda function's IAM Role here +# iamRoleStatements: +# - Effect: "Allow" +# Action: +# - "s3:ListBucket" +# Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ] } +# - Effect: "Allow" +# Action: +# - "s3:PutObject" +# Resource: +# Fn::Join: +# - "" +# - - "arn:aws:s3:::" +# - "Ref" : "ServerlessDeploymentBucket" + +# you can define service wide environment variables here +# environment: +# variable1: value1 + +# you can add packaging information here +package: + artifact: bin/Release/netcoreapp1.0/publish/deploy-package.zip +# exclude: +# - exclude-me.js +# - exclude-me-dir/** + +functions: + hello: + handler: CsharpHandlers::AwsDotnetCsharp.Handler::Hello + +# The following are a few example events you can configure +# NOTE: Please make sure to change your handler code to work with those events +# Check the event documentation for details +# events: +# - http: +# path: users/create +# method: get +# - s3: ${env:BUCKET} +# - schedule: rate(10 minutes) +# - sns: greeter-topic +# - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000 + +# Define function environment variables here +# environment: +# variable2: value2 + +# you can add CloudFormation resource templates here +#resources: +# Resources: +# NewResource: +# Type: AWS::S3::Bucket +# Properties: +# BucketName: my-new-bucket +# Outputs: +# NewOutput: +# Description: "Description for the output" +# Value: "Some output value" diff --git a/tests/templates/test_all_templates b/tests/templates/test_all_templates index d68c7268a..0d6e52c4d 100755 --- a/tests/templates/test_all_templates +++ b/tests/templates/test_all_templates @@ -8,6 +8,7 @@ function integration-test { $DIR/integration-test-template $@ } +integration-test aws-dotnet-csharp ./build.sh integration-test aws-java-gradle ./gradlew build integration-test aws-java-maven mvn package integration-test aws-scala-sbt sbt assembly