Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions .github/workflows/filters/filters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ dotnet:
- 'dotnet/**'
dotnet20:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also check code in donet20 and if we can consolidate both ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by consolidate both by looking at dotnet20 code?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think let it be, I was exploring if we can keep only one env.
But this can done later once dotnet8 is released

- 'dotnet20/**'
dotnet8:
- 'dotnet8/**'
go:
- 'go/**'
jvm:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/filters/version_filter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ dotnet:
- 'dotnet/envconfig.json'
dotnet20:
- 'dotnet20/envconfig.json'
dotnet8:
- 'dotnet8/envconfig.json'
go:
- 'go/envconfig.json'
jvm:
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ FISSION_ENVS := nodejs-envs \
binary-envs \
tensorflow-serving-envs \
dotnet20-envs \
dotnet8-envs \
ruby-envs

all: $(FISSION_ENVS)
Expand Down
32 changes: 32 additions & 0 deletions dotnet8/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Use the .NET 8 SDK image for runtime (needed for compilation support)
FROM mcr.microsoft.com/dotnet/sdk:8.0

# Install required tools
RUN apt-get update && apt-get install -y unzip curl && rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Copy the Fission .NET runtime application
COPY Fission.DotNet/ /app/Fission.DotNet/
COPY Fission.DotNet.Common/ /app/Fission.DotNet.Common/

# Build the runtime application
RUN dotnet restore Fission.DotNet/Fission.DotNet.csproj
RUN dotnet publish Fission.DotNet/Fission.DotNet.csproj -c Release -o /app/publish

# Build and copy Fission.DotNet.Common.dll to /app for runtime compilation
RUN dotnet build Fission.DotNet.Common/Fission.DotNet.Common.csproj -c Release -o /app/

# Create function directory
RUN mkdir -p /function

# Set environment variables
ENV ASPNETCORE_URLS=http://*:8888
ENV ASPNETCORE_ENVIRONMENT=Production

# Expose port
EXPOSE 8888

# Start the runtime
CMD ["dotnet", "/app/publish/Fission.DotNet.dll"]
26 changes: 26 additions & 0 deletions dotnet8/Fission.DotNet.Common/Fission.DotNet.Common.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
<PackageId>Fission.DotNet.Common</PackageId>
<Version>1.1.0</Version>
<Authors>Lorenzo Caldon</Authors>
<Description>Fission dotnet environment common package</Description>
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
<RepositoryUrl>https://github.com/lcsoft77/fission-env-dotnet8</RepositoryUrl>
<PackageOutputPath>./nupkg</PackageOutputPath>
</PropertyGroup>

<PropertyGroup>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\"/>
</ItemGroup>
</Project>
24 changes: 24 additions & 0 deletions dotnet8/Fission.DotNet.Common/Fission.DotNet.Common.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fission.DotNet.Common", "Fission.DotNet.Common.csproj", "{66CA3524-4798-6315-18DF-47CD0B936395}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{66CA3524-4798-6315-18DF-47CD0B936395}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{66CA3524-4798-6315-18DF-47CD0B936395}.Debug|Any CPU.Build.0 = Debug|Any CPU
{66CA3524-4798-6315-18DF-47CD0B936395}.Release|Any CPU.ActiveCfg = Release|Any CPU
{66CA3524-4798-6315-18DF-47CD0B936395}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AF6A70F1-84DB-4983-A581-08BC54DF98A5}
EndGlobalSection
EndGlobal
76 changes: 76 additions & 0 deletions dotnet8/Fission.DotNet.Common/FissionContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace Fission.DotNet.Common;

public class FissionContext
{
protected Stream _content;
protected Dictionary<string, object> _arguments;
protected Dictionary<string, string> _headers;
protected Dictionary<string, string> _parameters;

public FissionContext(Stream body, Dictionary<string, object> arguments, Dictionary<string, string> headers, Dictionary<string, string> parameters)
{
if (body == null) throw new ArgumentNullException(nameof(body));
if (arguments == null) throw new ArgumentNullException(nameof(arguments));
if (headers == null) throw new ArgumentNullException(nameof(headers));
if (parameters == null) throw new ArgumentNullException(nameof(parameters));

_content = body;
_arguments = arguments;
_headers = headers;
_parameters = parameters;
}

protected string GetHeaderValue(string key, string defaultValue = null)
{
return _headers.ContainsKey(key) ? _headers[key] : defaultValue;
}

public Dictionary<string, object> Arguments => _arguments;
public Dictionary<string, string> Parameters => _parameters;

public string TraceID => GetHeaderValue("traceparent", Guid.NewGuid().ToString());
public string FunctionName => GetHeaderValue("X-Fission-Function-Name");
public string Namespace => GetHeaderValue("X-Fission-Function-Namespace");
public string ResourceVersion => GetHeaderValue("X-Fission-Function-Resourceversion");
public string UID => GetHeaderValue("X-Fission-Function-Uid");
public string Trigger => GetHeaderValue("Source-Name");
public string ContentType => GetHeaderValue("Content-Type");
public Int32 ContentLength => GetHeaderValue("Content-Length") != null ? Int32.Parse(GetHeaderValue("Content-Length")) : 0;
public Stream Content => _content;

public async Task<string?> ContentAsString()
{
if (_content == null)
{
return null;
}

_content.Position = 0;
using (StreamReader reader = new StreamReader(_content, Encoding.UTF8, leaveOpen: true))
{
return await reader.ReadToEndAsync();
}
}

public async Task<T> ContentAs<T>(JsonSerializerOptions? options = null)
{
if (_content == null)
{
return default;
}

_content.Position = 0;
using (StreamReader reader = new StreamReader(_content, Encoding.UTF8, leaveOpen: true))
{
string content = await reader.ReadToEndAsync();
return JsonSerializer.Deserialize<T>(content, options);
}
}
}
44 changes: 44 additions & 0 deletions dotnet8/Fission.DotNet.Common/FissionHttpContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.Json;

namespace Fission.DotNet.Common;

public class FissionHttpContext : FissionContext
{
private string _method;

public FissionHttpContext(Stream body, string method, Dictionary<string, object> arguments, Dictionary<string, string> headers, Dictionary<string, string> parameters) : base(body, arguments, headers, parameters)
{
_method = method;
}

public Dictionary<string, string> Headers => _headers;
public string Url
{
get
{
var urlHeader = GetHeaderValue("X-Fission-Full-Url");

if (urlHeader != null)
{
if (urlHeader.Contains("?"))
{
urlHeader = urlHeader.Substring(0, urlHeader.IndexOf("?"));
}

return urlHeader;
}
else
{
return "/";
}
}
}
public string Method => _method;
public string Host => GetHeaderValue("X-Forwarded-Host");
public int Port => _headers.ContainsKey("X-Forwarded-Port") ? Int32.Parse(GetHeaderValue("X-Forwarded-Port")) : 0;
public string UserAgent => GetHeaderValue("User-Agent");
}
17 changes: 17 additions & 0 deletions dotnet8/Fission.DotNet.Common/FissionMqContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.IO;

namespace Fission.DotNet.Common;

public class FissionMqContext : FissionContext
{
public FissionMqContext(Stream body, Dictionary<string, object> arguments, Dictionary<string, string> headers, Dictionary<string, string> parameters) : base(body, arguments, headers, parameters)
{

}

public string Topic => GetHeaderValue("Topic");
public string ErrorTopic => GetHeaderValue("Errortopic");
public string ResponseTopic => GetHeaderValue("Resptopic");
}
16 changes: 16 additions & 0 deletions dotnet8/Fission.DotNet.Common/ICorsPolicy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace Fission.DotNet.Common
{
public interface ICorsPolicy
{
void AllowAnyOrigin();
void AllowAnyHeader();
void AllowAnyMethod();
void AllowCredentials();

void WithOrigin(string[] origin);
void WithHeader(string[] header);
void WithMethod(string[] method);
}
}
14 changes: 14 additions & 0 deletions dotnet8/Fission.DotNet.Common/ILogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace Fission.DotNet.Common
{
public interface ILogger
{
void LogInformation(string message);
void LogDebug(string message);
void LogWarning(string message);
void LogError(string message);
void LogCritical(string message);
void LogError(string message, Exception exception);
}
}
46 changes: 46 additions & 0 deletions dotnet8/Fission.DotNet.Common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Fission.DotNet.Common

This project is a common library for the .NET environment of [Fission](https://fission.io/), a serverless plugin for Kubernetes. The library provides common functionalities and utilities to facilitate the development of serverless functions with Fission on .NET.

## Main Features

- **Common Utilities**: Provides a set of common utilities to simplify the development of serverless functions.
- **.NET 8 Compatibility**: Designed to work with **.NET 8 on Linux**, offering an updated and improved experience.
- **Multi-Assembly Management**: Supports projects composed of multiple linked assemblies, simplifying the deployment and integration process.

## Inspiration

This project is inspired by the official Fission environment for .NET Core 2.0 but focuses on improvements and updates requested by the community, allowing developers to work with newer versions of the .NET framework and complex projects that include multiple assemblies.

## Usage

1. **Add the library to your project**:
Add the NuGet package `Fission.DotNet.Common` to your .NET project.

```bash
dotnet add package Fission.DotNet.Common

2. **Create the project**:
- Create a **class library project** in .NET.
- Add the NuGet package `Fission.DotNet.Common` to your project.
- Create a class with the following function:

```csharp
using Fission.DotNet.Common;

public class MyFunction
{
public object Execute(FissionContext input)
{
return "Hello World";
}
}
```
3. **Compression**: Compress the assemblies and related files into a ZIP file.

4. **Deploy to Fission**: Use this library to deploy your project to Fission, leveraging the ability to manage multiple linked assemblies. After compressing your project into a ZIP file, you can create the function in Fission with the following command:

```bash
fission fn create --name <function_name> --env dotnet8 --code <your_project.zip> --entrypoint <name_of_assembly_without_extension>:<namespace>:<classname>
```
Replace `<function_name>` with the name of your function and `<your_project.zip>` with the path to your ZIP file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v8.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v8.0": {
"Fission.DotNet.Common/1.1.0": {
"runtime": {
"Fission.DotNet.Common.dll": {}
}
}
}
},
"libraries": {
"Fission.DotNet.Common/1.1.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
Binary file not shown.
Binary file not shown.
Loading