mirror of
https://github.com/openfaas/faas.git
synced 2025-06-16 04:06:47 +00:00
Create your own functionk working.
This commit is contained in:
parent
98c9ef67f4
commit
fe1e9fc52e
@ -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">
|
||||
<label>Define a function:</label>
|
||||
<form name="userForm">
|
||||
@ -10,14 +10,14 @@
|
||||
</div>
|
||||
<div layout-gt-xs="row">
|
||||
<md-input-container class="md-block" flex-gt-sm>
|
||||
<label>Name:</label>
|
||||
<input name="serviceName" ng-model="item.name" required md-maxlength="200" minlength="4">
|
||||
<label>Service name:</label>
|
||||
<input name="serviceName" ng-model="item.service" required md-maxlength="200" minlength="4">
|
||||
</md-input-container>
|
||||
</div>
|
||||
<div layout-gt-xs="row">
|
||||
<md-input-container class="md-block" flex-gt-sm>
|
||||
<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>
|
||||
</div>
|
||||
<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 = {
|
||||
contentType: "text"
|
||||
};
|
||||
|
||||
$scope.functionTemplate = {
|
||||
image: ""
|
||||
image: "",
|
||||
envProcess: "",
|
||||
network: "",
|
||||
service: ""
|
||||
};
|
||||
|
||||
$scope.invocation.request = ""
|
||||
setInterval(function() {
|
||||
refreshData();
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"io/ioutil"
|
||||
@ -12,6 +13,7 @@ import (
|
||||
"github.com/alexellis/faas/gateway/requests"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/client"
|
||||
io_prometheus_client "github.com/prometheus/client_model/go"
|
||||
)
|
||||
@ -78,5 +80,40 @@ func MakeNewFunctionHandler(metricsOptions metrics.MetricOptions, c *client.Clie
|
||||
|
||||
fmt.Println(request)
|
||||
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
|
||||
}
|
||||
|
@ -2,10 +2,10 @@ package requests
|
||||
|
||||
// CreateFunctionRequest create a function in the swarm.
|
||||
type CreateFunctionRequest struct {
|
||||
Service string `json:"service"`
|
||||
FProcess string `json:"fprocess"`
|
||||
Image string `json:"image"`
|
||||
Network string `json:"network"`
|
||||
Service string `json:"service"`
|
||||
Image string `json:"image"`
|
||||
Network string `json:"network"`
|
||||
EnvProcess string `json:"envProcess"`
|
||||
}
|
||||
|
||||
type AlexaSessionApplication struct {
|
||||
|
Loading…
x
Reference in New Issue
Block a user