Skip to content

Commit

Permalink
Remove compose and cfn prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
yinshiua committed May 3, 2017
1 parent 30d6595 commit 2cc56fb
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 256 deletions.
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ install the binary on your `$PATH`. You can use the provided `md5` hash to
verify the integrity of your download.

### Latest version
* Linux:
* Linux:
* [https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest](https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest)
* [https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest.md5](https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest.md5)
* Macintosh:
Expand All @@ -39,7 +39,7 @@ verify the integrity of your download.
### Download specific version
Using the URLs above, replace `latest` with the desired tag, for example `v0.4.1`. After downloading, remember to rename the binary file to `ecs-cli`.

* Linux:
* Linux:
* [https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-v0.4.1](https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-v0.4.1)
* [https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-v0.4.1.md5](https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-v0.4.1.md5)
* Macintosh:
Expand Down Expand Up @@ -70,9 +70,6 @@ OPTIONS:
--secret-key Specifies the AWS secret key to use. If the AWS_SECRET_ACCESS_KEY environment variable is set when ecs-cli configure is run, then the AWS secret access key is set to the value of that environment variable. [$AWS_SECRET_ACCESS_KEY]
--profile, -p Specifies your AWS credentials with an existing named profile from ~/.aws/credentials. If the AWS_PROFILE environment variable is set when ecs-cli configure is run, then the AWS named profile is set to the value of that environment variable. [$AWS_PROFILE]
--cluster, -c Specifies the ECS cluster name to use. If the cluster does not exist, it is created when you try to add resources to it with the ecs-cli up command.
--compose-project-name-prefix "ecscompose-" [Optional] Specifies the prefix added to an ECS task definition created from a compose file. Format <prefix><project-name>.
--compose-service-name-prefix "ecscompose-service-" [Optional] Specifies the prefix added to an ECS service created from a compose file. Format <prefix><project-name>.
--cfn-stack-name-prefix "amazon-ecs-cli-setup-" [Optional] Specifies the prefix added to the AWS CloudFormation stack created on ecs-cli up. Format <prefix><cluster-name>.
```

## Using the CLI
Expand Down Expand Up @@ -157,7 +154,7 @@ that is running with `ecs-cli compose ps`, for example:
```
$ ecs-cli compose ps
Name State Ports TaskDefinition
fd8d5a69-87c5-46a4-80b6-51918092e600/web RUNNING 54.209.244.64:80->80/tcp ecscompose-web:1
fd8d5a69-87c5-46a4-80b6-51918092e600/web RUNNING 54.209.244.64:80->80/tcp web:1
```

Navigate your web browser to the task’s IP address to see the sample app
Expand All @@ -171,8 +168,8 @@ reason).
```
$ ecs-cli compose --project-name wordpress-test service create
INFO[0000] Using Task definition TaskDefinition=ecscompose-wordpress-test:1
INFO[0000] Created an ECS Service serviceName=ecscompose-service-wordpress-test taskDefinition=ecscompose-wordpress-test:1
INFO[0000] Using Task definition TaskDefinition=wordpress-test:1
INFO[0000] Created an ECS Service serviceName=service-wordpress-test taskDefinition=wordpress-test:1
```

Expand All @@ -184,8 +181,8 @@ the following command:
```
$ ecs-cli compose --project-name wordpress-test service ps
Name State Ports TaskDefinition
34333aa6-e976-4096-991a-0ec4cd5af5bd/wordpress RUNNING 54.186.138.217:80->80/tcp ecscompose-wordpress-test:1
34333aa6-e976-4096-991a-0ec4cd5af5bd/mysql RUNNING ecscompose-wordpress-test:1
34333aa6-e976-4096-991a-0ec4cd5af5bd/wordpress RUNNING 54.186.138.217:80->80/tcp wordpress-test:1
34333aa6-e976-4096-991a-0ec4cd5af5bd/mysql RUNNING wordpress-test:1
```


Expand Down
15 changes: 11 additions & 4 deletions ecs-cli/modules/cli/cluster/cluster_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ import (
)

// displayTitle flag is used to print the title for the fields
const displayTitle = true
const (
displayTitle = true
cfnStackNamePrefix = "amazon-ecs-cli-setup-"
)

var flagNamesToStackParameterKeys map[string]string

Expand Down Expand Up @@ -167,7 +170,7 @@ func createCluster(context *cli.Context, rdwr config.ReadWriter, ecsClient ecscl

// Check if cfn stack already exists
cfnClient.Initialize(ecsParams)
stackName := ecsParams.GetCfnStackName()
stackName := getCfnStackName(ecsParams.Cluster)
var deleteStack bool
if err := cfnClient.ValidateStackExists(stackName); err == nil {
if !isForceSet(context) {
Expand Down Expand Up @@ -291,7 +294,7 @@ func deleteCluster(context *cli.Context, rdwr config.ReadWriter, ecsClient ecscl

// Validate that a cfn stack exists for the cluster
cfnClient.Initialize(ecsParams)
stackName := ecsParams.GetCfnStackName()
stackName := getCfnStackName(ecsParams.Cluster)
if err := cfnClient.ValidateStackExists(stackName); err != nil {
return fmt.Errorf("CloudFormation stack not found for cluster '%s'", ecsParams.Cluster)
}
Expand Down Expand Up @@ -341,7 +344,7 @@ func scaleCluster(context *cli.Context, rdwr config.ReadWriter, ecsClient ecscli

// Validate that we have a cfn stack for the cluster
cfnClient.Initialize(ecsParams)
stackName := ecsParams.GetCfnStackName()
stackName := getCfnStackName(ecsParams.Cluster)
if err := cfnClient.ValidateStackExists(stackName); err != nil {
return fmt.Errorf("CloudFormation stack not found for cluster '%s'", ecsParams.Cluster)
}
Expand Down Expand Up @@ -438,3 +441,7 @@ func getClusterSize(context *cli.Context) (string, error) {

return size, nil
}

func getCfnStackName(cluster string) string {
return fmt.Sprintf("%s%s", cfnStackNamePrefix, cluster)
}
2 changes: 1 addition & 1 deletion ecs-cli/modules/cli/cluster/cluster_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (

const (
clusterName = "defaultCluster"
stackName = "defaultCluster"
stackName = cfnStackNamePrefix + "defaultCluster"
)

type mockReadWriter struct {
Expand Down
24 changes: 2 additions & 22 deletions ecs-cli/modules/cli/compose/entity/entity_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ func constructListPagesRequest(entity ProjectEntity, status string, filterLocal

// if service set ServiceName to the request, else set StartedBy to filter out (provided filterLocal is true)
if entity.EntityType() == "service" {
request.ServiceName = aws.String(GetServiceName(entity))
request.ServiceName = aws.String(GetProjectName(entity))
} else if filterLocal {
request.StartedBy = aws.String(GetStartedBy(entity))
request.StartedBy = aws.String(GetProjectName(entity))
}
return request
}
Expand Down Expand Up @@ -215,31 +215,11 @@ func ConvertMapToSlice(mapItems map[string]bool) []*string {

// ---------- naming utils -----------

// GetStartedBy returns an auto-generated formatted string
// that can be supplied while starting an ECS task and is used to identify the owner of ECS Task
func GetStartedBy(entity ProjectEntity) string {
return composeutils.GetStartedBy(getProjectPrefix(entity), GetProjectName(entity))
}

// GetProjectName returns the name of the project that was set in the context we are working with
func GetProjectName(entity ProjectEntity) string {
return entity.Context().Context.ProjectName
}

// getProjectPrefix returns the prefix for the project name
func getProjectPrefix(entity ProjectEntity) string {
return entity.Context().ECSParams.ComposeProjectNamePrefix
}

// GetServiceName using project entity
func GetServiceName(entity ProjectEntity) string {
return composeutils.GetServiceName(getServicePrefix(entity), GetProjectName(entity))
}

func getServicePrefix(entity ProjectEntity) string {
return entity.Context().ECSParams.ComposeServiceNamePrefix
}

// GetIdFromArn gets the aws String value of the input arn and returns the id part of the arn
func GetIdFromArn(arn *string) string {
return composeutils.GetIdFromArn(aws.StringValue(arn))
Expand Down
8 changes: 4 additions & 4 deletions ecs-cli/modules/cli/compose/entity/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (s *Service) Start() error {
// Read the custom error returned from describeService to see if the resource was missing
if strings.Contains(err.Error(), ecsMissingResourceCode) {
return fmt.Errorf("Please use '%s' command to create the service '%s' first",
command.CreateServiceCommandName, entity.GetServiceName(s))
command.CreateServiceCommandName, entity.GetProjectName(s))
}
return err
}
Expand Down Expand Up @@ -319,7 +319,7 @@ func (s *Service) EntityType() string {

// createService calls the underlying ECS.CreateService
func (s *Service) createService() error {
serviceName := entity.GetServiceName(s)
serviceName := entity.GetProjectName(s)
taskDefinitionID := entity.GetIdFromArn(s.TaskDefinition().TaskDefinitionArn)

err := s.Context().ECSClient.CreateService(serviceName, taskDefinitionID, s.loadBalancer, s.role, s.DeploymentConfig())
Expand All @@ -332,7 +332,7 @@ func (s *Service) createService() error {
// describeService calls underlying ECS.DescribeService and expects the service to be present,
// returns error otherwise
func (s *Service) describeService() (*ecs.Service, error) {
serviceName := entity.GetServiceName(s)
serviceName := entity.GetProjectName(s)
output, err := s.Context().ECSClient.DescribeService(serviceName)
if err != nil {
return nil, err
Expand Down Expand Up @@ -364,7 +364,7 @@ func (s *Service) startService(ecsService *ecs.Service) error {

// updateService calls the underlying ECS.UpdateService with the specified count
func (s *Service) updateService(count int64) error {
serviceName := entity.GetServiceName(s)
serviceName := entity.GetProjectName(s)
deploymentConfig := s.DeploymentConfig()
if err := s.Context().ECSClient.UpdateServiceCount(serviceName, count, deploymentConfig); err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions ecs-cli/modules/cli/compose/entity/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (t *Task) Run(commandOverrides map[string][]string) error {
return err
}
taskDefinitionId := aws.StringValue(taskDef.TaskDefinitionArn)
ecsTasks, err := t.Context().ECSClient.RunTaskWithOverrides(taskDefinitionId, entity.GetStartedBy(t), 1, commandOverrides)
ecsTasks, err := t.Context().ECSClient.RunTaskWithOverrides(taskDefinitionId, entity.GetProjectName(t), 1, commandOverrides)
if err != nil {
return nil
}
Expand Down Expand Up @@ -245,7 +245,7 @@ func (t *Task) runTasks(taskDefinitionId string, totalCount int) ([]*ecs.Task, e
if i+chunkSize > totalCount {
count = totalCount - i
}
ecsTasks, err := t.Context().ECSClient.RunTask(taskDefinitionId, entity.GetStartedBy(t), count)
ecsTasks, err := t.Context().ECSClient.RunTask(taskDefinitionId, entity.GetProjectName(t), count)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -336,6 +336,6 @@ func (t *Task) up(updateTasks bool) error {
// ---------- naming utils -----------

func getFormattedContainerName(task *ecs.Task, container *ecs.Container) string {
taskId := entity.GetIdFromArn(task.TaskArn)
return composeutils.GetFormattedContainerName(taskId, aws.StringValue(container.Name))
taskID := entity.GetIdFromArn(task.TaskArn)
return composeutils.GetFormattedContainerName(taskID, aws.StringValue(container.Name))
}
2 changes: 1 addition & 1 deletion ecs-cli/modules/cli/compose/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (p *ecsProject) transformTaskDefinition() error {

// convert to task definition
logrus.Debug("Transforming yaml to task definition...")
taskDefinitionName := utils.GetTaskDefinitionName(context.ECSParams.ComposeProjectNamePrefix, context.Context.ProjectName)
taskDefinitionName := context.Context.ProjectName
taskDefinition, err := utils.ConvertToTaskDefinition(taskDefinitionName, &context.Context, p.ServiceConfigs())
if err != nil {
return err
Expand Down
4 changes: 0 additions & 4 deletions ecs-cli/modules/cli/configure/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ func createECSConfigFromCli(context *cli.Context) (*config.CliConfig, error) {
ecsConfig.AwsSecretKey = secretKey
ecsConfig.Region = region

ecsConfig.ComposeProjectNamePrefix = context.String(command.ComposeProjectNamePrefixFlag)
ecsConfig.ComposeServiceNamePrefix = context.String(command.ComposeServiceNamePrefixFlag)
ecsConfig.CFNStackNamePrefix = context.String(command.CFNStackNamePrefixFlag)

return ecsConfig, nil
}

Expand Down
36 changes: 0 additions & 36 deletions ecs-cli/modules/cli/configure/configure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,39 +101,3 @@ func TestConfigInitWithProfileAndKeys(t *testing.T) {
_, err := createECSConfigFromCli(context)
assert.Error(t, err, "Expected error when both AWS Profile and access keys are specified")
}

func TestConfigInitWithPrefixes(t *testing.T) {
setPrefixes := flag.NewFlagSet("ecs-cli", 0)
setPrefixes.String(command.ProfileFlag, profileName, "")
setPrefixes.String(command.ClusterFlag, clusterName, "")

composeProjectName := "projectName"
composeServiceName := "serviceName"
cfnStackName := "stackName"

setPrefixes.String(command.ComposeProjectNamePrefixFlag, composeProjectName, "")
setPrefixes.String(command.ComposeServiceNamePrefixFlag, composeServiceName, "")
setPrefixes.String(command.CFNStackNamePrefixFlag, cfnStackName, "")

context := cli.NewContext(nil, setPrefixes, nil)

cfg, err := createECSConfigFromCli(context)
assert.NoError(t, err, "Unexpected error reading config from rdwr")
assert.Equal(t, composeProjectName, cfg.ComposeProjectNamePrefix, "Expected ComposeProjectName to match in config")
assert.Equal(t, composeServiceName, cfg.ComposeServiceNamePrefix, "Expected ComposeServiceName to match in config")
assert.Equal(t, cfnStackName, cfg.CFNStackNamePrefix, "Expected CfnStackName to match in config")
}

func TestConfigInitWithoutPrefixes(t *testing.T) {
setNoPrefixes := flag.NewFlagSet("ecs-cli", 0)
setNoPrefixes.String(command.ProfileFlag, profileName, "")
setNoPrefixes.String(command.ClusterFlag, clusterName, "")

context := cli.NewContext(nil, setNoPrefixes, nil)

cfg, err := createECSConfigFromCli(context)
assert.NoError(t, err, "Unexpected error reading config from rdwr")
assert.Empty(t, cfg.ComposeProjectNamePrefix, "Expected ComposeProjectNamePrefix to be empty")
assert.Empty(t, cfg.ComposeServiceNamePrefix, "Expected ComposeServiceNamePrefix to be empty")
assert.Empty(t, cfg.CFNStackNamePrefix, "Expected CFNStackNamePrefix to be empty")
}
21 changes: 0 additions & 21 deletions ecs-cli/modules/commands/configure/configure_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,5 @@ func configureFlags() []cli.Flag {
// Commenting it now to avoid user misunderstanding the behavior of this env var with other ecs-cli commands
// EnvVar: "ECS_CLUSTER",
},
cli.StringFlag{
Name: flags.ComposeProjectNamePrefixFlag,
Value: flags.ComposeProjectNamePrefixDefaultValue,
Usage: fmt.Sprintf(
"[Optional] Specifies the prefix added to an ECS task definition created from a compose file. Format <prefix><project-name>.",
),
},
cli.StringFlag{
Name: flags.ComposeServiceNamePrefixFlag,
Value: flags.ComposeServiceNamePrefixDefaultValue,
Usage: fmt.Sprintf(
"[Optional] Specifies the prefix added to an ECS service created from a compose file. Format <prefix><project-name>.",
),
},
cli.StringFlag{
Name: flags.CFNStackNamePrefixFlag,
Value: flags.CFNStackNamePrefixDefaultValue,
Usage: fmt.Sprintf(
"[Optional] Specifies the prefix added to the AWS CloudFormation stack created on ecs-cli up. Format <prefix><cluster-name>.",
),
},
}
}
7 changes: 0 additions & 7 deletions ecs-cli/modules/commands/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ const (
ClusterFlag = "cluster"
VerboseFlag = "verbose"

ComposeProjectNamePrefixFlag = "compose-project-name-prefix"
ComposeProjectNamePrefixDefaultValue = "ecscompose-"
ComposeServiceNamePrefixFlag = "compose-service-name-prefix"
ComposeServiceNamePrefixDefaultValue = ComposeProjectNamePrefixDefaultValue + "service-"
CFNStackNamePrefixFlag = "cfn-stack-name-prefix"
CFNStackNamePrefixDefaultValue = "amazon-ecs-cli-setup-"

// Cluster
AsgMaxSizeFlag = "size"
VpcAzFlag = "azs"
Expand Down
20 changes: 5 additions & 15 deletions ecs-cli/modules/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
)

const (
ecsSectionKey = "ecs"
composeProjectNamePrefixKey = "compose-project-name-prefix"
composeServiceNamePrefixKey = "compose-service-name-prefix"
cfnStackNamePrefixKey = "cfn-stack-name-prefix"
)

// CliConfig is the top level struct used to map to the ini config.
type CliConfig struct {
// TODO Add metadata information like version etc.
Expand All @@ -38,14 +31,11 @@ type CliConfig struct {

// SectionKeys is the struct embedded in CliConfig. It groups all the keys in the 'ecs' section in the ini file.
type SectionKeys struct {
Cluster string `ini:"cluster"`
AwsProfile string `ini:"aws_profile"`
Region string `ini:"region"`
AwsAccessKey string `ini:"aws_access_key_id"`
AwsSecretKey string `ini:"aws_secret_access_key"`
ComposeProjectNamePrefix string `ini:"compose-project-name-prefix"`
ComposeServiceNamePrefix string `ini:"compose-service-name-prefix"`
CFNStackNamePrefix string `ini:"cfn-stack-name-prefix"`
Cluster string `ini:"cluster"`
AwsProfile string `ini:"aws_profile"`
Region string `ini:"region"`
AwsAccessKey string `ini:"aws_access_key_id"`
AwsSecretKey string `ini:"aws_secret_access_key"`
}

// NewCliConfig creates a new instance of CliConfig from the cluster name.
Expand Down
Loading

0 comments on commit 2cc56fb

Please sign in to comment.