Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): implement exec for task run #1077

Closed
wants to merge 4 commits into from

Conversation

Louise15926
Copy link
Contributor

@Louise15926 Louise15926 commented Jun 30, 2020

The PR implements execute for task run command. Specifically, it does the following:

  1. modifies ecs package, and adds a ec2 package
  2. modifies deploy, cloudformation and stack packages
  3. creates a cloudformation template for task run
  4. modifies cli package

Related #702

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Louise15926 Louise15926 requested a review from a team as a code owner June 30, 2020 21:06
@Louise15926 Louise15926 requested a review from kohidave June 30, 2020 21:06
@Louise15926 Louise15926 requested a review from piradeepk June 30, 2020 21:06
@Louise15926 Louise15926 added the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Jun 30, 2020
@piradeepk piradeepk requested a review from iamhopaul123 June 30, 2020 21:08
Copy link
Contributor

@iamhopaul123 iamhopaul123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome PR. A great leap from 0 to 1!

internal/pkg/aws/ec2/ec2.go Outdated Show resolved Hide resolved
internal/pkg/aws/ec2/ec2.go Show resolved Hide resolved
internal/pkg/aws/ec2/ec2.go Outdated Show resolved Hide resolved
internal/pkg/aws/ec2/ec2.go Outdated Show resolved Hide resolved
internal/pkg/aws/ec2/ec2.go Outdated Show resolved Hide resolved
internal/pkg/cli/task_run.go Outdated Show resolved Hide resolved
internal/pkg/cli/task_run.go Outdated Show resolved Hide resolved
internal/pkg/cli/task_run.go Outdated Show resolved Hide resolved
internal/pkg/cli/task_run.go Show resolved Hide resolved
internal/pkg/cli/task_run.go Outdated Show resolved Hide resolved
Copy link
Contributor

@iamhopaul123 iamhopaul123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good to me! Could you also add manual tests for this feature? Like doing a deployment with local image and url?

internal/pkg/aws/ec2/ec2.go Outdated Show resolved Hide resolved
internal/pkg/aws/ec2/ec2.go Show resolved Hide resolved
internal/pkg/aws/ec2/ec2.go Outdated Show resolved Hide resolved
internal/pkg/cli/interfaces.go Show resolved Hide resolved
internal/pkg/aws/ec2/ec2.go Outdated Show resolved Hide resolved
internal/pkg/cli/task_run.go Show resolved Hide resolved
internal/pkg/cli/task_run.go Outdated Show resolved Hide resolved
internal/pkg/cli/task_run.go Outdated Show resolved Hide resolved
templates/task/cf.yml Outdated Show resolved Hide resolved
templates/task/cf.yml Outdated Show resolved Hide resolved
Copy link
Contributor

@bvtujo bvtujo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks awesome. What a massive effort. Just a few nits from my side but LGTM!

internal/pkg/aws/ecs/ecs.go Show resolved Hide resolved
internal/pkg/deploy/task.go Show resolved Hide resolved
internal/pkg/deploy/cloudformation/task.go Show resolved Hide resolved
Copy link
Contributor

@iamhopaul123 iamhopaul123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ship it :shipit: just a few nits and adding the manual test

internal/pkg/aws/ec2/ec2.go Show resolved Hide resolved
internal/pkg/aws/ec2/ec2.go Show resolved Hide resolved
internal/pkg/aws/ecs/ecs.go Show resolved Hide resolved
@@ -168,6 +181,60 @@ func (e *ECS) ServiceTasks(clusterName, serviceName string) ([]*Task, error) {
return tasks, nil
}

