-
Notifications
You must be signed in to change notification settings - Fork 3
/
gensvc.go
58 lines (48 loc) · 1001 Bytes
/
gensvc.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
package main
import (
"os"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"
"github.com/natesales/openreactor/pkg/service"
)
type Build struct {
Context string
Args []string
}
type Container struct {
Image string
Build Build
Devices []string
Ports []string
}
func main() {
svc, err := service.ParseFile()
if err != nil {
log.Fatal(err)
}
outFile, err := os.Create("docker-compose.svc.yml")
if err != nil {
log.Fatal(err)
}
var cfg struct {
Services map[string]Container `yaml:"services"`
}
cfg.Services = make(map[string]Container)
i := 0
for name, port := range svc.Ports {
cfg.Services[name] = Container{
Image: "openreactor-" + name,
Build: Build{
Context: ".",
Args: []string{"SVC=" + name},
},
Devices: []string{port + ":/serial"},
// Ports: []string{fmt.Sprintf("%d:80", 8080+i)},
}
log.Infof("Added service %s", name)
i++
}
if err := yaml.NewEncoder(outFile).Encode(cfg); err != nil {
log.Fatal(err)
}
}