Skip to content

Commit

Permalink
Merge pull request #10 from silinternational/develop
Browse files Browse the repository at this point in the history
Release 2.0.0 - Use Launch Templates instead of Launch Configurations
  • Loading branch information
briskt authored May 4, 2023
2 parents f23cc69 + 8ea12a5 commit 3a9fa1f
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 168 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ available or not. When `--force-replacement` is enabled the process is _not_ ide
## Instance Replacement Process

1. Look up latest AMI based on either the given AMI filter, or the default: `amzn2-ami-ecs-hvm-*-x86_64-ebs`
2. Identify the ASG for the given ECS cluster to get current launch configuration and instances list
3. Compare latest AMI with AMI in use by launch configuration
2. Identify the ASG for the given ECS cluster to get current launch template and instances list
3. Compare latest AMI with AMI in use by launch template
1. If cluster is not using latest AMI, or `force replacement` is enabled, proceed to #4
2. Else if using latest AMI already, jump to #10
4. Create new launch configuration with new AMI
5. Update ASG to use new launch config
4. Create new launch template version with new AMI
5. Update launch template default version and set ASG to use the latest template version (`"$Latest"`)
6. Detach existing instances from ASG and replace with new ones
7. Wait for new instances to reach `InService` state with ASG
8. Watch ECS cluster instances until all new ones are registered and available
Expand All @@ -71,9 +71,9 @@ available or not. When `--force-replacement` is enabled the process is _not_ ide
1. Grab the latest binary for your platform at https://github.com/silinternational/ecs-ami-deploy/releases
2. The CLI makes use of AWS's SDK for Go, which can load authentication credentials from various places similar to the
AWS CLI itself
3. Run `ecs-ami-deploy list-cluster` to check if it's working and what clusters you have available.
3. Run `ecs-ami-deploy list-clusters` to check if it's working and what clusters you have available.
4. If you have multiple profiles configured in your `~/.aws/credentials` file, you can use the `-p` or `--profile`
flags to specify a different profile.
5. The CLI defaults to region `us-east-1`, you can use the `-r` or `-region` flags to specify else
5. The CLI defaults to region `us-east-1`, you can use the `-r` or `--region` flags to specify a different region
6. The CLI has help information built in for the various subcommands and their supported flags, use `-h` or `--help`
flags with each subcommand for more information.
4 changes: 2 additions & 2 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/spf13/cobra"

homedir "github.com/mitchellh/go-homedir"
"github.com/mitchellh/go-homedir"
"github.com/spf13/viper"
)

Expand Down Expand Up @@ -55,7 +55,7 @@ func init() {

rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.ecs-ami-deploy.yaml)")
rootCmd.PersistentFlags().StringVarP(&Profile, "profile", "p", "", "AWS shared credentials profile to use")
rootCmd.PersistentFlags().StringVarP(&Region, "region", "r", "us-east-1", "AWS shared credentials profile to use")
rootCmd.PersistentFlags().StringVarP(&Region, "region", "r", "us-east-1", "AWS region")

// Cobra also supports local flags, which will only run
// when this action is called directly.
Expand Down
44 changes: 25 additions & 19 deletions cli/cmd/upgrade-cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
)

var (
cluster string
forceReplace bool
launchConfigNamePrefix string
launchConfigLimit int
pollingInterval int
pollingTimeout int
cluster string
forceReplace bool
launchTemplateNamePrefix string
launchTemplateLimit int
pollingInterval int
pollingTimeout int
)