// DefaultClusters returns the default clusters in the account and region
func (e *ECS) DefaultCluster() (string, error) {
resp, err := e.client.DescribeClusters(&ecs.DescribeClustersInput{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we include the "Default" cluster as an input parameter? Otherwise we're just choosing the "first" cluster - which may not be the default cluster at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From DescribeClustersInput it says, If Clusters is not specified, the default cluster is assumed. Not sure if this answers your concern 👀

internal/pkg/aws/ecs/ecs.go Show resolved Hide resolved
Comment on lines +227 to +230
clusters, err := o.resourceGetter.GetResourcesByTags(clusterResourceType, map[string]string{
deploy.AppTagKey: o.AppName(),
deploy.EnvTagKey: o.env,
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should hide this somewhere. Perhaps in the describe package or the ECSGetter?

store store
parser dockerfileParser
sel appEnvWithNoneSelector
fs afero.Fs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used at Validate to determine whether the dockerfile path that user provides is valid


Cpu int
Memory int

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may also need to support EntryPoint, as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new flag🚩 Sounds good! Will do this in a separate PR!

templates/task/cf.yml Show resolved Hide resolved
templates/task/cf.yml Show resolved Hide resolved
internal/pkg/aws/ec2/ec2.go Show resolved Hide resolved
internal/pkg/aws/ec2/ec2.go Show resolved Hide resolved
internal/pkg/aws/ec2/ec2.go Show resolved Hide resolved
internal/pkg/aws/ec2/ec2.go Show resolved Hide resolved
internal/pkg/aws/ecs/ecs.go Show resolved Hide resolved
internal/pkg/aws/ecs/ecs.go Show resolved Hide resolved
internal/pkg/aws/ecs/ecs.go Show resolved Hide resolved
internal/pkg/cli/interfaces.go Show resolved Hide resolved
internal/pkg/cli/interfaces.go Show resolved Hide resolved
internal/pkg/cli/interfaces.go Show resolved Hide resolved
Copy link
Contributor

@efekarakus efekarakus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a huge amount of work and amazing! However, can we close this PR and create new ones by splitting up this work?

I think for us to be able to give good feedback, we need the PRs to be smaller. I personally struggle digesting all this information. We can take our time slightly more but deliver the right UX for our customers.

What do you think of submitting a PR individually for each one of the packages touched?

  • internal/aws/ec2 pkg
  • deploy/cfn/stack pkg + cf template
  • deploy/cfn pkg with DeployTask
  • An internal/task pkg with multiple functions like RunInDefaultVPC or RunInEnv that could
    abstract away the getCluster, getNetworking methods.
  • An internal/repository pkg to abstract pushToECRRepo()
  • The task_run file.

Feel free to change the order or add additional/remove item but in general let's try to keep each layer in a separate PR.

Also this is my bad, I'll make sure to provide quick feedback with the PRs to unblock you!

internal/pkg/cli/task_run.go Show resolved Hide resolved
internal/pkg/cli/task_run.go Show resolved Hide resolved
)

const (
defaultImageTag = "copilot"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we re-use:

func getVersionTag(runner runner) (string, error) {
var b bytes.Buffer
if err := runner.Run("git", []string{"describe", "--always"}, command.Stdout(&b)); err != nil {
return "", err
}
// NOTE: `git describe` output bytes includes a `\n` character, so we trim it out.
return strings.TrimSpace(b.String()), nil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think it makes sense if I first try to getVersionTag, if it fails (e.g. it is not a git repo), then I use this defaultImageTag?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what we do with svc deploy is first checking if we can getVersionTag, if that fails we prompt for a tag value

internal/pkg/cli/task_run.go Show resolved Hide resolved
cmd.Flags().StringSliceVar(&vars.securityGroups, securityGroupsFlag, nil, securityGroupsFlagDescription)

cmd.Flags().StringToStringVar(&vars.envVars, envVarsFlag, nil, envVarsFlagDescription)
cmd.Flags().StringSliceVar(&vars.commands, commandsFlag, nil, commandsFlagDescription)
cmd.Flags().StringVar(&vars.command, commandFlag, "", commandFlagDescription)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the style guide for the CLI we decided: https://github.com/aws/copilot-cli/blob/master/STYLE_GUIDE.md#flags

Flags are used when you need more than one required input of different type or if the inputs are optional.

Since the flag is optional and to keep it consistent with the other commands, I think we should have it behind a flag

}

func (o *runTaskOpts) getCluster() (string, error) {
if o.env == config.EnvNameNone {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the EnvNameNone a bit confusing, so as a customer do I have to explicitly write "None" to the -e flag for it to pick up the default cluster?

Why can't we use the default empty string "" to say that a user hasn't specified an environment?
I'd love for us to think if we can simplify this for our customers since the "None" environment doesn't exist in our other commands.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, they don't explicitly specify "None". The first time "None" appears is when we ask for an env name during Ask. We list all the environments of the app, and append to the end an option called "None" which would result in the default cluster and subnets if selected.

We can use "" instead of "None". As a customer the experience would be the same - the "None" would still be a reserved keyword because it's till gonna be there during Ask, so that the user can opt to use the default cluster/subnet during Ask.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha! that's good to know :) ok then I think it's fine but maybe we can move the const out of the config pkg to the cli package itself. Since config pkg itself doesn't use the constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!!

internal/pkg/cli/task_run.go Show resolved Hide resolved
@Louise15926 Louise15926 closed this Jul 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge Pull requests that mergify shouldn't merge until the requester allows it.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants