Skip to content

Commit f9bb405

Browse files
authored
feat: add .NET 8 runtime and builder (#425)
* feat: add .NET 8 runtime and builder * feat: add env related items for dotnet 8 * fix: update README * feat: add tests and changes to .gitignore
1 parent e3bb394 commit f9bb405

File tree

81 files changed

+3677
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+3677
-0
lines changed

.github/workflows/environment.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,24 @@ jobs:
267267
with:
268268
command: run
269269
profile: tensorflow-serving
270+
dotnet8:
271+
runs-on: ubuntu-latest
272+
needs: check
273+
if: contains(needs.check.outputs.packages, 'dotnet8')
274+
steps:
275+
- name: Checkout sources
276+
uses: actions/checkout@v4
277+
- name: Setup Fission Environment
278+
uses: ./.github/actions/setup-cluster
279+
- name: Fission and Test images
280+
run: |
281+
SKAFFOLD_PROFILE=dotnet8 make skaffold-run
282+
make dotnet8-test-images
283+
make router-port-forward
284+
- name: dotnet8-tests
285+
run: ./test_utils/run_test.sh ./dotnet8/tests/test_dotnet8_env.sh
286+
- name: Collect Fission Dump
287+
uses: ./.github/actions/collect-fission-dump
288+
if: ${{ failure() }}
289+
with:
290+
workflow-name: dotnet8

.github/workflows/filters/filters.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ dotnet:
88
- 'dotnet/**'
99
dotnet20:
1010
- 'dotnet20/**'
11+
dotnet8:
12+
- 'dotnet8/**'
1113
go:
1214
- 'go/**'
1315
jvm:

.github/workflows/filters/version_filter.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ dotnet:
88
- 'dotnet/envconfig.json'
99
dotnet20:
1010
- 'dotnet20/envconfig.json'
11+
dotnet8:
12+
- 'dotnet8/envconfig.json'
1113
go:
1214
- 'go/envconfig.json'
1315
jvm:

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ FISSION_ENVS := nodejs-envs \
2626
binary-envs \
2727
tensorflow-serving-envs \
2828
dotnet20-envs \
29+
dotnet8-envs \
2930
ruby-envs
3031

3132
all: $(FISSION_ENVS)
@@ -91,5 +92,9 @@ python-fastapi-test-images:
9192
@kind load docker-image python-fastapi-env
9293
@kind load docker-image python-fastapi-builder
9394

95+
dotnet8-test-images:
96+
@kind load docker-image dotnet8-env
97+
@kind load docker-image dotnet8-builder
98+
9499
router-port-forward:
95100
@kubectl port-forward svc/router 8888:80 -nfission &

dotnet8/.gitignore

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Build results
2+
[Dd]ebug/
3+
[Dd]ebugPublic/
4+
[Rr]elease/
5+
[Rr]eleases/
6+
x64/
7+
x86/
8+
[Ww][Ii][Nn]32/
9+
[Aa][Rr][Mm]/
10+
[Aa][Rr][Mm]64/
11+
bld/
12+
[Bb]in/
13+
[Oo]bj/
14+
[Ll]og/
15+
[Ll]ogs/
16+
17+
# Visual Studio cache/options directory
18+
.vs/
19+
20+
# .NET Core
21+
project.lock.json
22+
project.fragment.lock.json
23+
artifacts/
24+
25+
# Files built by Visual Studio
26+
*.user
27+
*.userosscache
28+
*.sln.docstates
29+
30+
# Build results
31+
*.dll
32+
*.exe
33+
*.pdb
34+
*.cache
35+
*.log
36+
37+
# NuGet Packages
38+
*.nupkg
39+
*.snupkg
40+
# The packages folder can be ignored because of Package Restore
41+
**/[Pp]ackages/*
42+
# except build/, which is used as an MSBuild target.
43+
!**/[Pp]ackages/build/
44+
# Uncomment if necessary however generally it will be regenerated when needed
45+
#!**/[Pp]ackages/repositories.config
46+
# NuGet v3's project.json files produces more ignorable files
47+
*.nuget.props
48+
*.nuget.targets
49+
50+
# Visual Studio cache files
51+
# files ending in .cache can be ignored
52+
*.[Cc]ache
53+
# but keep track of directories ending in .cache
54+
!?*.[Cc]ache/
55+
56+
# Example ZIP files (for testing)
57+
examples/**/*.zip
58+
59+
# macOS
60+
.DS_Store

dotnet8/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Use the .NET 8 SDK image for runtime (needed for compilation support)
2+
FROM mcr.microsoft.com/dotnet/sdk:8.0
3+
4+
# Install required tools
5+
RUN apt-get update && apt-get install -y unzip curl && rm -rf /var/lib/apt/lists/*
6+
7+
# Set working directory
8+
WORKDIR /app
9+
10+
# Copy the Fission .NET runtime application
11+
COPY Fission.DotNet/ /app/Fission.DotNet/
12+
COPY Fission.DotNet.Common/ /app/Fission.DotNet.Common/
13+
14+
# Build the runtime application
15+
RUN dotnet restore Fission.DotNet/Fission.DotNet.csproj
16+
RUN dotnet publish Fission.DotNet/Fission.DotNet.csproj -c Release -o /app/publish
17+
18+
# Build and copy Fission.DotNet.Common.dll to /app for runtime compilation
19+
RUN dotnet build Fission.DotNet.Common/Fission.DotNet.Common.csproj -c Release -o /app/
20+
21+
# Create function directory
22+
RUN mkdir -p /function
23+
24+
# Set environment variables
25+
ENV ASPNETCORE_URLS=http://*:8888
26+
ENV ASPNETCORE_ENVIRONMENT=Production
27+
28+
# Expose port
29+
EXPOSE 8888
30+
31+
# Start the runtime
32+
CMD ["dotnet", "/app/publish/Fission.DotNet.dll"]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<PropertyGroup>
10+
<PackageId>Fission.DotNet.Common</PackageId>
11+
<Version>1.1.0</Version>
12+
<Authors>Lorenzo Caldon</Authors>
13+
<Description>Fission dotnet environment common package</Description>
14+
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
15+
<RepositoryUrl>https://github.com/lcsoft77/fission-env-dotnet8</RepositoryUrl>
16+
<PackageOutputPath>./nupkg</PackageOutputPath>
17+
</PropertyGroup>
18+
19+
<PropertyGroup>
20+
<PackageReadmeFile>README.md</PackageReadmeFile>
21+
</PropertyGroup>
22+
23+
<ItemGroup>
24+
<None Include="README.md" Pack="true" PackagePath="\"/>
25+
</ItemGroup>
26+
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.5.2.0
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fission.DotNet.Common", "Fission.DotNet.Common.csproj", "{66CA3524-4798-6315-18DF-47CD0B936395}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{66CA3524-4798-6315-18DF-47CD0B936395}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{66CA3524-4798-6315-18DF-47CD0B936395}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{66CA3524-4798-6315-18DF-47CD0B936395}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{66CA3524-4798-6315-18DF-47CD0B936395}.Release|Any CPU.Build.0 = Release|Any CPU
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
GlobalSection(ExtensibilityGlobals) = postSolution
22+
SolutionGuid = {AF6A70F1-84DB-4983-A581-08BC54DF98A5}
23+
EndGlobalSection
24+
EndGlobal
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Text;
5+
using System.Text.Json;
6+
using System.Threading.Tasks;
7+
8+
namespace Fission.DotNet.Common;
9+
10+
public class FissionContext
11+
{
12+
protected Stream _content;
13+
protected Dictionary<string, object> _arguments;
14+
protected Dictionary<string, string> _headers;
15+
protected Dictionary<string, string> _parameters;
16+
17+
public FissionContext(Stream body, Dictionary<string, object> arguments, Dictionary<string, string> headers, Dictionary<string, string> parameters)
18+
{
19+
if (body == null) throw new ArgumentNullException(nameof(body));
20+
if (arguments == null) throw new ArgumentNullException(nameof(arguments));
21+
if (headers == null) throw new ArgumentNullException(nameof(headers));
22+
if (parameters == null) throw new ArgumentNullException(nameof(parameters));
23+
24+
_content = body;
25+
_arguments = arguments;
26+
_headers = headers;
27+
_parameters = parameters;
28+
}
29+
30+
protected string GetHeaderValue(string key, string defaultValue = null)
31+
{
32+
return _headers.ContainsKey(key) ? _headers[key] : defaultValue;
33+
}
34+
35+
public Dictionary<string, object> Arguments => _arguments;
36+
public Dictionary<string, string> Parameters => _parameters;
37+
38+
public string TraceID => GetHeaderValue("traceparent", Guid.NewGuid().ToString());
39+
public string FunctionName => GetHeaderValue("X-Fission-Function-Name");
40+
public string Namespace => GetHeaderValue("X-Fission-Function-Namespace");
41+
public string ResourceVersion => GetHeaderValue("X-Fission-Function-Resourceversion");
42+
public string UID => GetHeaderValue("X-Fission-Function-Uid");
43+
public string Trigger => GetHeaderValue("Source-Name");
44+
public string ContentType => GetHeaderValue("Content-Type");
45+
public Int32 ContentLength => GetHeaderValue("Content-Length") != null ? Int32.Parse(GetHeaderValue("Content-Length")) : 0;
46+
public Stream Content => _content;
47+
48+
public async Task<string?> ContentAsString()
49+
{
50+
if (_content == null)
51+
{
52+
return null;
53+
}
54+
55+
_content.Position = 0;
56+
using (StreamReader reader = new StreamReader(_content, Encoding.UTF8, leaveOpen: true))
57+
{
58+
return await reader.ReadToEndAsync();
59+
}
60+
}
61+
62+
public async Task<T> ContentAs<T>(JsonSerializerOptions? options = null)
63+
{
64+
if (_content == null)
65+
{
66+
return default;
67+
}
68+
69+
_content.Position = 0;
70+
using (StreamReader reader = new StreamReader(_content, Encoding.UTF8, leaveOpen: true))
71+
{
72+
string content = await reader.ReadToEndAsync();
73+
return JsonSerializer.Deserialize<T>(content, options);
74+
}
75+
}
76+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Text;
5+
using System.Text.Json;
6+
7+
namespace Fission.DotNet.Common;
8+
9+
public class FissionHttpContext : FissionContext
10+
{
11+
private string _method;
12+
13+
public FissionHttpContext(Stream body, string method, Dictionary<string, object> arguments, Dictionary<string, string> headers, Dictionary<string, string> parameters) : base(body, arguments, headers, parameters)
14+
{
15+
_method = method;
16+
}
17+
18+
public Dictionary<string, string> Headers => _headers;
19+
public string Url
20+
{
21+
get
22+
{
23+
var urlHeader = GetHeaderValue("X-Fission-Full-Url");
24+
25+
if (urlHeader != null)
26+
{
27+
if (urlHeader.Contains("?"))
28+
{
29+
urlHeader = urlHeader.Substring(0, urlHeader.IndexOf("?"));
30+
}
31+
32+
return urlHeader;
33+
}
34+
else
35+
{
36+
return "/";
37+
}
38+
}
39+
}
40+
public string Method => _method;
41+
public string Host => GetHeaderValue("X-Forwarded-Host");
42+
public int Port => _headers.ContainsKey("X-Forwarded-Port") ? Int32.Parse(GetHeaderValue("X-Forwarded-Port")) : 0;
43+
public string UserAgent => GetHeaderValue("User-Agent");
44+
}

0 commit comments

Comments
 (0)