-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
75 lines (63 loc) · 1.9 KB
/
config.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
package main
import (
"encoding/json"
"io/ioutil"
"os"
"time"
)
type PoolConfig struct {
Image string `json:"image"`
Capacity int `json:"capacity"`
Standby int `json:"standby"`
}
type Config struct {
Listen string `json:"listen"`
DockerHost string `json:"docker_host"`
LanguagesPath string `json:"languages_path"`
SharedPath string `json:"shared_path"`
RunDuration time.Duration `json:"run_duration"`
ThrottleQuota int `json:"throttle_quota"`
ThrottleConcurrency int `json:"throttle_concurrency"`
ThrottleWhitelist []string `json:"throttle_whitelist"`
NetworkDisabled bool `json:"network_disabled"`
MemoryLimit int64 `json:"memory_limit"`
Pools []PoolConfig `json:"pools"`
ApiToken string `json:"api_token"`
FetchImages bool `json:"fetch_images"`
Namespaces bool `json:"namespaces"`
}
func NewConfig() *Config {
cfg := Config{
DockerHost: os.Getenv("DOCKER_HOST"),
SharedPath: os.Getenv("SHARED_PATH"),
}
cfg.Listen = "127.0.0.1:5000"
cfg.SharedPath = expandPath(cfg.SharedPath)
cfg.RunDuration = time.Second * 10
cfg.ThrottleQuota = 5
cfg.ThrottleConcurrency = 1
cfg.ThrottleWhitelist = []string{}
cfg.NetworkDisabled = false
cfg.MemoryLimit = 67108864
cfg.Pools = []PoolConfig{}
cfg.FetchImages = false
cfg.Namespaces = false
cfg.LanguagesPath = "./languages.json"
return &cfg
}
func NewConfigFromFile(path string) (*Config, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
config := Config{}
err = json.Unmarshal(data, &config)
if err == nil {
config.SharedPath = expandPath(config.SharedPath)
config.RunDuration = config.RunDuration * time.Second
if config.Listen == "" {
config.Listen = "127.0.0.1:5000"
}
}
return &config, err
}