Skip to content

Commit

Permalink
FSharp giraffe (TechEmpower#3859)
Browse files Browse the repository at this point in the history
  • Loading branch information
dv00d00 authored and roberthusak committed Nov 6, 2018
1 parent 51b57df commit 32f2424
Show file tree
Hide file tree
Showing 9 changed files with 257 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ env:
- "TESTLANG=Dart"
- "TESTLANG=Elixir"
- "TESTLANG=Erlang"
- "TESTLANG=FSharp"
- "TESTLANG=Go"
- "TESTLANG=Groovy"
- "TESTDIR=Haskell/snap"
Expand Down
38 changes: 38 additions & 0 deletions frameworks/FSharp/giraffe/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[Oo]bj/
[Bb]in/
TestResults/
.nuget/
*.sln.ide/
_ReSharper.*/
.idea/
packages/
artifacts/
PublishProfiles/
.vs/
*.user
*.suo
*.cache
*.docstates
_ReSharper.*
nuget.exe
*net45.csproj
*net451.csproj
*k10.csproj
*.psess
*.vsp
*.pidb
*.userprefs
*DS_Store
*.ncrunchsolution
*.*sdf
*.ipch
*.swp
*~
.build/
.testPublish/
launchSettings.json
BenchmarkDotNet.Artifacts/
BDN.Generated/
binaries/
global.json
*.sln
27 changes: 27 additions & 0 deletions frameworks/FSharp/giraffe/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# girrafe Tests on Linux
This includes tests for plaintext and json serialization.

## Infrastructure Software Versions

**Language**

* F# 4.1

**Platforms**

* .NET Core (Windows and Linux)

**Web Servers**

* [Kestrel](https://github.com/aspnet/KestrelHttpServer)

**Web Stack**

* [giraffe](https://github.com/giraffe-fsharp/Giraffe)
* ASP.NET Core

## Paths & Source for Tests

* [Plaintext](src/App/Programs.fs): "/plaintext"
* [JSON serialization](src/App/Programs.fs): "/json"
* [JSON serialization via utf8json lib](src/App/Programs.fs): "/jsonutf8"
66 changes: 66 additions & 0 deletions frameworks/FSharp/giraffe/benchmark_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"framework": "giraffe",
"tests": [
{
"default": {
"plaintext_url": "/plaintext",
"json_url": "/json",
"port": 8080,
"approach": "Realistic",
"classification": "fullstack",
"database": "None",
"framework": "giraffe",
"language": "F#",
"orm": "Raw",
"platform": ".NET",
"flavor": "CoreCLR",
"webserver": "Kestrel",
"os": "Linux",
"database_os": "Linux",
"display_name": "Giraffe",
"notes": "",
"versus": "aspcore"
}
},
{
"utf8json": {
"json_url": "/json",
"port": 8080,
"approach": "Realistic",
"classification": "fullstack",
"database": "None",
"framework": "giraffe",
"language": "F#",
"orm": "Raw",
"platform": ".NET",
"flavor": "CoreCLR",
"webserver": "Kestrel",
"os": "Linux",
"database_os": "Linux",
"display_name": "Giraffe",
"notes": "",
"versus": "aspcore"
}
},
{
"utf8plaintext": {
"plaintext_url": "/plaintext",
"port": 8080,
"approach": "Realistic",
"classification": "fullstack",
"database": "None",
"framework": "giraffe",
"language": "F#",
"orm": "Raw",
"platform": ".NET",
"flavor": "CoreCLR",
"webserver": "Kestrel",
"os": "Linux",
"database_os": "Linux",
"display_name": "Giraffe",
"notes": "",
"versus": "aspcore"
}
}
]
}
12 changes: 12 additions & 0 deletions frameworks/FSharp/giraffe/giraffe-utf8json.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM microsoft/dotnet:2.1-sdk-stretch AS build
WORKDIR /app
COPY src/App .
RUN dotnet publish -c Release -o out

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS runtime
ENV ASPNETCORE_URLS http://+:8080
ENV COMPlus_ReadyToRun 0
WORKDIR /app
COPY --from=build /app/out ./

ENTRYPOINT ["dotnet", "App.dll"]
12 changes: 12 additions & 0 deletions frameworks/FSharp/giraffe/giraffe-utf8plaintext.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM microsoft/dotnet:2.1-sdk-stretch AS build
WORKDIR /app
COPY src/App .
RUN dotnet publish -c Release -o out

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS runtime
ENV ASPNETCORE_URLS http://+:8080
ENV COMPlus_ReadyToRun 0
WORKDIR /app
COPY --from=build /app/out ./

ENTRYPOINT ["dotnet", "App.dll"]
12 changes: 12 additions & 0 deletions frameworks/FSharp/giraffe/giraffe.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM microsoft/dotnet:2.1-sdk-stretch AS build
WORKDIR /app
COPY src/App .
RUN dotnet publish -c Release -o out

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS runtime
ENV ASPNETCORE_URLS http://+:8080
ENV COMPlus_ReadyToRun 0
WORKDIR /app
COPY --from=build /app/out ./

ENTRYPOINT ["dotnet", "App.dll", "stock"]
27 changes: 27 additions & 0 deletions frameworks/FSharp/giraffe/src/App/App.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<DebugType>portable</DebugType>
<AssemblyName>App</AssemblyName>
<OutputType>Exe</OutputType>
<EnableDefaultContentItems>false</EnableDefaultContentItems>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.0" />
<PackageReference Include="Giraffe" Version="1.1.0" />
<PackageReference Include="Utf8Json" Version="1.3.7" />
</ItemGroup>

<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="4.5.0" />
</ItemGroup>

</Project>
62 changes: 62 additions & 0 deletions frameworks/FSharp/giraffe/src/App/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module App.App

open Microsoft.AspNetCore.Hosting
open Giraffe

[<CLIMutable>]
type JsonMessage = { message : string }

[<CLIMutable>][<Struct>]
type JsonStructMessage = { message : string }

type Implementation = Stock | Custom

module Routes =

let stock : HttpHandler list =
[ route "/plaintext" >=> text "Hello, World!"
route "/json" >=> json { JsonMessage.message = "Hello, World!" } ]

let custom : HttpHandler list =
let inline contentLength (x:int32) = new System.Nullable<int64>( int64 x )

let json data : HttpHandler =
let bytes = Utf8Json.JsonSerializer.Serialize(data)
fun _ ctx ->
ctx.Response.ContentLength <- contentLength ( bytes.Length )
ctx.Response.ContentType <- "application/json"
ctx.Response.StatusCode <- 200
ctx.WriteBytesAsync bytes

let bytes = System.Text.Encoding.UTF8.GetBytes "Hello, World!"
let text : HttpHandler =
fun _ ctx ->
ctx.Response.ContentLength <- contentLength ( bytes.Length )
ctx.Response.ContentType <- "text/plain"
ctx.Response.StatusCode <- 200
ctx.WriteBytesAsync bytes

[ route "/plaintext" >=> text
route "/json" >=> json { JsonStructMessage.message = "Hello, World!" } ]

let webApp implementation =
match implementation with
| Stock -> GET >=> choose Routes.stock
| Custom -> GET >=> choose Routes.custom

[<EntryPoint>]
let main args =
let implementation =
match args with
| [| "stock" |] -> Stock
| _ -> Custom

printfn "Running with %A implementation" implementation

WebHostBuilder()
.UseKestrel()
.Configure(fun app -> app.UseGiraffe (webApp implementation))
.ConfigureServices(fun services -> services.AddGiraffe() |> ignore)
.Build()
.Run()
0

0 comments on commit 32f2424

Please sign in to comment.