Skip to content

.NET 8 Support #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
25649ae
Merge pull request #1 from apache/master
shawnallen85 Oct 17, 2019
ec9dee5
.NET Core 3.0 support
shawnallen85 Oct 17, 2019
05eee73
Updated .NET Core 2.2 project references
shawnallen85 Oct 18, 2019
33465be
.NET Core 2.2 quickstart update for JSON reference
shawnallen85 Oct 18, 2019
bfb6259
Removed trailing whitespace
shawnallen85 Nov 7, 2019
d7b7df5
Travis updates
shawnallen85 Nov 7, 2019
ea01fdf
Download correct dpkg for .NET Core on 16.04
shawnallen85 Nov 7, 2019
cbfac52
Scala formatting
shawnallen85 Nov 7, 2019
1a1b4cc
CHANGELOG Updates
shawnallen85 Nov 22, 2019
5f117fa
Merge pull request #2 from shawnallen85/dotnet-3.0
shawnallen85 Nov 22, 2019
d44cf05
Merge pull request #3 from apache/master
shawnallen85 Nov 22, 2019
e30899a
Merge remote-tracking branch 'upstream/master'
shawnallen85 Dec 2, 2019
0e65ffd
Merge remote-tracking branch 'upstream/master'
shawnallen85 Dec 13, 2019
a75972e
Merge remote-tracking branch 'upstream/master'
shawnallen85 Dec 27, 2019
9db63ff
Merge remote-tracking branch 'apache/master'
shawnallen85 Apr 14, 2021
f389c9e
Merge remote-tracking branch 'apache/master'
shawnallen85 Apr 19, 2021
ca3f791
Merge branch 'apache:master' into master
shawnallen85 Nov 20, 2022
ccac44d
Merge branch 'apache:master' into master
shawnallen85 Feb 14, 2023
56f561c
Merge pull request #4 from apache/master
shawnallen85 Oct 4, 2024
733ed8e
Merge branch 'apache:master' into master
shawnallen85 Oct 9, 2024
b2ef072
feature: net 8 support
shawnallen85 Oct 10, 2024
e8d64b7
feature: update settings
shawnallen85 Oct 10, 2024
3f0c019
fix: revert gradle dotnet plugin; update test build
shawnallen85 Oct 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions core/net8.0/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-->

# .NET 8.0 OpenWhisk Runtime Container

## N.NN
- Initial release
42 changes: 42 additions & 0 deletions core/net8.0/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build

