Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#

sudo: required
group: deprecated-2017Q3
dist: xenial
language: scala
scala:
- 2.12.7
Expand All @@ -41,7 +41,7 @@ deploy:
all_branches: true
repo: apache/openwhisk-runtime-dotnet
- provider: script
script: "./tools/travis/publish.sh openwhisk 2.2 nightly"
script: "./tools/travis/publish.sh openwhisk 2.2 nightly && ./tools/travis/publish.sh openwhisk 3.0 nightly"
on:
branch: master
repo: apache/openwhisk-runtime-dotnet
Expand Down
154 changes: 6 additions & 148 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,157 +23,15 @@
[![Build Status](https://travis-ci.org/apache/openwhisk-runtime-dotnet.svg?branch=master)](https://travis-ci.org/apache/openwhisk-runtime-dotnet)

## Changelogs
- [.NET Core 2.2 CHANGELOG.md](core/dotnet2.2/CHANGELOG.md)


## Quick .NET Core Action
A .NET Core action is a .NET Core class library with a method called `Main` that has the exact signature as follows:

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

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.

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

```bash
dotnet new classlib -n Apache.OpenWhisk.Example.Dotnet -lang C#
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 12.0.1
```

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

```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);
}
}
}
```

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.bin *
```

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.,
`Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::Main`

### Create the .NET Core Action
To use on a deployment of OpenWhisk that contains the runtime as a kind:
```bash
wsk action update helloDotNet helloDotNet.bin --main Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::Main --kind dotnet:2.2
```

### Invoke the .NET Core Action
Action invocation is the same for .NET Core 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:dotnet2.2:distDocker
```
This will produce the image `whisk/action-dotnet-v2.2`

Build and Push image
```bash
docker login
./gradlew core:action-dotnet-v2.2:distDocker -PdockerImagePrefix=$prefix-user -PdockerRegistry=docker.io
```

Deploy OpenWhisk using ansible environment that contains the kind `dotnet:2.2`
Assuming you have OpenWhisk already deploy localy 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:
```
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
podd $OPENWHISK_HOME
```
- [.NET Core 2.2 CHANGELOG.md](core/dotnet2.2/CHANGELOG.md)
- [.NET Core 3.0 CHANGELOG.md](core/dotnet3.0/CHANGELOG.md)

Using gradle to run all tests
```bash
./gradlew :tests:test
```
Using gradle to run some tests
```bash
./gradlew :tests:test --tests *ActionContainerTests*
```
Using IntelliJ:
- Import project as gradle project.
- Make sure working directory is root of the project/repo
## Quick Start Guides

#### Using container image to test
To use as docker action push to your own dockerhub account
```bash
docker tag whisk/action-dotnet-v2.2 $user_prefix/action-dotnet-v2.2
docker push $user_prefix/action-dotnet-v2.2
```
Then create the action using your the image from dockerhub
```bash
wsk action update helloDotNet helloDotNet.bin --main Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::Main --docker $user_prefix/action-dotnet-v2.2
```
The `$user_prefix` is usually your dockerhub user id.
- [.NET Core 2.2](core/dotnet2.2/QUICKSTART.md)
- [.NET Core 3.0](core/dotnet3.0/QUICKSTART.md)

# License

[Apache 2.0](LICENSE.txt)
2 changes: 1 addition & 1 deletion core/dotnet2.2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
# .NET Core 2.2 OpenWhisk Runtime Container


## 1.13 (next Apache release)
## 1.13
Changes:
- Initial release
6 changes: 3 additions & 3 deletions core/dotnet2.2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
#

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

WORKDIR /app
COPY proxy/Apache.OpenWhisk.Runtime.Common/*.csproj ./Apache.OpenWhisk.Runtime.Common/
Expand All @@ -26,9 +26,9 @@ 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 -r alpine.3.7-x64 -o out
RUN dotnet publish -c Release -r alpine.3.9-x64 -o out

FROM microsoft/dotnet:2.2-runtime-alpine AS runtime
FROM mcr.microsoft.com/dotnet/core/runtime:2.2-alpine AS runtime
WORKDIR /app
COPY --from=build /app/Apache.OpenWhisk.Runtime.Dotnet.Minimal/out ./
ENV ASPNETCORE_URLS http://+:8080
Expand Down
Loading