-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
appspec.go
57 lines (50 loc) · 1.39 KB
/
appspec.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
package ecspresso
import (
"context"
"fmt"
"strings"
"github.com/kayac/ecspresso/v2/appspec"
)
type AppSpecOption struct {
TaskDefinition string `help:"use task definition arn in AppSpec (latest, current or Arn)" default:"latest"`
UpdateService bool `help:"update service definition with task definition arn" default:"true" negatable:""`
}
func (d *App) AppSpec(ctx context.Context, opt AppSpecOption) error {
ctx, cancel := d.Start(ctx)
defer cancel()
var taskDefinitionArn string
sv, err := d.DescribeService(ctx)
if err != nil {
return err
}
switch opt.TaskDefinition {
case "current":
taskDefinitionArn = *sv.TaskDefinition
case "latest":
family := strings.Split(arnToName(*sv.TaskDefinition), ":")[0]
taskDefinitionArn, err = d.findLatestTaskDefinitionArn(ctx, family)
if err != nil {
return err
}
default:
if !strings.HasPrefix(opt.TaskDefinition, "arn:aws:ecs:") {
return fmt.Errorf("--task-definition requires current, latest or a valid task definition arn")
}
}
if opt.UpdateService {
newSv, err := d.LoadServiceDefinition(d.config.ServiceDefinitionPath)
if err != nil {
return err
}
sv = newSv
}
spec, err := appspec.NewWithService(&sv.Service, taskDefinitionArn)
if err != nil {
return fmt.Errorf("failed to create appspec: %w", err)
}
if d.config.AppSpec != nil {
spec.Hooks = d.config.AppSpec.Hooks
}
fmt.Print(spec.String())
return nil
}