Browse Source

Update zebra and giraffe to use dotnet core 3 (#4997)

* Update zebra and giraffe to use dotnet core 3

* Remove obsole env variable

* Simplify fsproj

* Use anonymouse json message types

* Use System.Text.Json

* Set language version to F# 4.6

* Use async serialization
Steffen Forkmann 6 years ago
parent
commit
b76731132d

+ 1 - 1
frameworks/FSharp/giraffe/README.md

@@ -5,7 +5,7 @@ This includes tests for plaintext and json serialization.
 
 **Language**
 
-* F# 4.1
+* F# 4.6
 
 **Platforms**
 

+ 2 - 3
frameworks/FSharp/giraffe/giraffe-stripped.dockerfile

@@ -1,11 +1,10 @@
-FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
+FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build
 WORKDIR /app
 COPY src/App .
 RUN dotnet publish -c Release -o out
 
-FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime
+FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 AS runtime
 ENV ASPNETCORE_URLS http://+:8080
-ENV COMPlus_ReadyToRun 0
 WORKDIR /app
 COPY --from=build /app/out ./
 

+ 2 - 3
frameworks/FSharp/giraffe/giraffe-utf8direct.dockerfile

@@ -1,11 +1,10 @@
-FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
+FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build
 WORKDIR /app
 COPY src/App .
 RUN dotnet publish -c Release -o out
 
-FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime
+FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 AS runtime
 ENV ASPNETCORE_URLS http://+:8080
-ENV COMPlus_ReadyToRun 0
 WORKDIR /app
 COPY --from=build /app/out ./
 

+ 2 - 3
frameworks/FSharp/giraffe/giraffe-utf8json.dockerfile

@@ -1,11 +1,10 @@
-FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
+FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build
 WORKDIR /app
 COPY src/App .
 RUN dotnet publish -c Release -o out
 
-FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime
+FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 AS runtime
 ENV ASPNETCORE_URLS http://+:8080
-ENV COMPlus_ReadyToRun 0
 WORKDIR /app
 COPY --from=build /app/out ./
 

+ 2 - 3
frameworks/FSharp/giraffe/giraffe.dockerfile

@@ -1,11 +1,10 @@
-FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
+FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build
 WORKDIR /app
 COPY src/App .
 RUN dotnet publish -c Release -o out
 
-FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime
+FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 AS runtime
 ENV ASPNETCORE_URLS http://+:8080
-ENV COMPlus_ReadyToRun 0
 WORKDIR /app
 COPY --from=build /app/out ./
 

+ 7 - 13
frameworks/FSharp/giraffe/src/App/App.fsproj

@@ -1,7 +1,8 @@
 <Project Sdk="Microsoft.NET.Sdk.Web">
 
   <PropertyGroup>
-    <TargetFramework>netcoreapp2.2</TargetFramework>
+    <TargetFramework>netcoreapp3.0</TargetFramework>
+    <LangVersion>preview</LangVersion>
     <DebugType>portable</DebugType>
     <AssemblyName>App</AssemblyName>
     <OutputType>Exe</OutputType>
@@ -9,13 +10,10 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="Dapper" Version="1.50.5" />
-    <PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.0" />
-    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" />
-    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
-    <PackageReference Include="Giraffe" Version="3.5.0" />
-    <PackageReference Include="Npgsql" Version="4.0.4" />
-    <PackageReference Include="Utf8Json" Version="1.3.7" />
+    <PackageReference Include="Dapper" Version="1.60.6" />
+    <PackageReference Include="Giraffe" Version="3.6.0" />
+    <PackageReference Include="Npgsql" Version="4.0.9" />
+    <PackageReference Update="FSharp.Core" Version="4.7" />
   </ItemGroup>
 
   <ItemGroup>
@@ -27,8 +25,4 @@
     <Compile Include="Program.fs" />
   </ItemGroup>
 
-  <ItemGroup>
-    <PackageReference Update="FSharp.Core" Version="4.5.2" />
-  </ItemGroup>
-
-</Project> 
+</Project>

+ 4 - 4
frameworks/FSharp/giraffe/src/App/Custom.fs

@@ -11,6 +11,7 @@ open System.IO
 
 let private DefaultCapacity = 1386
 let private MaxBuilderSize = DefaultCapacity * 3
+let private BufferSize = 27
 
 type MemoryStreamCache = 
     
@@ -43,13 +44,12 @@ let application : HttpHandler =
     let inline contentLength x = new Nullable<int64> ( int64 x )
 
     let json' data : HttpHandler =
-        let bytes = Utf8Json.JsonSerializer.Serialize(data)
         fun _ ctx -> 
-            ctx.Response.ContentLength <- contentLength bytes.Length
+            ctx.Response.ContentLength <- contentLength BufferSize
             ctx.Response.ContentType <- "application/json"
             ctx.Response.StatusCode <- 200
             task {
-                do! ctx.Response.Body.WriteAsync(bytes, 0, bytes.Length)
+                do! System.Text.Json.JsonSerializer.SerializeAsync(ctx.Response.Body, data)
                 return Some ctx
             }
 
@@ -108,7 +108,7 @@ let application : HttpHandler =
 
     routes' [
         "/plaintext", text' "Hello, World!"
-        "/json", json' { JsonStructMessage.message = "Hello, World!" }
+        "/json", json' struct {| message = "Hello, World!" |}
         "/fortunes", fortunes'
     ]
 

