-
Notifications
You must be signed in to change notification settings - Fork 179
/
gen1.go
83 lines (69 loc) · 1.51 KB
/
gen1.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
82
83
package start
import (
"context"
"fmt"
"path/filepath"
"strings"
"github.com/convox/rack/pkg/helpers"
"github.com/convox/rack/pkg/manifest1"
"github.com/pkg/errors"
)
type Options1 struct {
App string
Build bool
Cache bool
Command []string
Manifest string
Service string
Shift int
Sync bool
}
func (s *Start) Start1(ctx context.Context, opts Options1) error {
select {
case <-ctx.Done():
return nil
default:
}
opts.Manifest = helpers.CoalesceString(opts.Manifest, "docker-compose.yml")
if !helpers.FileExists(opts.Manifest) {
return errors.WithStack(fmt.Errorf("manifest not found: %s", opts.Manifest))
}
m, err := manifest1.LoadFile(opts.Manifest)
if err != nil {
return errors.WithStack(err)
}
errs := m.Validate()
switch len(errs) {
case 0:
case 1:
return errs[0]
default:
ss := []string{""}
for _, err := range errs {
ss = append(ss, err.Error())
}
return errors.WithStack(errors.New(strings.Join(ss, "\n")))
}
if err := m.Shift(opts.Shift); err != nil {
return errors.WithStack(err)
}
pcc, err := m.PortConflicts()
if err != nil {
return errors.WithStack(err)
}
if len(pcc) > 0 {
return errors.WithStack(fmt.Errorf("ports in use: %v", pcc))
}
r := m.Run(filepath.Dir(opts.Manifest), opts.App, manifest1.RunOptions{
Build: opts.Build,
Cache: opts.Cache,
Command: opts.Command,
Service: opts.Service,
Sync: opts.Sync,
})
defer r.Stop()
if err := r.Start(); err != nil {
return errors.WithStack(err)
}
return r.Wait(ctx)
}