-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
exec.go
69 lines (61 loc) · 1.79 KB
/
exec.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
package ecspresso
import (
"context"
"fmt"
"github.com/fujiwara/ecsta"
)
type ExecOption struct {
ID string `help:"task ID" default:""`
Command string `help:"command to execute" default:"sh"`
Container string `help:"container name" default:""`
PortForward bool `help:"enable port forward" default:"false"`
LocalPort int `help:"local port number" default:"0"`
Port int `help:"remote port number (required for --port-forward)" default:"0"`
Host string `help:"remote host (required for --port-forward)" default:""`
L string `name:"L" short:"L" help:"short expression of local-port:host:port" default:""`
}
func (d *App) NewEcsta(ctx context.Context) (*ecsta.Ecsta, error) {
app, err := ecsta.New(ctx, d.config.Region, d.config.Cluster)
if err != nil {
return nil, fmt.Errorf("failed to create ecsta application: %w", err)
}
if fc := d.FilterCommand(); fc != "" {
app.Config.Set("filter_command", fc)
}
return app, nil
}
func (d *App) Exec(ctx context.Context, opt ExecOption) error {
// Do not call d.Start() because timeout disabled for exec.
ecstaApp, err := d.NewEcsta(ctx)
if err != nil {
return err
}
family, err := d.taskDefinitionFamily(ctx)
if err != nil {
return err
}
var service *string
if d.config.Service != "" {
service = &d.config.Service
}
if opt.PortForward {
return ecstaApp.RunPortforward(ctx, &ecsta.PortforwardOption{
ID: opt.ID,
Container: opt.Container,
LocalPort: opt.LocalPort,
RemotePort: opt.Port,
RemoteHost: opt.Host,
L: opt.L,
Family: &family,
Service: service,
})
} else {
return ecstaApp.RunExec(ctx, &ecsta.ExecOption{
ID: opt.ID,
Command: opt.Command,
Container: opt.Container,
Family: &family,
Service: service,
})
}
}