Skip to content

Commit 417445e

Browse files
Ticket #9 : Deploy & execute a function
1 parent fb8a77b commit 417445e

Some content is hidden

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

46 files changed

+1148
-25
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<VersionPrefix>0.0.1</VersionPrefix>
3+
<VersionPrefix>0.0.2</VersionPrefix>
44
<Authors>SimpleIdServer</Authors>
55
<Owners>SimpleIdServer</Owners>
66
</PropertyGroup>

default.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,28 @@ task publishHelmAndWebsite {
6969
exec { git checkout master }
7070
}
7171

72+
task buildLocalDockerImage -depends publish {
73+
exec { docker build -f RuntimeGetSqlDockerfile -t localhost:5000/faasgetsql . }
74+
exec { docker build -f RuntimeGetSqlDockerfile -t localhost:5000/faastransform . }
75+
exec { docker build -f KubernetesDockerfile -t localhost:5000/faaskubernetes . }
76+
exec { docker build -f GatewayDockerfile -t localhost:5000/faasgateway . }
77+
exec { docker push localhost:5000/faasgetsql }
78+
exec { docker push localhost:5000/faastransform }
79+
exec { docker push localhost:5000/faaskubernetes }
80+
exec { docker push localhost:5000/faasgateway }
81+
}
82+
83+
task initLocalKubernetes {
84+
exec { kubectl apply -f ./kubernetes/faas-namespace.yml }
85+
exec { kubectl apply -f ./kubernetes/run-mssql.yml --namespace=faas }
86+
exec { kubectl apply -f ./kubernetes/mssql-external-svc.yml --namespace=faas }
87+
exec { kubectl apply -f ./kubernetes/mssql-internal-svc.yml --namespace=faas }
88+
exec { kubectl apply -f ./kubernetes/run-faas-kubernetes.yml --namespace=faas }
89+
exec { kubectl apply -f ./kubernetes/faas-kubernetes-svc.yml --namespace=faas }
90+
exec { kubectl apply -f ./kubernetes/run-faas-gateway.yml --namespace=faas }
91+
exec { kubectl apply -f ./kubernetes/faas-gateway-svc.yml --namespace=faas }
92+
}
93+
7294
task pack -depends release, compile {
7395
exec { dotnet pack $source_dir\FaasNet.Runtime\FaasNet.Runtime.csproj -c $config --no-build $versionSuffix --output $result_dir }
7496
exec { dotnet pack $source_dir\FaasNet.Templates\FaasNet.Templates.csproj -c $config --no-build $versionSuffix --output $result_dir }

docs/documentation/functions/create.md

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Create a function
22

3-
Install FaasNet template
3+
Install FaasNet template. This utility can be used to generate Function project in C#.
44

55
```
66
dotnet new --install FaasNet.Templates
@@ -21,8 +21,11 @@ dotnet new faasnetfn -n Function
2121
The following files will be created :
2222

2323
* *Startup.cs* and *Program.cs*: the application entry point.
24-
* *HelloWorldConfiguration.cs*: configuration of the function.
25-
* *FunctionHandler.cs*: logic of the function.
24+
* *HelloWorldConfiguration.cs*: configuration properties of the function.
25+
* *FunctionHandler.cs*: contains the business logic. This class has one function which accepts one parameter and returns a JSON result. The input parameter has two distinct properties :
26+
27+
* Configuration: its value is coming from the gateway, it will be used to configure the behavior of the function for example : `ConnectionString` and `SQL Statement`.
28+
* Input: value passed by caller.
2629

2730
In case the Visual Studio Support is needed, a solution can be created :
2831

@@ -31,28 +34,61 @@ cd ..
3134
dotnet new sln -n QuickStart
3235
```
3336

34-
Add the Function project into the solution :
37+
Add the Function project into the solution.
3538

3639
```
3740
dotnet sln add ./src/Function/Function.csproj
3841
```
3942

4043
# Deploy a function
4144

42-
Create the docker file. Replace the `DIRECTORY` variable by the project directory.
45+
> [!WARNING]
46+
> Before you start, Make sure your working environment is properly configured.
47+
48+
When the Function project is ready, it can be deployed to the Gateway API.
49+
50+
First of all, open a command prompt and execute the following command line to create a Docker file. The `DIRECTORY` variable must be replaced by the directory of the Function.csproj project.
4351

4452
```
4553
FaasNet.CLI function -df <DIRECTORY>
4654
```
4755

48-
Build the docker image. Replace the `DIRECTORY` variable by the project directory, replace the `NAME` variable by the name of your image.
56+
Execute the following instruction to locally build the Docker image.
57+
The `DIRECTORY` variable must be replaced by the directory of the Function.csproj project, and the `IMAGENAME` variable must be replaced by the name of the Docker image for example : localhost:5000/function.
58+
59+
```
60+
FaasNet.CLI function -db <DIRECTORY> -t <IMAGENAME>
61+
```
62+
63+
Execute the following command line to push the local Docker image into a registry. The `IMAGENAME` variable must be replaced by the name of the Docker Image.
64+
65+
```
66+
FaasNet.CLI function -dp <IMAGENAME>
67+
```
68+
69+
Finally, execute the latest command line to deploy the function into the Gateway API. Replace the `FUNCTIONNAME` variable by the name of your function and replace the `IMAGENAME` variable by the name of your Docker image.
70+
71+
```
72+
FaasNet.CLI function deploy -name <FUNCTIONAME> -image <IMAGENAME>
73+
```
74+
75+
# Execute a function
76+
77+
> [!WARNING]
78+
> Before you start, Make sure you have a function deployed in the Gateway API.
79+
80+
Execute the following command to invoke a function. Replace the `FUNCTIONNAME` variable by the name of your function.
4981

5082
```
51-
FaasNet.CLI function -db <DIRECTORY> -t <NAME>
83+
FaasNet.CLI function invoke <FUNCTIONNAME> -input {} -configuration {'firstName':'coucou'}
5284
```
5385

54-
Push the docker image into the Hub. Replace the `NAME` variable by the name of your image.
86+
The following message is displayed
5587

5688
```
57-
FaasNet.CLI function -dp <NAME>
89+
{
90+
"content": {
91+
"message": "Hello 'coucou'"
92+
}
93+
}
5894
```

kubernetes/run-faas-gateway.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ spec:
1414
spec:
1515
containers:
1616
- name: faas-gateway
17-
image: localhost:5000/gateway
17+
image: localhost:5000/faasgateway
1818
ports:
1919
- containerPort: 8080

kubernetes/run-faas-kubernetes.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ spec:
1414
spec:
1515
containers:
1616
- name: faas-kubernetes
17-
image: localhost:5000/kubernetes
17+
image: localhost:5000/faaskubernetes
1818
ports:
1919
- containerPort: 8080
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using FaasNet.CLI.Helpers;
2+
using System.Collections.Generic;
3+
4+
namespace FaasNet.CLI.Commands
5+
{
6+
public class ConfigurationCommand : IMenuItemCommand
7+
{
8+
private List<IMenuItemCommand> _commands = new List<IMenuItemCommand>
9+
{
10+
new ConfigurationUpdateCommand(),
11+
new ConfigurationGetCommand()
12+
};
13+
14+
public string Command => "configuration";
15+
public string Description => "Manage configuration";
16+
17+
public void Execute(IEnumerable<string> args)
18+
{
19+
MenuHelper.Execute(args, _commands);
20+
}
21+
}
22+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using FaasNet.CLI.Helpers;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
6+
namespace FaasNet.CLI.Commands
7+
{
8+
public class ConfigurationGetCommand : IMenuItemCommand
9+
{
10+
public string Command => "-get";
11+
public string Description => "Get the configuration";
12+
13+
public void Execute(IEnumerable<string> args)
14+
{
15+
if (!args.Any())
16+
{
17+
Console.WriteLine("A Property with its value must be specified");
18+
return;
19+
}
20+
21+
var configuration = ConfigurationHelper.GetConfiguration();
22+
if (configuration == null)
23+
{
24+
Console.WriteLine($"The configuration file '{ConfigurationHelper.ConfigurationFileName}' doesn't exist");
25+
return;
26+
}
27+
28+
var key = args.First();
29+
if (!ConfigurationHelper.HasKey(key))
30+
{
31+
Console.WriteLine($"The key '{key}' cannot be configured");
32+
return;
33+
}
34+
35+
if(key == ConfigurationHelper.GatewayKey)
36+
{
37+
Console.WriteLine($"{key}={configuration.Provider.Gateway}");
38+
}
39+
}
40+
}
41+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using FaasNet.CLI.Helpers;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
6+
namespace FaasNet.CLI.Commands
7+
{
8+
public class ConfigurationUpdateCommand : IMenuItemCommand
9+
{
10+
public string Command => "-set";
11+
public string Description => "Update the configuration";
12+
13+
public void Execute(IEnumerable<string> args)
14+
{
15+
if (!args.Any())
16+
{
17+
Console.WriteLine("A Property with its value must be specified");
18+
return;
19+
}
20+
21+
var splitted = args.First().Split('=');
22+
if (splitted.Count() != 2)
23+
{
24+
Console.WriteLine("The argument is not correct, it must respect the format Key=Value");
25+
return;
26+
}
27+
28+
var configuration = ConfigurationHelper.GetConfiguration();
29+
if (configuration == null)
30+
{
31+
Console.WriteLine($"The configuration file '{ConfigurationHelper.ConfigurationFileName}' doesn't exist");
32+
return;
33+
}
34+
35+
var key = splitted.First();
36+
var value = splitted.Last();
37+
if (!ConfigurationHelper.HasKey(key))
38+
{
39+
Console.WriteLine($"The key '{key}' cannot be configured");
40+
return;
41+
}
42+
43+
if (key == ConfigurationHelper.GatewayKey)
44+
{
45+
configuration.Provider.Gateway = value;
46+
}
47+
48+
ConfigurationHelper.UpdateConfiguration(configuration);
49+
}
50+
}
51+
}

src/FaasNet.CLI/Commands/FunctionCommand.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ public class FunctionCommand : IMenuItemCommand
99
{
1010
new FunctionCreateDockerFileCommand(),
1111
new FunctionBuildDockerFileCommand(),
12-
new FunctionPublishDockerFileCommand()
12+
new FunctionPublishDockerFileCommand(),
13+
new FunctionDeployCommand(),
14+
new FunctionRemoveCommand(),
15+
new FunctionInvokeCommand(),
16+
new FunctionConfigurationCommand()
1317
};
1418

1519
public string Command => "function";
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using FaasNet.CLI.Helpers;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
6+
namespace FaasNet.CLI.Commands
7+
{
8+
public class FunctionConfigurationCommand : IMenuItemCommand
9+
{
10+
public string Command => "configuration";
11+
public string Description => "Invoke a function";
12+
13+
public void Execute(IEnumerable<string> args)
14+
{
15+
if (!args.Any())
16+
{
17+
Console.WriteLine("The name must be specified");
18+
return;
19+
}
20+
21+
var configuration = ConfigurationHelper.GetConfiguration();
22+
if (configuration == null)
23+
{
24+
Console.WriteLine($"The configuration file '{ConfigurationHelper.ConfigurationFileName}' doesn't exist");
25+
return;
26+
}
27+
28+
var name = args.First();
29+
var gatewayClient = new GatewayClient();
30+
var jObj = gatewayClient.GetConfiguration(configuration.Provider.Gateway, name);
31+
Console.WriteLine(jObj.ToString());
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)