forked from openfaas/faas-swarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
60 lines (48 loc) · 1.7 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) Alex Ellis 2017. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/docker/docker/client"
"github.com/openfaas/faas-provider"
bootTypes "github.com/openfaas/faas-provider/types"
"github.com/openfaas/faas-swarm/handlers"
)
func main() {
var err error
dockerClient, err := client.NewEnvClient()
if err != nil {
log.Fatalf("Error with Docker client: %s.", err.Error())
}
fmt.Println(dockerClient)
dockerVersion, versionErr := dockerClient.ServerVersion(context.Background())
if versionErr != nil {
log.Fatalf("Error with Docker server: %s", versionErr.Error())
}
log.Printf("Docker API version: %s, %s\n", dockerVersion.APIVersion, dockerVersion.Version)
// How many times to reschedule a function.
maxRestarts := uint64(5)
// Delay between container restarts
restartDelay := time.Second * 5
bootstrapHandlers := bootTypes.FaaSHandlers{
FunctionProxy: handlers.FunctionProxy(true, dockerClient),
DeleteHandler: handlers.DeleteHandler(dockerClient),
DeployHandler: handlers.DeployHandler(dockerClient, maxRestarts, restartDelay),
FunctionReader: handlers.FunctionReader(true, dockerClient),
ReplicaReader: handlers.ReplicaReader(dockerClient),
ReplicaUpdater: handlers.ReplicaUpdater(dockerClient),
UpdateHandler: handlers.UpdateHandler(dockerClient, maxRestarts, restartDelay),
Health: handlers.Health(),
}
var port int
port = 8080
bootstrapConfig := bootTypes.FaaSConfig{
ReadTimeout: time.Second * 10,
WriteTimeout: time.Second * 10,
TCPPort: &port,
}
bootstrap.Serve(&bootstrapHandlers, &bootstrapConfig)
}