-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,225 additions
and
843 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[*.go] | ||
indent_size = 4 | ||
indent_size = 2 | ||
indent_style = tab | ||
[Shakefile] | ||
indent_size = 2 | ||
indent_style = tab | ||
indent_style = tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package commands | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/apex/log" | ||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/config" | ||
"github.com/aws/aws-sdk-go-v2/service/ec2" | ||
"github.com/aws/aws-sdk-go-v2/service/ecs" | ||
elbv2 "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2" | ||
cage "github.com/loilo-inc/canarycage" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func (c *cageCommands) Recreate() *cli.Command { | ||
envars := cage.Envars{} | ||
return &cli.Command{ | ||
Name: "recreate", | ||
Usage: "recreate ECS service with specified service/task definition", | ||
Description: "recreate ECS service with specified service/task definition", | ||
ArgsUsage: "[directory path of service.json and task-definition.json (default=.)]", | ||
Flags: []cli.Flag{ | ||
RegionFlag(&envars.Region), | ||
ClusterFlag(&envars.Cluster), | ||
ServiceFlag(&envars.Service), | ||
TaskDefinitionArnFlag(&envars.TaskDefinitionArn), | ||
CanaryTaskIdleDurationFlag(&envars.CanaryTaskIdleDuration), | ||
}, | ||
Action: func(ctx *cli.Context) error { | ||
c.aggregateEnvars(ctx, &envars) | ||
|
||
if err := c.prompt.ConfirmService(&envars); err != nil { | ||
return err | ||
} | ||
var cfg aws.Config | ||
if o, err := config.LoadDefaultConfig(context.Background(), config.WithRegion(envars.Region)); err != nil { | ||
return err | ||
} else { | ||
cfg = o | ||
} | ||
cagecli := cage.NewCage(&cage.Input{ | ||
Env: &envars, | ||
ECS: ecs.NewFromConfig(cfg), | ||
EC2: ec2.NewFromConfig(cfg), | ||
ALB: elbv2.NewFromConfig(cfg), | ||
}) | ||
_, err := cagecli.Recreate(context.Background()) | ||
if err != nil { | ||
log.Error(err.Error()) | ||
} | ||
return err | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package prompt | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
cage "github.com/loilo-inc/canarycage" | ||
"golang.org/x/xerrors" | ||
) | ||
|
||
type Prompter struct { | ||
Reader *bufio.Reader | ||
} | ||
|
||
func NewPrompter(stdin io.Reader) *Prompter { | ||
return &Prompter{Reader: bufio.NewReader(stdin)} | ||
} | ||
|
||
func (s *Prompter) Confirm( | ||
name string, | ||
value string, | ||
) error { | ||
fmt.Fprintf(os.Stderr, "please confirm [%s]: ", name) | ||
if text, err := s.Reader.ReadString('\n'); err != nil { | ||
return xerrors.Errorf("failed to read from stdin: %w", err) | ||
} else if text[:len(text)-1] != value { | ||
return xerrors.Errorf("%s is not matched. expected: %s", name, value) | ||
} | ||
return nil | ||
} | ||
|
||
func (s *Prompter) ConfirmTask( | ||
envars *cage.Envars, | ||
) error { | ||
return s.confirmStackChange(envars, false) | ||
} | ||
|
||
func (s *Prompter) ConfirmService( | ||
envars *cage.Envars, | ||
) error { | ||
return s.confirmStackChange(envars, true) | ||
} | ||
|
||
func (s *Prompter) confirmStackChange( | ||
envars *cage.Envars, | ||
service bool, | ||
) error { | ||
// Skip confirmation if running in CI | ||
if envars.CI { | ||
return nil | ||
} | ||
if err := s.Confirm("region", envars.Region); err != nil { | ||
return err | ||
} | ||
if err := s.Confirm("cluster", envars.Cluster); err != nil { | ||
return err | ||
} | ||
if service { | ||
if err := s.Confirm("service", envars.Service); err != nil { | ||
return err | ||
} | ||
} | ||
fmt.Fprintf(os.Stderr, "confirm changes:\n") | ||
fmt.Fprintf(os.Stderr, "[region]: %s\n", envars.Region) | ||
fmt.Fprintf(os.Stderr, "[cluster]: %s\n", envars.Cluster) | ||
if service { | ||
fmt.Fprintf(os.Stderr, "[service]: %s\n", envars.Service) | ||
} | ||
if err := s.Confirm("yes", "yes"); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
Oops, something went wrong.