// latestAMICmd represents the ec2 latest-ami command
Expand All @@ -28,13 +28,13 @@ var upgradeClusterCmd = &cobra.Command{
initAwsCfg()

upgrader, err := ead.NewUpgrader(AwsCfg, &ead.Config{
Cluster: cluster,
AMIFilter: AMIFilter,
ForceReplacement: forceReplace,
LaunchConfigNamePrefix: launchConfigNamePrefix,
LaunchConfigLimit: launchConfigLimit,
PollingInterval: time.Duration(pollingInterval) * time.Second,
PollingTimeout: time.Duration(pollingTimeout) * time.Minute,
Cluster: cluster,
AMIFilter: AMIFilter,
ForceReplacement: forceReplace,
LaunchTemplateNamePrefix: launchTemplateNamePrefix,
LaunchTemplateLimit: launchTemplateLimit,
PollingInterval: time.Duration(pollingInterval) * time.Second,
PollingTimeout: time.Duration(pollingTimeout) * time.Minute,
})
if err != nil {
fmt.Println(err)
Expand Down Expand Up @@ -65,10 +65,16 @@ func init() {
upgradeClusterCmd.PersistentFlags().StringVar(&cluster, "cluster", "", "Cluster name")
_ = upgradeClusterCmd.MarkPersistentFlagRequired("cluster")

upgradeClusterCmd.PersistentFlags().StringVar(&launchConfigNamePrefix, "launch-config-name-prefix", "", "Launch Configuration name prefix")
upgradeClusterCmd.PersistentFlags().BoolVar(&forceReplace, "force-replacement", false, "Force replacement if current AMI is already latest")
upgradeClusterCmd.PersistentFlags().StringVar(&AMIFilter, "ami-filter", ead.DefaultAMIFilter, "AMI search filter")
upgradeClusterCmd.PersistentFlags().IntVar(&launchConfigLimit, "launch-config-limit", ead.DefaultLaunchConfigLimit, "Number of previous launch configurations to keep.")
upgradeClusterCmd.PersistentFlags().IntVar(&pollingInterval, "polling-interval-seconds", int(ead.DefaultPollingInterval.Seconds()), "Number of seconds between status checks.")
upgradeClusterCmd.PersistentFlags().IntVar(&pollingTimeout, "polling-timeout-minutes", int(ead.DefaultPollingTimeout.Minutes()), "Number of minutes before a polling operation times out.")
upgradeClusterCmd.PersistentFlags().StringVar(&launchTemplateNamePrefix, "launch-template-name-prefix",
"", "Launch template name prefix")
upgradeClusterCmd.PersistentFlags().BoolVar(&forceReplace, "force-replacement",
false, "Force replacement if current AMI is already latest")
upgradeClusterCmd.PersistentFlags().StringVar(&AMIFilter, "ami-filter",
ead.DefaultAMIFilter, "AMI search filter")
upgradeClusterCmd.PersistentFlags().IntVar(&launchTemplateLimit, "launch-template-limit",
ead.DefaultLaunchTemplateLimit, "Number of previous launch template versions to keep.")
upgradeClusterCmd.PersistentFlags().IntVar(&pollingInterval, "polling-interval-seconds",
int(ead.DefaultPollingInterval.Seconds()), "Number of seconds between status checks.")
upgradeClusterCmd.PersistentFlags().IntVar(&pollingTimeout, "polling-timeout-minutes",
int(ead.DefaultPollingTimeout.Minutes()), "Number of minutes before a polling operation times out.")
}
54 changes: 27 additions & 27 deletions domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
)

const (
DefaultAMIFilter = "amzn2-ami-ecs-hvm-*-x86_64-ebs"
DefaultPollingTimeout = 15 * time.Minute
DefaultPollingInterval = 5 * time.Second
DefaultLaunchConfigLimit = 5
DefaultTimestampLayout = "20060102T150405"
MinimumIntervalsForStable = 6
TagNameASG = "ecs-ami-deploy-asg"
TagNameTerminate = "ecs-ami-deploy-terminate"
Version = "0.0.0"
DefaultAMIFilter = "amzn2-ami-ecs-hvm-*-x86_64-ebs"
DefaultPollingTimeout = 15 * time.Minute
DefaultPollingInterval = 5 * time.Second
DefaultLaunchTemplateLimit = 5
DefaultTimestampLayout = "20060102T150405"
MinimumIntervalsForStable = 6
TagNameASG = "ecs-ami-deploy-asg"
TagNameTerminate = "ecs-ami-deploy-terminate"
Version = "0.0.0"
)

type ClusterMeta struct {
Expand All @@ -26,25 +26,25 @@ type ClusterMeta struct {
}

type Config struct {
AMIFilter string
Cluster string
ForceReplacement bool
LaunchConfigLimit int
LaunchConfigNamePrefix string
Logger *log.Logger
PollingInterval time.Duration
PollingTimeout time.Duration
TimestampLayout string
AMIFilter string
Cluster string
ForceReplacement bool
LaunchTemplateLimit int
LaunchTemplateNamePrefix string
Logger *log.Logger
PollingInterval time.Duration
PollingTimeout time.Duration
TimestampLayout string
}

var DefaultConfig = Config{
AMIFilter: DefaultAMIFilter,
Cluster: "",
ForceReplacement: false,
LaunchConfigLimit: DefaultLaunchConfigLimit,
LaunchConfigNamePrefix: "",
Logger: nil,
PollingInterval: DefaultPollingInterval,
PollingTimeout: DefaultPollingTimeout,
TimestampLayout: DefaultTimestampLayout,
AMIFilter: DefaultAMIFilter,
Cluster: "",
ForceReplacement: false,
LaunchTemplateLimit: DefaultLaunchTemplateLimit,
LaunchTemplateNamePrefix: "",
Logger: nil,
PollingInterval: DefaultPollingInterval,
PollingTimeout: DefaultPollingTimeout,
TimestampLayout: DefaultTimestampLayout,
}
Loading

0 comments on commit 3a9fa1f

Please sign in to comment.