This repository has been archived by the owner on Feb 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
server.go
81 lines (69 loc) · 2.19 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
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, Ken Fukuyama 2017. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package main
import (
"fmt"
"net"
"net/http"
"os"
"time"
bootstrap "github.com/alexellis/faas-provider"
bootTypes "github.com/alexellis/faas-provider/types"
"github.com/openfaas-incubator/faas-rancher/handlers"
"github.com/openfaas-incubator/faas-rancher/rancher"
)
const (
// TimeoutSeconds used for http client
TimeoutSeconds = 2
)
func main() {
functionStackName := os.Getenv("FUNCTION_STACK_NAME")
cattleURL := os.Getenv("CATTLE_URL")
cattleAccessKey := os.Getenv("CATTLE_ACCESS_KEY")
cattleSecretKey := os.Getenv("CATTLE_SECRET_KEY")
// creates the rancher client config
config, err := rancher.NewClientConfig(
functionStackName,
cattleURL,
cattleAccessKey,
cattleSecretKey)
if err != nil {
panic(err.Error())
}
// create the rancher REST client
rancherClient, err := rancher.NewClientForConfig(config)
if err != nil {
panic(err.Error())
}
fmt.Println("Created Rancher Client")
proxyClient := http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 3 * time.Second,
KeepAlive: 0,
}).DialContext,
MaxIdleConns: 1,
DisableKeepAlives: true,
IdleConnTimeout: 120 * time.Millisecond,
ExpectContinueTimeout: 1500 * time.Millisecond,
},
}
bootstrapHandlers := bootTypes.FaaSHandlers{
FunctionProxy: handlers.MakeProxy(&proxyClient, config.FunctionsStackName).ServeHTTP,
DeleteHandler: handlers.MakeDeleteHandler(rancherClient).ServeHTTP,
DeployHandler: handlers.MakeDeployHandler(rancherClient).ServeHTTP,
FunctionReader: handlers.MakeFunctionReader(rancherClient).ServeHTTP,
ReplicaReader: handlers.MakeReplicaReader(rancherClient).ServeHTTP,
ReplicaUpdater: handlers.MakeReplicaUpdater(rancherClient).ServeHTTP,
}
// Todo: AE - parse port and parse timeout from env-vars
var port int
port = 8080
bootstrapConfig := bootTypes.FaaSConfig{
ReadTimeout: time.Second * 8,
WriteTimeout: time.Second * 8,
TCPPort: &port,
}
bootstrap.Serve(&bootstrapHandlers, &bootstrapConfig)
}