/
deploy.go
65 lines (52 loc) · 1.29 KB
/
deploy.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
package teleport
import (
"context"
"fmt"
"sync"
"github.com/docker/compose/v2/pkg/progress"
"github.com/local-deploy/dl/utils/docker"
)
var pullWaitGroup sync.WaitGroup
var tsh string
// DeployTeleport Deploy using teleport
func DeployTeleport(ctx context.Context, database bool, files bool, override []string, tables []string) error {
var err error
w := progress.ContextWriter(ctx)
tsh, err = teleportBin()
if err != nil {
w.Event(progress.ErrorMessageEvent("Failed deploy", "Teleport not installed"))
return err
}
client, err := getClient()
if err != nil {
w.Event(progress.ErrorMessageEvent("Failed deploy", fmt.Sprint(err)))
return err
}
if !database && !files {
database = true
files = true
}
if files {
pullWaitGroup.Add(1)
go startFiles(ctx, client, override)
}
if database {
err = docker.UpDbContainer()
if err != nil {
w.Event(progress.ErrorMessageEvent("Import failed", fmt.Sprint(err)))
return err
}
pullWaitGroup.Add(1)
go startDump(ctx, client, tables)
}
pullWaitGroup.Wait()
return err
}
func startFiles(ctx context.Context, t *teleport, override []string) {
defer pullWaitGroup.Done()
copyFiles(ctx, t, override)
}
func startDump(ctx context.Context, t *teleport, tables []string) {
defer pullWaitGroup.Done()
dumpDB(ctx, t, tables)
}