-
Notifications
You must be signed in to change notification settings - Fork 0
/
starter.go
53 lines (38 loc) · 984 Bytes
/
starter.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
package starter
import (
"context"
"fmt"
"os"
"path"
tc "github.com/testcontainers/testcontainers-go/modules/compose"
"github.com/g41797/sputnik/sidecar"
)
func StartServices() (stopServices func(), err error) {
confFolder, err := sidecar.ConfFolder()
if err != nil {
return nil, err
}
composePath := path.Join(confFolder, "docker-compose.yml")
return StartServicesWithCompose(composePath)
}
func StartServicesWithCompose(composePath string) (stopServices func(), err error) {
_, err = os.ReadFile(composePath)
if err != nil {
fmt.Println("docker-compose.yml does not exist. Please start required services manually")
stopServices = func() {
return
}
return stopServices, nil
}
dc, err := tc.NewDockerCompose(composePath)
if err != nil {
return nil, err
}
dc.Up(context.Background(), tc.Wait(true))
services := dc.Services()
fmt.Println(services)
stopServices = func() {
dc.Down(context.Background())
}
return stopServices, nil
}