+ 0 - 5
frameworks/FSharp/giraffe/src/App/Models.fs

@@ -3,11 +3,6 @@
 open System.Collections.Generic
 open System
 
-type JsonMessage = { message : string }
-
-[<Struct>]
-type JsonStructMessage = { message : string }
-
  [<CLIMutable>]
 type Fortune = { id: int; message: string }
 

+ 1 - 1
frameworks/FSharp/giraffe/src/App/Stock.fs

@@ -34,6 +34,6 @@ let application : HttpHandler =
 
     choose [
         route "/plaintext" >=> text "Hello, World!" 
-        route "/json" >=> json { JsonMessage.message = "Hello, World!" }
+        route "/json" >=> json {| message = "Hello, World!" |}
         route "/fortunes" >=> fortunes
     ]

+ 1 - 1
frameworks/FSharp/zebra/README.md

@@ -7,7 +7,7 @@ Zebra is a new F# functional Asp.net Framework Wrapper that utalises a shared st
 
 **Language**
 
-* F# 4.1
+* F# 4.6
 
 **Platforms**
 

+ 5 - 11
frameworks/FSharp/zebra/src/App/App.fsproj

@@ -1,7 +1,8 @@
 <Project Sdk="Microsoft.NET.Sdk.Web">
 
   <PropertyGroup>
-    <TargetFramework>netcoreapp2.1</TargetFramework>
+    <TargetFramework>netcoreapp3.0</TargetFramework>
+    <LangVersion>preview</LangVersion>
     <DebugType>portable</DebugType>
     <AssemblyName>App</AssemblyName>
     <OutputType>Exe</OutputType>
@@ -9,13 +10,10 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="Microsoft.Extensions.Primitives" Version="2.2.0" />
-    <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.0" />
-    <PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.0" />
-    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" />
-    <PackageReference Include="Dapper" Version="1.50.5" />
-    <PackageReference Include="Npgsql" Version="4.0.4" />
+    <PackageReference Include="Dapper" Version="1.60.6" />
+    <PackageReference Include="Npgsql" Version="4.0.9" />
     <PackageReference Include="Utf8Json" Version="1.3.7" />
+    <PackageReference Update="FSharp.Core" Version="4.7.0" />
   </ItemGroup>
 
   <ItemGroup>
@@ -32,8 +30,4 @@
     <Compile Include="Program.fs" />
   </ItemGroup>
 
-  <ItemGroup>
-    <PackageReference Update="FSharp.Core" Version="4.5.0" />
-  </ItemGroup>
-
 </Project>

+ 2 - 3
frameworks/FSharp/zebra/zebra-simple.dockerfile

@@ -1,11 +1,10 @@
-FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
+FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build
 WORKDIR /app
 COPY src/App .
 RUN dotnet publish -c Release -o out
 
-FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime
+FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 AS runtime
 ENV ASPNETCORE_URLS http://+:8080
-ENV COMPlus_ReadyToRun 0
 WORKDIR /app
 COPY --from=build /app/out ./
 

+ 2 - 3
frameworks/FSharp/zebra/zebra.dockerfile

@@ -1,11 +1,10 @@
-FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
+FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build
 WORKDIR /app
 COPY src/App .
 RUN dotnet publish -c Release -o out
 
-FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime
+FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 AS runtime
 ENV ASPNETCORE_URLS http://+:8080
-ENV COMPlus_ReadyToRun 0
 WORKDIR /app
 COPY --from=build /app/out ./