Skip to content
Closed
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
18 changes: 18 additions & 0 deletions dotnet60/Common/BuilderSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Fission.Common
{
public readonly record struct BuilderSettings(
string NugetSpecsFile,
string DllExcludeFile,
string BuildLogDirectory,
string NugetPackageRegEx,
string ExcludeDllRegEx,
bool RunningOnWindows,
string functionBodyFileName,
string functionSpecFileName,
string DllDirectory
);
}
12 changes: 12 additions & 0 deletions dotnet60/Common/Common.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2020.3.0" />
</ItemGroup>

</Project>
112 changes: 112 additions & 0 deletions dotnet60/Common/CompilerHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Text.Json;
using System.Linq;

namespace Fission.Common
{

public sealed class CompilerHelper
{

private static readonly Lazy<CompilerHelper> lazy =
new Lazy<CompilerHelper>(() => new CompilerHelper());

public string _logFileName = string.Empty;
public static CompilerHelper Instance { get { return lazy.Value; } }

private BuilderSettings? _builderSettings = null;

public BuilderSettings builderSettings
{
get
{
if (_builderSettings == null)
{
string builderSettingsjson = GetBuilderSettingsJson();
_builderSettings = JsonSerializer.Deserialize<BuilderSettings>(builderSettingsjson);
}

return _builderSettings.Value;
}
set
{
builderSettings = value;
}
}

static CompilerHelper()
{
}

private CompilerHelper()
{
}

public static string GetRelevantPathAsPerOS(string currentPath)
{
if (CompilerHelper.Instance.builderSettings.RunningOnWindows)
{
return currentPath;
}
else
{
return currentPath.Replace("\\","/");
}
}

private string GetBuilderSettingsJson()
{
var path = AppDomain.CurrentDomain.BaseDirectory + "builderSettings.json";
return System.IO.File.ReadAllText(path);
}

public FunctionSpecification GetFunctionSpecs(string directoryPath)
{
string functionSpecsFilePath = Path.Combine(directoryPath, this.builderSettings.functionSpecFileName);
if (!File.Exists(functionSpecsFilePath))
{
string specsJson = File.ReadAllText(functionSpecsFilePath);
return JsonSerializer.Deserialize<FunctionSpecification>(specsJson);
}

throw new Exception($"Function Specification file not found at {functionSpecsFilePath}");
}

public static IEnumerable<string> GetDirectoryFiles(string rootPath, string patternMatch, SearchOption searchOption)
{
var foundFiles = Enumerable.Empty<string>();

if (searchOption == SearchOption.AllDirectories)
{
try
{
IEnumerable<string> subDirs = Directory.EnumerateDirectories(rootPath);
foreach (string dir in subDirs)
{
foundFiles = foundFiles.Concat(GetDirectoryFiles(dir, patternMatch, searchOption)); // Add files in subdirectories recursively to the list
}
}
catch (UnauthorizedAccessException) {}
catch (PathTooLongException) {}
}

try
{
foundFiles = foundFiles.Concat(Directory.EnumerateFiles(rootPath, patternMatch)); // Add files from the current directory
}
catch (UnauthorizedAccessException) {}

return foundFiles;
}

static public IEnumerable<string> GetCSharpSources(string path)
{
return GetDirectoryFiles(path, "*.cs", SearchOption.AllDirectories);
}
}

}
8 changes: 8 additions & 0 deletions dotnet60/Common/DllInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Fission.Common
{
public readonly record struct DllInfo(string name, string rootPackage, string framework, string processor, string path);
}
17 changes: 17 additions & 0 deletions dotnet60/Common/FunctionSpecification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;

namespace Fission.Common
{
public readonly record struct FunctionSpecification(
string functionName,
List<Library> libraries,
string hash,
string certificatePath
);

public readonly record struct Library(
string name,
string path,
string nugetPackage
);
}
18 changes: 18 additions & 0 deletions dotnet60/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Prep work for all images.
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 8888

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS restore
WORKDIR /src
COPY . /src
RUN dotnet restore "./fission-dotnet6.sln"

# Specific work for environment image.
FROM restore as build-env
RUN dotnet publish "./fission-dotnet6/fission-dotnet6.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=build-env /app/publish .
ENTRYPOINT ["dotnet", "fission-dotnet6.dll"]
39 changes: 39 additions & 0 deletions dotnet60/Dockerfile.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ARG BUILDER_IMAGE=fission/builder
FROM ${BUILDER_IMAGE} AS fission-builder


