This repository has been archived by the owner on Dec 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
main.go
81 lines (64 loc) · 2.81 KB
/
main.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// 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"
"log"
"time"
"github.com/openfaas/faas-provider/logs"
"github.com/openfaas/faas-provider/proxy"
"github.com/docker/docker/client"
bootstrap "github.com/openfaas/faas-provider"
bootTypes "github.com/openfaas/faas-provider/types"
"github.com/openfaas/faas-swarm/handlers"
"github.com/openfaas/faas-swarm/types"
"github.com/openfaas/faas-swarm/version"
)
func main() {
var err error
dockerClient, err := client.NewEnvClient()
if err != nil {
log.Fatalf("Error with Docker client: %s.", err.Error())
}
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
readConfig := types.ReadConfig{}
osEnv := bootTypes.OsEnv{}
cfg, err := readConfig.Read(osEnv)
if err != nil {
log.Fatalf("Error reading config: %s", err.Error())
}
log.Printf("HTTP Read Timeout: %s\n", cfg.FaaSConfig.GetReadTimeout())
log.Printf("HTTP Write Timeout: %s\n", cfg.FaaSConfig.WriteTimeout)
funcProxyHandler := handlers.NewFunctionLookup(dockerClient, cfg.DNSRoundRobin)
bootstrapHandlers := bootTypes.FaaSHandlers{
DeleteHandler: handlers.DeleteHandler(dockerClient),
DeployHandler: handlers.DeployHandler(dockerClient, maxRestarts, restartDelay),
FunctionReader: handlers.FunctionReader(true, dockerClient),
FunctionProxy: proxy.NewHandlerFunc(cfg.FaaSConfig, funcProxyHandler),
ReplicaReader: handlers.ReplicaReader(dockerClient),
ReplicaUpdater: handlers.ReplicaUpdater(dockerClient),
UpdateHandler: handlers.UpdateHandler(dockerClient, maxRestarts, restartDelay),
HealthHandler: handlers.Health(),
InfoHandler: handlers.MakeInfoHandler(version.BuildVersion(), version.GitCommit),
SecretHandler: handlers.MakeSecretsHandler(dockerClient),
LogHandler: logs.NewLogHandlerFunc(handlers.NewLogRequester(dockerClient), cfg.FaaSConfig.WriteTimeout),
ListNamespaceHandler: handlers.NamespaceLister(),
}
bootstrapConfig := bootTypes.FaaSConfig{
ReadTimeout: cfg.FaaSConfig.GetReadTimeout(),
WriteTimeout: cfg.FaaSConfig.WriteTimeout,
TCPPort: cfg.FaaSConfig.TCPPort,
EnableBasicAuth: cfg.FaaSConfig.EnableBasicAuth,
SecretMountPath: cfg.FaaSConfig.SecretMountPath,
}
log.Printf("Basic authentication: %v\n", bootstrapConfig.EnableBasicAuth)
bootstrap.Serve(&bootstrapHandlers, &bootstrapConfig)
}