Skip to content

Commit fb8a77b

Browse files
Ticket #8: Publish template + add documentation
1 parent 89c1de5 commit fb8a77b

23 files changed

+579
-4
lines changed

.dockerignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
**/.classpath
2+
**/.dockerignore
3+
**/.env
4+
**/.git
5+
**/.gitignore
6+
**/.project
7+
**/.settings
8+
**/.toolstarget
9+
**/.vs
10+
**/.vscode
11+
**/*.*proj.user
12+
**/*.dbmdl
13+
**/*.jfm
14+
**/azds.yaml
15+
**/bin
16+
**/charts
17+
**/docker-compose*
18+
**/Dockerfile*
19+
**/node_modules
20+
**/npm-debug.log
21+
**/obj
22+
**/secrets.dev.yaml
23+
**/values.dev.yaml
24+
LICENSE
25+
README.md

FaasNet.sln

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FaasNet.Gateway.Core", "src
2323
EndProject
2424
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FaasNet.Gateway.Startup", "src\FaasNet.Gateway.Startup\FaasNet.Gateway.Startup.csproj", "{24686604-17C3-4BBB-9B05-7668073546E2}"
2525
EndProject
26-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FaasNet.CLI", "src\FaasNet.CLI\FaasNet.CLI.csproj", "{EDDFD04B-B4F0-47A6-8FD3-628F3F542402}"
26+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FaasNet.CLI", "src\FaasNet.CLI\FaasNet.CLI.csproj", "{EDDFD04B-B4F0-47A6-8FD3-628F3F542402}"
2727
EndProject
28-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FaasNet.Common", "src\FaasNet.Common\FaasNet.Common.csproj", "{8B02C02D-EF1A-4F48-A69D-DC8592D966B9}"
28+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FaasNet.Common", "src\FaasNet.Common\FaasNet.Common.csproj", "{8B02C02D-EF1A-4F48-A69D-DC8592D966B9}"
29+
EndProject
30+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "04. Templates", "04. Templates", "{8C14A385-0FC5-4517-B570-05FF7039CEA3}"
31+
EndProject
32+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FaasNet.Templates", "src\FaasNet.Templates\FaasNet.Templates.csproj", "{6738B4F6-C01A-42D0-B205-7A9DACB4FD52}"
2933
EndProject
3034
Global
3135
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -69,6 +73,10 @@ Global
6973
{8B02C02D-EF1A-4F48-A69D-DC8592D966B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
7074
{8B02C02D-EF1A-4F48-A69D-DC8592D966B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
7175
{8B02C02D-EF1A-4F48-A69D-DC8592D966B9}.Release|Any CPU.Build.0 = Release|Any CPU
76+
{6738B4F6-C01A-42D0-B205-7A9DACB4FD52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
77+
{6738B4F6-C01A-42D0-B205-7A9DACB4FD52}.Debug|Any CPU.Build.0 = Debug|Any CPU
78+
{6738B4F6-C01A-42D0-B205-7A9DACB4FD52}.Release|Any CPU.ActiveCfg = Release|Any CPU
79+
{6738B4F6-C01A-42D0-B205-7A9DACB4FD52}.Release|Any CPU.Build.0 = Release|Any CPU
7280
EndGlobalSection
7381
GlobalSection(SolutionProperties) = preSolution
7482
HideSolutionNode = FALSE
@@ -83,6 +91,7 @@ Global
8391
{24686604-17C3-4BBB-9B05-7668073546E2} = {B0C38F6D-3F83-458A-A493-428AB3DD9F85}
8492
{EDDFD04B-B4F0-47A6-8FD3-628F3F542402} = {B0C38F6D-3F83-458A-A493-428AB3DD9F85}
8593
{8B02C02D-EF1A-4F48-A69D-DC8592D966B9} = {1064A767-7322-4A14-BFD4-97FDD40E76B4}
94+
{6738B4F6-C01A-42D0-B205-7A9DACB4FD52} = {8C14A385-0FC5-4517-B570-05FF7039CEA3}
8695
EndGlobalSection
8796
GlobalSection(ExtensibilityGlobals) = postSolution
8897
SolutionGuid = {46764455-0D10-4266-9C37-35D7BD67517C}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ For project documentation, please visit [docs](https://simpleidserver.github.io/
1717
| | | | |
1818
| --------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1919
| `FaasNet.Runtime` | [![MyGet (dev)](https://img.shields.io/myget/advance-ict/v/FaasNet.Runtime.svg)](https://www.myget.org/feed/advance-ict/package/nuget/FaasNet.Runtime) | [![NuGet](https://img.shields.io/nuget/v/FaasNet.Runtime.svg)](https://nuget.org/packages/FaasNet.Runtime) | [![NuGet](https://img.shields.io/nuget/dt/FaasNet.Runtime.svg)](https://nuget.org/packages/FaasNet.Runtime) |
20+
| `FaasNet.Templates` | [![MyGet (dev)](https://img.shields.io/myget/advance-ict/v/FaasNet.Templates.svg)](https://www.myget.org/feed/advance-ict/package/nuget/FaasNet.Templates) | [![NuGet](https://img.shields.io/nuget/v/FaasNet.Templates.svg)](https://nuget.org/packages/FaasNet.Templates) | [![NuGet](https://img.shields.io/nuget/dt/FaasNet.Templates.svg)](https://nuget.org/packages/FaasNet.Templates) |

default.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ task publishHelmAndWebsite {
7171

7272
task pack -depends release, compile {
7373
exec { dotnet pack $source_dir\FaasNet.Runtime\FaasNet.Runtime.csproj -c $config --no-build $versionSuffix --output $result_dir }
74+
exec { dotnet pack $source_dir\FaasNet.Templates\FaasNet.Templates.csproj -c $config --no-build $versionSuffix --output $result_dir }
7475
}
7576

7677
task test {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Create a function
2+
3+
Install FaasNet template
4+
5+
```
6+
dotnet new --install FaasNet.Templates
7+
```
8+
9+
Create a Function project
10+
11+
```
12+
mkdir QuickStart
13+
cd QuickStart
14+
15+
mkdir src
16+
cd src
17+
18+
dotnet new faasnetfn -n Function
19+
```
20+
21+
The following files will be created :
22+
23+
* *Startup.cs* and *Program.cs*: the application entry point.
24+
* *HelloWorldConfiguration.cs*: configuration of the function.
25+
* *FunctionHandler.cs*: logic of the function.
26+
27+
In case the Visual Studio Support is needed, a solution can be created :
28+
29+
```
30+
cd ..
31+
dotnet new sln -n QuickStart
32+
```
33+
34+
Add the Function project into the solution :
35+
36+
```
37+
dotnet sln add ./src/Function/Function.csproj
38+
```
39+
40+
# Deploy a function
41+
42+
Create the docker file. Replace the `DIRECTORY` variable by the project directory.
43+
44+
```
45+
FaasNet.CLI function -df <DIRECTORY>
46+
```
47+
48+
Build the docker image. Replace the `DIRECTORY` variable by the project directory, replace the `NAME` variable by the name of your image.
49+
50+
```
51+
FaasNet.CLI function -db <DIRECTORY> -t <NAME>
52+
```
53+
54+
Push the docker image into the Hub. Replace the `NAME` variable by the name of your image.
55+
56+
```
57+
FaasNet.CLI function -dp <NAME>
58+
```

docs/documentation/toc.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
- name: Getting Started
2-
href: gettingstarted/index.md
2+
href: gettingstarted/index.md
3+
- name: Functions
4+
items:
5+
- name: Create and deploy a function
6+
href: functions/create.md
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using FaasNet.CLI.Helpers;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Diagnostics;
5+
using System.IO;
6+
using System.Linq;
7+
8+
namespace FaasNet.CLI.Commands
9+
{
10+
public class FunctionBuildDockerFileCommand : IMenuItemCommand
11+
{
12+
public string Command => "-db";
13+
public string Description => "Build docker file";
14+
15+
public void Execute(IEnumerable<string> args)
16+
{
17+
if (!args.Any())
18+
{
19+
Console.WriteLine("A directory must be specified");
20+
return;
21+
}
22+
23+
if (!DockerHelper.CheckDockerExists())
24+
{
25+
Console.WriteLine("Docker is not installed");
26+
return;
27+
}
28+
29+
var directory = args.First();
30+
var dockerFileTargetPath = GetDockerFilePath(directory);
31+
if (string.IsNullOrWhiteSpace(dockerFileTargetPath))
32+
{
33+
return;
34+
}
35+
36+
BuildDocker(dockerFileTargetPath, directory, args);
37+
}
38+
39+
protected static string GetDockerFilePath(string directory)
40+
{
41+
if (!Directory.Exists(directory))
42+
{
43+
Console.WriteLine($"The Directory '{directory}' doesn't exist");
44+
return null;
45+
}
46+
47+
var dockerFileTargetPath = DockerHelper.GetDockefilePath(directory);
48+
if (!File.Exists(dockerFileTargetPath))
49+
{
50+
Console.WriteLine($"There is no Dockerfile in the directory '{dockerFileTargetPath}'");
51+
return null;
52+
}
53+
54+
return dockerFileTargetPath;
55+
}
56+
57+
protected static void BuildDocker(string dockerFileTargetPath, string directory, IEnumerable<string> args)
58+
{
59+
args = args.Skip(1);
60+
string addArgs = args.Any() ? string.Join(" ", args) : string.Empty;
61+
using (var p = new Process())
62+
{
63+
p.StartInfo.FileName = "docker";
64+
p.StartInfo.Arguments = $"build -f {dockerFileTargetPath} {addArgs} {directory}";
65+
p.StartInfo.UseShellExecute = false;
66+
p.StartInfo.CreateNoWindow = true;
67+
p.StartInfo.RedirectStandardOutput = true;
68+
p.Start();
69+
while (!p.StandardOutput.EndOfStream)
70+
{
71+
var line = p.StandardOutput.ReadLine();
72+
Console.WriteLine(line);
73+
}
74+
75+
p.WaitForExit();
76+
}
77+
}
78+
}
79+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using FaasNet.CLI.Helpers;
2+
using System.Collections.Generic;
3+
4+
namespace FaasNet.CLI.Commands
5+
{
6+
public class FunctionCommand : IMenuItemCommand
7+
{
8+
private List<IMenuItemCommand> _commands = new List<IMenuItemCommand>
9+
{
10+
new FunctionCreateDockerFileCommand(),
11+
new FunctionBuildDockerFileCommand(),
12+
new FunctionPublishDockerFileCommand()
13+
};
14+
15+
public string Command => "function";
16+
public string Description => "Manage a function";
17+
18+
public void Execute(IEnumerable<string> args)
19+
{
20+
MenuHelper.Execute(args, _commands);
21+
}
22+
}
23+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using FaasNet.CLI.Helpers;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
7+
namespace FaasNet.CLI.Commands
8+
{
9+
public class FunctionCreateDockerFileCommand : IMenuItemCommand
10+
{
11+
public string Command => "-df";
12+
public string Description => "Create a docker file for the function";
13+
14+
public void Execute(IEnumerable<string> args)
15+
{
16+
if (!args.Any())
17+
{
18+
Console.WriteLine("A directory must be specified");
19+
return;
20+
}
21+
22+
var projectName = GetProjectName(args.First());
23+
if (string.IsNullOrWhiteSpace(projectName))
24+
{
25+
return;
26+
}
27+
28+
var dockerFileContent = GetDockerFile(projectName);
29+
if (string.IsNullOrWhiteSpace(dockerFileContent))
30+
{
31+
return;
32+
}
33+
34+
WriteDockerFile(args.First(), dockerFileContent);
35+
}
36+
37+
protected static string GetProjectName(string directory)
38+
{
39+
if (!DockerHelper.CheckDockerExists())
40+
{
41+
Console.WriteLine("Docker is not installed");
42+
return null;
43+
}
44+
45+
var projectName = ExtractProjectName(directory);
46+
if (string.IsNullOrWhiteSpace(projectName))
47+
{
48+
return null;
49+
}
50+
51+
return projectName;
52+
}
53+
54+
protected static string ExtractProjectName(string directory)
55+
{
56+
if (!Directory.Exists(directory))
57+
{
58+
Console.WriteLine($"The Directory '{directory}' doesn't exist");
59+
return null;
60+
}
61+
62+
var files = Directory.GetFiles(directory, "*.csproj");
63+
if (!files.Any())
64+
{
65+
Console.WriteLine($"The Directory '{directory}' doesn't contain .csproj");
66+
return null;
67+
}
68+
69+
if (files.Count() > 1)
70+
{
71+
Console.WriteLine($"The Directory '{directory}' contains more than one .csproj");
72+
return null;
73+
}
74+
75+
return Path.GetFileName(files.First()).Replace(".csproj", string.Empty);
76+
}
77+
78+
protected static string GetDockerFile(string projectName)
79+
{
80+
var dockerFilePath = Path.Combine(Directory.GetCurrentDirectory(), "Files", "Dockerfile.txt");
81+
if(!File.Exists(dockerFilePath))
82+
{
83+
Console.WriteLine("The Dockerfile doesn't exist");
84+
return null;
85+
}
86+
87+
var txt = File.ReadAllText(dockerFilePath);
88+
return txt.Replace("{{ProjectName}}", projectName);
89+
}
90+
91+
protected static void WriteDockerFile(string directory, string content)
92+
{
93+
var dockerFileTargetPath = DockerHelper.GetDockefilePath(directory);
94+
if (File.Exists(dockerFileTargetPath))
95+
{
96+
File.Delete(dockerFileTargetPath);
97+
}
98+
99+
File.WriteAllText(dockerFileTargetPath, content);
100+
Console.WriteLine($"The dockerfile has been written into '{dockerFileTargetPath}'");
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)