Skip to content

Commit 05f5d30

Browse files
authored
.NET 6.0 Support (#68)
* feature: initial 6.0 work * feature: vagrant for testing; fixed Dockerfile * fix: README.md * fix: Vagrantfile; Vagrant readme
1 parent 18b7f12 commit 05f5d30

30 files changed

Lines changed: 286 additions & 186 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ obj/
1616
bin/
1717
*.zip
1818

19+
.vagrant/

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#
1818
-->
1919

20-
# Apache OpenWhisk runtimes for .NET Core
20+
# Apache OpenWhisk runtimes for .NET
2121

2222
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)
2323
[![Build Status](https://travis-ci.com/apache/openwhisk-runtime-dotnet.svg?branch=master)](https://travis-ci.com/github/apache/openwhisk-runtime-dotnet)
@@ -33,7 +33,7 @@ cd Apache.OpenWhisk.Example.Dotnet
3333
Install the [Newtonsoft.Json](https://www.newtonsoft.com/json) NuGet package as follows:
3434

3535
```bash
36-
dotnet add package Newtonsoft.Json -v 12.0.1
36+
dotnet add package Newtonsoft.Json -v 13.0.1
3737
```
3838

3939
Now create a file called `Hello.cs` with the following content:
@@ -75,7 +75,7 @@ zip -r -0 helloDotNet.zip *
7575
Create the action
7676

7777
```bash
78-
wsk action update helloDotNet helloDotNet.zip --main Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::Main --kind dotnet:2.2
78+
wsk action update helloDotNet helloDotNet.zip --main Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::Main --kind dotnet:6.0
7979
```
8080

8181
For the return result, not only support `dictionary` but also support `array`
@@ -123,13 +123,13 @@ namespace Apache.OpenWhisk.Tests.Dotnet
123123

124124
## Changelogs
125125

126-
- [.NET Core 2.2 CHANGELOG.md](core/dotnet2.2/CHANGELOG.md)
127126
- [.NET Core 3.1 CHANGELOG.md](core/dotnet3.1/CHANGELOG.md)
127+
- [.NET 6.0 CHANGELOG.md](core/net6.0/CHANGELOG.md)
128128

129129
## Quick Start Guides
130130

131-
- [.NET Core 2.2](core/dotnet2.2/QUICKSTART.md)
132131
- [.NET Core 3.1](core/dotnet3.1/QUICKSTART.md)
132+
- [.NET Core 6.0](core/net6.0/QUICKSTART.md)
133133

134134
# License
135135

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,7 @@
1717
#
1818
-->
1919

20-
# .NET Core 2.2 OpenWhisk Runtime Container
20+
# .NET 6.0 OpenWhisk Runtime Container
2121

2222
## 1.16
23-
- Fix Akka version ($55)
24-
- Init json quickstart updates (#50)
25-
- Export init args to environment. (#44)
26-
27-
## 1.15
28-
Changes:
29-
- Increased MaxRequestBodySize, so larger zip files can be uploaded (#33)
30-
- Get the latest security fixes (apk upgrade) with every build.
31-
32-
## 1.14
33-
Changes:
34-
- Support for async methods. Example:
35-
36-
```csharp
37-
public async Task<JObject> MainAsync(JObject args)
38-
{
39-
await Task.Delay(10); // Just do a delay to have an async/await process occur.
40-
return (args);
41-
}
42-
```
43-
44-
## 1.13
45-
Changes:
4623
- Initial release
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# limitations under the License.
1616
#
1717

18-
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-alpine AS build
18+
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
1919

2020
WORKDIR /app
2121
COPY proxy/Apache.OpenWhisk.Runtime.Common/*.csproj ./Apache.OpenWhisk.Runtime.Common/
@@ -26,9 +26,9 @@ RUN dotnet restore
2626
COPY proxy/Apache.OpenWhisk.Runtime.Common/. ./Apache.OpenWhisk.Runtime.Common/
2727
COPY proxy/Apache.OpenWhisk.Runtime.Dotnet.Minimal/. ./Apache.OpenWhisk.Runtime.Dotnet.Minimal/
2828
WORKDIR /app/Apache.OpenWhisk.Runtime.Dotnet.Minimal
29-
RUN dotnet publish -c Release -r alpine.3.9-x64 -o out
29+
RUN dotnet publish -c Release -r linux-musl-x64 -o out
3030

31-
FROM mcr.microsoft.com/dotnet/core/runtime:2.2-alpine AS runtime
31+
FROM mcr.microsoft.com/dotnet/runtime:6.0-alpine AS runtime
3232

3333
# Get the latest security fixes in case the base image does not contain them already.
3434
RUN apk update \
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
#
1818
-->
1919

20-
# Quick .NET Core 2.2 Action
20+
# Quick .NET 6.0 Action
2121

22-
A .NET Core action is a .NET Core class library with a method called `Main` or `MainAsync` that has the exact signature as follows:
22+
A .NET action is a .NET class library with a method called `Main` or `MainAsync` that has the exact signature as follows:
2323

2424
Synchronous:
2525

@@ -33,12 +33,12 @@ Asynchronous:
3333
public async System.Threading.Tasks.Task<Newtonsoft.Json.Linq.JObject> MainAsync(Newtonsoft.Json.Linq.JObject);
3434
```
3535

36-
In order to compile, test and archive .NET Core projects, you must have the [.NET Core SDK](https://www.microsoft.com/net/download) installed locally and the environment variable `DOTNET_HOME` set to the location where the `dotnet` executable can be found.
36+
In order to compile, test and archive .NET projects, you must have the [.NET SDK](https://dotnet.microsoft.com/en-us/download) installed locally and ensure that the `dotnet` executable is included in the `PATH` environment variable.
3737

3838
For example, create a C# project called `Apache.OpenWhisk.Example.Dotnet`:
3939

4040
```bash
41-
dotnet new classlib -n Apache.OpenWhisk.Example.Dotnet -lang C# -f netstandard2.0
41+
dotnet new classlib -n Apache.OpenWhisk.Example.Dotnet -lang C# -f netstandard2.1
4242
cd Apache.OpenWhisk.Example.Dotnet
4343
```
4444

@@ -127,18 +127,18 @@ To use on a deployment of OpenWhisk that contains the runtime as a kind:
127127
Synchronous:
128128

129129
```bash
130-
wsk action update helloDotNet helloDotNet.zip --main Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::Main --kind dotnet:2.2
130+
wsk action update helloDotNet helloDotNet.zip --main Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::Main --kind dotnet:6.0
131131
```
132132

133133
Asynchronous:
134134

135135
```bash
136-
wsk action update helloDotNet helloDotNet.zip --main Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::MainAsync --kind dotnet:2.2
136+
wsk action update helloDotNet helloDotNet.zip --main Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::MainAsync --kind dotnet:6.0
137137
```
138138

139139
## Invoke the .NET Core Action
140140

141-
Action invocation is the same for .NET Core actions as it is for Swift and JavaScript actions:
141+
Action invocation is the same for .NET actions as it is for Swift and JavaScript actions:
142142

143143
```bash
144144
wsk action invoke --result helloDotNet --param name World
@@ -153,19 +153,19 @@ wsk action invoke --result helloDotNet --param name World
153153
## Local Development
154154

155155
```bash
156-
./gradlew core:dotnet2.2:distDocker
156+
./gradlew core:dotnet3.1:distDocker
157157
```
158158

159-
This will produce the image `whisk/action-dotnet-v2.2`
159+
This will produce the image `whisk/action-dotnet-v6.0`
160160

161161
Build and Push image
162162

163163
```bash
164164
docker login
165-
./gradlew core:action-dotnet-v2.2:distDocker -PdockerImagePrefix=$prefix-user -PdockerRegistry=docker.io
165+
./gradlew core:action-dotnet-v6.0:distDocker -PdockerImagePrefix=$prefix-user -PdockerRegistry=docker.io
166166
```
167167

168-
Deploy OpenWhisk using ansible environment that contains the kind `dotnet:2.2`
168+
Deploy OpenWhisk using ansible environment that contains the kind `dotnet:6.0`
169169
Assuming you have OpenWhisk already deploy locally and `OPENWHISK_HOME` pointing to root directory of OpenWhisk core repository.
170170

171171
Set `ROOTDIR` to the root directory of this repository.
@@ -208,7 +208,7 @@ Using gradle to run all tests
208208
Using gradle to run some tests
209209

210210
```bash
211-
./gradlew :tests:test --tests DotNet2_2ActionContainerTests
211+
./gradlew :tests:test --tests Net6_0ActionContainerTests
212212
```
213213

214214
Using IntelliJ:
@@ -221,14 +221,14 @@ Using IntelliJ:
221221
To use as docker action push to your own dockerhub account
222222

223223
```bash
224-
docker tag whisk/action-dotnet-v2.2 $user_prefix/action-dotnet-v2.2
225-
docker push $user_prefix/action-dotnet-v2.2
224+
docker tag whisk/action-dotnet-v6.0 $user_prefix/action-dotnet-v6.0
225+
docker push $user_prefix/action-dotnet-v6.0
226226
```
227227

228228
Then create the action using your the image from dockerhub
229229

230230
```bash
231-
wsk action update helloDotNet helloDotNet.zip --main Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::Main --docker $user_prefix/action-dotnet-v2.2
231+
wsk action update helloDotNet helloDotNet.zip --main Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::Main --docker $user_prefix/action-dotnet-v6.0
232232
```
233233

234234
The `$user_prefix` is usually your dockerhub user id.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
ext.dockerImageName = 'action-dotnet-v2.2'
18+
ext.dockerImageName = 'action-dotnet-v6.0'
1919

2020
apply from: '../../gradle/docker.gradle'

core/dotnet2.2/proxy/Apache.OpenWhisk.Runtime.Common/Apache.OpenWhisk.Runtime.Common.csproj renamed to core/net6.0/proxy/Apache.OpenWhisk.Runtime.Common/Apache.OpenWhisk.Runtime.Common.csproj

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@
1717
<Project Sdk="Microsoft.NET.Sdk">
1818

1919
<PropertyGroup>
20-
<TargetFramework>netcoreapp2.2</TargetFramework>
20+
<TargetFramework>net6.0</TargetFramework>
2121
</PropertyGroup>
2222

2323
<ItemGroup>
24-
<PackageReference Include="Microsoft.AspNetCore">
25-
<Version>2.2.0</Version>
26-
</PackageReference>
27-
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel">
28-
<Version>2.2.0</Version>
29-
</PackageReference>
24+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
25+
</ItemGroup>
26+
27+
<ItemGroup>
3028
<PackageReference Include="Newtonsoft.Json">
3129
<Version>13.0.1</Version>
3230
</PackageReference>

core/dotnet2.2/proxy/Apache.OpenWhisk.Runtime.Common/HttpResponseExtension.cs renamed to core/net6.0/proxy/Apache.OpenWhisk.Runtime.Common/HttpResponseExtension.cs

File renamed without changes.

core/dotnet2.2/proxy/Apache.OpenWhisk.Runtime.Common/Init.cs renamed to core/net6.0/proxy/Apache.OpenWhisk.Runtime.Common/Init.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using System.Reflection;
2222
using System.Threading;
2323
using System.Threading.Tasks;
24+
using System.Collections.Generic;
2425
using Microsoft.AspNetCore.Http;
2526
using Newtonsoft.Json.Linq;
2627

@@ -121,6 +122,17 @@ public async Task<Run> HandleRequest(HttpContext httpContext)
121122

122123
try
123124
{
125+
// Export init arguments as environment variables
126+
if (message["env"] != null && message["env"].HasValues)
127+
{
128+
Dictionary<string, string> dictEnv = message["env"].ToObject<Dictionary<string, string>>();
129+
foreach (KeyValuePair<string, string> entry in dictEnv) {
130+
// See https://docs.microsoft.com/en-us/dotnet/api/system.environment.setenvironmentvariable
131+
// If entry.Value is null or the empty string, the variable is not set
132+
Environment.SetEnvironmentVariable(entry.Key, entry.Value);
133+
}
134+
}
135+
124136
Assembly assembly = Assembly.LoadFrom(assemblyPath);
125137
Type = assembly.GetType(mainParts[1]);
126138
if (Type == null)

core/dotnet2.2/proxy/Apache.OpenWhisk.Runtime.Common/Run.cs renamed to core/net6.0/proxy/Apache.OpenWhisk.Runtime.Common/Run.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ await Console.Error.WriteLineAsync(
7676
$"Unable to set environment variable for the \"{token.Path}\" token.");
7777
}
7878
}
79-
}
80-
if (valObject == null) {
81-
valArray = inputObject["value"] as JArray;
79+
if (valObject == null) {
80+
valArray = inputObject["value"] as JArray;
81+
}
8282
}
8383

8484
object owObject = _constructor.Invoke(new object[] { });

0 commit comments

Comments
 (0)