WORKDIR /app
COPY proxy/Apache.OpenWhisk.Runtime.Common/*.csproj ./Apache.OpenWhisk.Runtime.Common/
COPY proxy/Apache.OpenWhisk.Runtime.Dotnet.Minimal/*.csproj ./Apache.OpenWhisk.Runtime.Dotnet.Minimal/
COPY proxy/openwhisk-runtime-dotnet.sln ./openwhisk-runtime-dotnet.sln
RUN dotnet restore

COPY proxy/Apache.OpenWhisk.Runtime.Common/. ./Apache.OpenWhisk.Runtime.Common/
COPY proxy/Apache.OpenWhisk.Runtime.Dotnet.Minimal/. ./Apache.OpenWhisk.Runtime.Dotnet.Minimal/
WORKDIR /app/Apache.OpenWhisk.Runtime.Dotnet.Minimal
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS runtime

# Get the latest security fixes in case the base image does not contain them already.
RUN apk update \
&& apk upgrade \
&& rm -f /var/cache/apk/*

WORKDIR /app
COPY --from=build /app/Apache.OpenWhisk.Runtime.Dotnet.Minimal/out ./
ENV ASPNETCORE_URLS=http://+:8080
EXPOSE 8080/tcp
ENTRYPOINT ["dotnet", "Apache.OpenWhisk.Runtime.Dotnet.Minimal.dll"]
238 changes: 238 additions & 0 deletions core/net8.0/QUICKSTART.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
<!--
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-->

# Quick .NET 8.0 Action

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

Synchronous:

```csharp
public Newtonsoft.Json.Linq.JObject Main(Newtonsoft.Json.Linq.JObject);
```

Asynchronous:

```csharp
public async System.Threading.Tasks.Task<Newtonsoft.Json.Linq.JObject> MainAsync(Newtonsoft.Json.Linq.JObject);
```

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.

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

```bash
dotnet new classlib -n Apache.OpenWhisk.Example.Dotnet -lang C# -f net8.0
cd Apache.OpenWhisk.Example.Dotnet
```

Install the [Newtonsoft.Json](https://www.newtonsoft.com/json) NuGet package as follows:

```bash
dotnet add package Newtonsoft.Json -v 13.0.3
```

Now create a file called `Hello.cs` with the following content:

Synchronous example:

```csharp
using System;
using Newtonsoft.Json.Linq;

namespace Apache.OpenWhisk.Example.Dotnet
{
public class Hello
{
public JObject Main(JObject args)
{
string name = "stranger";
if (args.ContainsKey("name")) {
name = args["name"].ToString();
}
JObject message = new JObject();
message.Add("greeting", new JValue($"Hello, {name}!"));
return (message);
}
}
}
```

Asynchronous example:

```csharp
using System;
using Newtonsoft.Json.Linq;
using System.Threading.Tasks;

namespace Apache.OpenWhisk.Example.Dotnet
{
public class Hello
{
public async Task<JObject> MainAsync(JObject args)
{
await Task.Delay(10); // Just do a delay to have an async/await process occur.
string name = "stranger";
if (args.ContainsKey("name")) {
name = args["name"].ToString();
}
JObject message = new JObject();
message.Add("greeting", new JValue($"Hello, {name}!"));
return (message);
}
}
}
```

Publish the project as follows:

```bash
dotnet publish -c Release -o out
```

Zip the published files as follows:

```bash
cd out
zip -r -0 helloDotNet.zip *
```

You need to specify the name of the function handler using `--main` argument.
The value for `main` needs to be in the following format:
`{Assembly}::{Class Full Name}::{Method}`, e.q.:

+ Synchronous: `Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::Main`
+ Asynchronous: `Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::MainAsync`

## Create the .NET Action

To use on a deployment of OpenWhisk that contains the runtime as a kind:

Synchronous:

```bash
wsk action update helloDotNet helloDotNet.zip --main Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::Main --kind dotnet:8.0
```

Asynchronous:

```bash
wsk action update helloDotNet helloDotNet.zip --main Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::MainAsync --kind dotnet:8.0
```

## Invoke the .NET Action

Action invocation is the same for .NET actions as it is for Swift and JavaScript actions:

```bash
wsk action invoke --result helloDotNet --param name World
```

```json
{
"greeting": "Hello World!"
}
```

## Local Development

```bash
./gradlew core:net8.0:distDocker
```

This will produce the image `whisk/action-dotnet-v8.0`

Build and Push image

```bash
docker login
./gradlew core:action-dotnet-v8.0:distDocker -PdockerImagePrefix=$prefix-user -PdockerRegistry=docker.io
```

Deploy OpenWhisk using ansible environment that contains the kind `dotnet:8.0`
Assuming you have OpenWhisk already deploy locally and `OPENWHISK_HOME` pointing to root directory of OpenWhisk core repository.

Set `ROOTDIR` to the root directory of this repository.

Redeploy OpenWhisk

```bash
cd $OPENWHISK_HOME/ansible
ANSIBLE_CMD="ansible-playbook -i ${ROOTDIR}/ansible/environments/local"
$ANSIBLE_CMD setup.yml
$ANSIBLE_CMD couchdb.yml
$ANSIBLE_CMD initdb.yml
$ANSIBLE_CMD wipe.yml
$ANSIBLE_CMD openwhisk.yml
```

Or you can use `wskdev` and create a soft link to the target ansible environment, for example:

```bash
ln -s ${ROOTDIR}/ansible/environments/local ${OPENWHISK_HOME}/ansible/environments/local-dotnet
wskdev fresh -t local-dotnet
```

### Testing

Install dependencies from the root directory on $OPENWHISK_HOME repository

```bash
pushd $OPENWHISK_HOME
./gradlew install
popd
```

Using gradle to run all tests

```bash
./gradlew :tests:test
```

Using gradle to run some tests

```bash
./gradlew :tests:test --tests Net8_0ActionContainerTests
```

Using IntelliJ:

- Import project as gradle project.
- Make sure working directory is root of the project/repo

#### Using Container Image To Test

To use as docker action push to your own dockerhub account

```bash
docker tag whisk/action-dotnet-v8.0 $user_prefix/action-dotnet-v8.0
docker push $user_prefix/action-dotnet-v8.0
```

Then create the action using your the image from dockerhub

```bash
wsk action update helloDotNet helloDotNet.zip --main Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::Main --docker $user_prefix/action-dotnet-v8.0
```

The `$user_prefix` is usually your dockerhub user id.

# License

[Apache 2.0](../../LICENSE.txt)
20 changes: 20 additions & 0 deletions core/net8.0/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

ext.dockerImageName = 'action-dotnet-v8.0'

apply from: '../../gradle/docker.gradle'
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!--
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.3</Version>
</PackageReference>
</ItemGroup>

</Project>
Loading