FROM mcr.microsoft.com/dotnet/sdk:6.0 AS builderimage


WORKDIR /app

# Copy csproj and restore as distinct layers
COPY Common ./../Common
COPY Fission.Functions ./../Fission.Functions
COPY builder/*.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY builder ./
RUN dotnet publish -c Release -o out


# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=builderimage /app/out .

# this builder is actually compilation from : https://github.com/fission/fission/tree/master/builder/cmd and renamed cmd.exe to builder
# make sure to compile it in linux only else you will get exec execute error as binary was compiled in windows and running on linux

COPY --from=fission-builder /builder /builder

#ADD builder /builder

ADD builder/build.sh /usr/local/bin/build
RUN chmod +x /usr/local/bin/build

ADD builder/build.sh /bin/build
RUN chmod +x /bin/build

EXPOSE 8001
12 changes: 12 additions & 0 deletions dotnet60/Fission.Functions/Fission.Functions.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2020.3.0" />
</ItemGroup>

</Project>
66 changes: 66 additions & 0 deletions dotnet60/Fission.Functions/FissionContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#region header

// Fission.Functions - FissionContext.cs
//
// Created by: Alistair J R Young (avatar) at 2020/12/28 11:30 PM.

#endregion

#region using

using System.Collections.Generic;
using System.IO;
using System.Text.Json;

using JetBrains.Annotations;

#endregion

namespace Fission.Functions
{
/// <summary>
/// The context supplied to Fission functions by the .NET 5 environment, including arguments, HTTP request information,
/// logging facilities, and (for built functions) settings.
/// </summary>
[PublicAPI]
public record FissionContext
{
/// <summary>
/// The arguments specified to the Fission function, derived from the HTTP request's query string.
/// </summary>
public IReadOnlyDictionary<string, string> Arguments;

/// <summary>
/// Functions permitting the Fission function to write to the container log.
/// </summary>
public FissionLogger Logger;

/// <summary>
/// The path to the location in which the Fission function package is loaded into the container.
/// </summary>
/// <remarks>
/// This is primarily used internally to fetch the location for JSON settings files.
/// </remarks>
public string PackagePath;

/// <summary>
/// Details of the HTTP request which generated the function call.
/// </summary>
public FissionRequest Request;

/// <summary>
/// Read a JSON settings file supplied in the function package, and deserialize it into a corresponding .NET object.
/// </summary>
/// <typeparam name="T">Type of the .NET object corresponding to the settings file.</typeparam>
/// <param name="relativePath">Path, beneath <see cref="PackagePath" />, of the JSON settings file.</param>
/// <returns>A .NET object corresponding to the JSON settings file.</returns>
[CanBeNull]
public T GetSettings<T> ([NotNull] string relativePath)
{
string filePath = Path.Combine (path1: this.PackagePath, path2: relativePath);
string json = File.ReadAllText (path: filePath);

return JsonSerializer.Deserialize<T> (json: json);
}
}
}
51 changes: 51 additions & 0 deletions dotnet60/Fission.Functions/FissionLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#region header

// Fission.Functions - FissionLogger.cs
//
// Created by: Alistair J R Young (avatar) at 2020/12/30 8:08 AM.

#endregion

#region using

using JetBrains.Annotations;

#endregion

namespace Fission.Functions
{
/// <summary>
/// A delegate defining a function capable of performing Fission function logging; i.e., a possible FissionLogger
/// function.
/// </summary>
/// <param name="format">The message to log, in the form of a format string for the following arguments, if any.</param>
/// <param name="args">Any arguments to log (parameters for the format string).</param>
public delegate void FissionWriteLog (string format, params object[] args);

/// <summary>
/// Logging functions for the receiving Fission function.
/// </summary>
[PublicAPI]
public record FissionLogger
{
/// <summary>
/// Log a message reporting a critical error.
/// </summary>
public FissionWriteLog WriteCritical;

/// <summary>
/// Log a message reporting an error.
/// </summary>
public FissionWriteLog WriteError;

/// <summary>
/// Log an informational message.
/// </summary>
public FissionWriteLog WriteInfo;

/// <summary>
/// Log a warning message.
/// </summary>
public FissionWriteLog WriteWarning;
}
}
Loading