mirror of
https://github.com/openfaas/faas.git
synced 2025-06-21 22:33:23 +00:00
Create your own functionk working.
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
<md-dialog aria-label="List dialog" layout="column" flex="80">
|
<md-dialog aria-label="List dialog" layout="column" flex="70">
|
||||||
<md-dialog-content class="md-padding">
|
<md-dialog-content class="md-padding">
|
||||||
<label>Define a function:</label>
|
<label>Define a function:</label>
|
||||||
<form name="userForm">
|
<form name="userForm">
|
||||||
@ -10,14 +10,14 @@
|
|||||||
</div>
|
</div>
|
||||||
<div layout-gt-xs="row">
|
<div layout-gt-xs="row">
|
||||||
<md-input-container class="md-block" flex-gt-sm>
|
<md-input-container class="md-block" flex-gt-sm>
|
||||||
<label>Name:</label>
|
<label>Service name:</label>
|
||||||
<input name="serviceName" ng-model="item.name" required md-maxlength="200" minlength="4">
|
<input name="serviceName" ng-model="item.service" required md-maxlength="200" minlength="4">
|
||||||
</md-input-container>
|
</md-input-container>
|
||||||
</div>
|
</div>
|
||||||
<div layout-gt-xs="row">
|
<div layout-gt-xs="row">
|
||||||
<md-input-container class="md-block" flex-gt-sm>
|
<md-input-container class="md-block" flex-gt-sm>
|
||||||
<label>fProcess:</label>
|
<label>fProcess:</label>
|
||||||
<input name="fprocess" ng-model="item.fprocess" required md-maxlength="200" minlength="4">
|
<input name="envProcess" ng-model="item.envProcess" required md-maxlength="200" minlength="1">
|
||||||
</md-input-container>
|
</md-input-container>
|
||||||
</div>
|
</div>
|
||||||
<div layout-gt-xs="row">
|
<div layout-gt-xs="row">
|
||||||
|
7
gateway/assets/script/bootstrap.js
vendored
7
gateway/assets/script/bootstrap.js
vendored
@ -10,9 +10,14 @@ app.controller("home", ['$scope', '$log', '$http', '$location', '$timeout', '$md
|
|||||||
$scope.invocation = {
|
$scope.invocation = {
|
||||||
contentType: "text"
|
contentType: "text"
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.functionTemplate = {
|
$scope.functionTemplate = {
|
||||||
image: ""
|
image: "",
|
||||||
|
envProcess: "",
|
||||||
|
network: "",
|
||||||
|
service: ""
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.invocation.request = ""
|
$scope.invocation.request = ""
|
||||||
setInterval(function() {
|
setInterval(function() {
|
||||||
refreshData();
|
refreshData();
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -12,6 +13,7 @@ import (
|
|||||||
"github.com/alexellis/faas/gateway/requests"
|
"github.com/alexellis/faas/gateway/requests"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
io_prometheus_client "github.com/prometheus/client_model/go"
|
io_prometheus_client "github.com/prometheus/client_model/go"
|
||||||
)
|
)
|
||||||
@ -78,5 +80,40 @@ func MakeNewFunctionHandler(metricsOptions metrics.MetricOptions, c *client.Clie
|
|||||||
|
|
||||||
fmt.Println(request)
|
fmt.Println(request)
|
||||||
w.WriteHeader(http.StatusNotImplemented)
|
w.WriteHeader(http.StatusNotImplemented)
|
||||||
|
options := types.ServiceCreateOptions{}
|
||||||
|
spec := makeSpec(&request)
|
||||||
|
|
||||||
|
response, err := c.ServiceCreate(context.Background(), spec, options)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
log.Println(response.ID, response.Warnings)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makeSpec(request *requests.CreateFunctionRequest) swarm.ServiceSpec {
|
||||||
|
max := uint64(1)
|
||||||
|
|
||||||
|
nets := []swarm.NetworkAttachmentConfig{
|
||||||
|
swarm.NetworkAttachmentConfig{Target: request.Network},
|
||||||
|
}
|
||||||
|
|
||||||
|
spec := swarm.ServiceSpec{
|
||||||
|
TaskTemplate: swarm.TaskSpec{
|
||||||
|
RestartPolicy: &swarm.RestartPolicy{
|
||||||
|
MaxAttempts: &max,
|
||||||
|
Condition: swarm.RestartPolicyConditionNone,
|
||||||
|
},
|
||||||
|
ContainerSpec: swarm.ContainerSpec{
|
||||||
|
Image: request.Image,
|
||||||
|
Env: []string{fmt.Sprintf("fprocess=%s", request.EnvProcess)},
|
||||||
|
Labels: map[string]string{"function": "true"},
|
||||||
|
},
|
||||||
|
Networks: nets,
|
||||||
|
},
|
||||||
|
Annotations: swarm.Annotations{
|
||||||
|
Name: request.Service,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return spec
|
||||||
|
}
|
||||||
|
@ -3,9 +3,9 @@ package requests
|
|||||||
// CreateFunctionRequest create a function in the swarm.
|
// CreateFunctionRequest create a function in the swarm.
|
||||||
type CreateFunctionRequest struct {
|
type CreateFunctionRequest struct {
|
||||||
Service string `json:"service"`
|
Service string `json:"service"`
|
||||||
FProcess string `json:"fprocess"`
|
|
||||||
Image string `json:"image"`
|
Image string `json:"image"`
|
||||||
Network string `json:"network"`
|
Network string `json:"network"`
|
||||||
|
EnvProcess string `json:"envProcess"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AlexaSessionApplication struct {
|
type AlexaSessionApplication struct {
|
||||||
|
Reference in New Issue
Block a user