From f815ab54c2f44ac9ba54a3995525d1d0c09ab5dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Seif=20Lotfy=20=D8=B3=D9=8A=D9=81=20=D9=84=D8=B7=D9=81?= =?UTF-8?q?=D9=8A?= Date: Thu, 8 Dec 2016 19:32:36 +0100 Subject: [PATCH] Add support for F# and set dotnet docket image to 1.0.1-projectjson (#409) --- examples/hash/.gitignore | 3 -- examples/hash/README.md | 6 ++++ examples/hash/{ => csharp}/func.cs | 0 examples/hash/{ => csharp}/project.json | 0 examples/hash/fsharp/func.fs | 39 +++++++++++++++++++++++++ examples/hash/fsharp/project.json | 27 +++++++++++++++++ fn/init.go | 1 + fn/langs/dotnet.go | 2 +- 8 files changed, 74 insertions(+), 4 deletions(-) delete mode 100644 examples/hash/.gitignore rename examples/hash/{ => csharp}/func.cs (100%) rename examples/hash/{ => csharp}/project.json (100%) create mode 100755 examples/hash/fsharp/func.fs create mode 100644 examples/hash/fsharp/project.json diff --git a/examples/hash/.gitignore b/examples/hash/.gitignore deleted file mode 100644 index ed730df34..000000000 --- a/examples/hash/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -dotnet.* -func.yaml -project.lock.json diff --git a/examples/hash/README.md b/examples/hash/README.md index c03d67f18..ea8cd8c41 100644 --- a/examples/hash/README.md +++ b/examples/hash/README.md @@ -18,6 +18,12 @@ fn init / This will create the ```func.yaml``` file required by functions, which can be built by running: + +## Build the function docker image +```bash +fn build +``` + ## Push to docker ```bash fn push diff --git a/examples/hash/func.cs b/examples/hash/csharp/func.cs similarity index 100% rename from examples/hash/func.cs rename to examples/hash/csharp/func.cs diff --git a/examples/hash/project.json b/examples/hash/csharp/project.json similarity index 100% rename from examples/hash/project.json rename to examples/hash/csharp/project.json diff --git a/examples/hash/fsharp/func.fs b/examples/hash/fsharp/func.fs new file mode 100755 index 000000000..0739b2c7b --- /dev/null +++ b/examples/hash/fsharp/func.fs @@ -0,0 +1,39 @@ +open System +open System.IO +open System.Security.Cryptography + +let createChecksum (data:byte array) = + use md5 = MD5.Create () + let hash = data |> md5.ComputeHash + BitConverter.ToString(hash).Replace("-", "").ToLower () + +let downloadRemoteImageFile uri = + async { + let req = System.Net.HttpWebRequest.Create (System.Uri (uri)) :?> System.Net.HttpWebRequest + let! res = req.AsyncGetResponse () + let stm = res.GetResponseStream () + use ms = new MemoryStream () + stm.CopyTo(ms) + return ms.ToArray () + } + +[] +let main argv = + let isPipedInput = + try + Console.KeyAvailable |> ignore + false + with + | _ -> true + + match isPipedInput with + | true -> + let input = stdin + async { + let! uri = input.ReadToEndAsync () |> Async.AwaitTask + return! downloadRemoteImageFile uri + } |> Async.RunSynchronously + |> createChecksum + |> printfn "%s" + | false -> () // if nothing is being piped in, then exit + 0 \ No newline at end of file diff --git a/examples/hash/fsharp/project.json b/examples/hash/fsharp/project.json new file mode 100644 index 000000000..c940314fb --- /dev/null +++ b/examples/hash/fsharp/project.json @@ -0,0 +1,27 @@ +{ + "version": "1.0.0-*", + "buildOptions": { + "debugType": "portable", + "emitEntryPoint": true, + "compilerName": "fsc", + "compile": { + "includeFiles": [ + "func.fs" + ] + } + }, + "tools": { + "dotnet-compile-fsc": "1.0.0-preview2.1-*" + }, + "frameworks": { + "netcoreapp1.1": { + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.1.0" + }, + "Microsoft.FSharp.Core.netcore": "1.0.0-alpha-160629" + } + } + } +} diff --git a/fn/init.go b/fn/init.go index 38b966a2c..e6fd64b1e 100644 --- a/fn/init.go +++ b/fn/init.go @@ -29,6 +29,7 @@ var ( ".py": "python", ".rs": "rust", ".cs": "dotnet", + ".fs": "dotnet", } fnInitRuntimes []string diff --git a/fn/langs/dotnet.go b/fn/langs/dotnet.go index d943595d5..23422892b 100644 --- a/fn/langs/dotnet.go +++ b/fn/langs/dotnet.go @@ -26,7 +26,7 @@ func (lh *DotNetLangHelper) PreBuild() error { cmd := exec.Command( "docker", "run", "--rm", "-v", - wd+":/dotnet", "-w", "/dotnet", "microsoft/dotnet", + wd+":/dotnet", "-w", "/dotnet", "microsoft/dotnet:1.0.1-sdk-projectjson", "/bin/sh", "-c", "dotnet restore && dotnet publish -c release -b /tmp -o .", ) cmd.Stderr = os.Stderr