feat: implement --generate-cmd flag for task run#2201
feat: implement --generate-cmd flag for task run#2201mergify[bot] merged 22 commits intoaws:mainlinefrom
Conversation
|
Conducted the following manual testings. For Copilot service
For non-Copilot ECS ServiceUsing cluster name and service name
Using ARN
|
bvtujo
left a comment
There was a problem hiding this comment.
Looks great to me! Just a few questions.
| if err != nil { | ||
| return nil, fmt.Errorf("extract service name from arn %s", svcARN) | ||
| } | ||
| return generator.ECSServiceCommandGenerator{ |
There was a problem hiding this comment.
Are we not supporting jobs with this feature? I apologize I didn't get in on the earlier review of this. Or was the decision made to delegate that to the hypothetical job run subcommand?
There was a problem hiding this comment.
I will make a draft PR for job for this feature! The code is working but is a little messy and I haven't got the chance to really clean it up, so it's not in this PR yet.
efekarakus
left a comment
There was a problem hiding this comment.
The code looks good! let me know what's your thought on the comment below :)
| type cmdGenerator interface { | ||
| Generate() (*generator.GenerateCommandOpts, error) | ||
| } |
There was a problem hiding this comment.
This is interesting 💭 this is the first time that we have a package that populates values for a command.
Did we go with this route to keep the cli pkg small? I think that makes sense to me, but I wonder if instead of a new pkg we could have moved most of the functionality into the internal/pkg/ecs pkg and removed the generator pkg altogether.
This functionality seems like should belong in thecli pkg since it can only be used by task_run so there is no other possible consumer of the generator pkg:
copilot-cli/internal/pkg/generator/generate.go
Lines 74 to 75 in f2ad676
Hope that makes sense! Instead, we can maybe move this functionality to the ecs pkg:
func RunTaskRequestFromECSService(client ecsDescriber, cluster, service string) (*RunTaskRequest, error)
func RunTaskRequestFromService(client ecsDescriber, app, env, svc string) (*RunTaskRequest, error)
iamhopaul123
left a comment
There was a problem hiding this comment.
Amazing work! LGTM mostly but just some nits.
| return nil | ||
| } | ||
|
|
||
| func (o *runTaskOpts) runTaskCommand() (*ecs.RunTaskRequest, error) { |
There was a problem hiding this comment.
Maybe i was missing anything but i don't see the logic is well tested for this func...
| } | ||
|
|
||
| if len(taskDef.ContainerDefinitions) > 1 { | ||
| return nil, fmt.Errorf("found more than one container in task definition: %s", taskDefNameOrARN) |
There was a problem hiding this comment.
I think for a better user experience, it would be nice if we can log here about the reason why they cannot use a taskdef with more than one container. But we don't log elsewhere than the cli pkg. What do you think of it @efekarakus ?
There was a problem hiding this comment.
We can throw a typed error here and catch that in the cli package and log. So something like:
var errMultiContainers *ecs.ErrMultipleContainersInTaskDef
if errors.As(err, &errMultiContainers) {
log.Errorf("`copilot task run` does not support running more than one container")
}
return errThere was a problem hiding this comment.
That's exactly what I've been thinking!
efekarakus
left a comment
There was a problem hiding this comment.
Yay looks great, just one more minor suggestion and then we can ![]()
| } | ||
|
|
||
| if len(taskDef.ContainerDefinitions) > 1 { | ||
| return nil, fmt.Errorf("found more than one container in task definition: %s", taskDefNameOrARN) |
There was a problem hiding this comment.
We can throw a typed error here and catch that in the cli package and log. So something like:
var errMultiContainers *ecs.ErrMultipleContainersInTaskDef
if errors.As(err, &errMultiContainers) {
log.Errorf("`copilot task run` does not support running more than one container")
}
return err| } | ||
|
|
||
| // String stringifies a RunTaskRequest. | ||
| func (r RunTaskRequest) String() string { |
There was a problem hiding this comment.
I don't think we should implement the fmt.Stringer interface if it can't be used across packages. For example, if we do fmt.Sprintf("%s", RunTaskRequest{...}) it's going to write "copilot task run ..." which is surprising.
Instead, we can create our own string method: CLIString() string and a type CLIStringer interface so that we can implement this interface across many data types
…oad (#2246) This PR implement the function to generate a run task request from a deployed job, and the functions to support it. This PR is rebased from #2201 (which is not merged yet). The real changes to this PR are at - `ecs/run_task_request.go` (where the information needed to generated a `task run` command is grabbed from a Copilot job) - `ecs/run_task_request_test.go` - `aws/stepfunctions/*` (where the client to make API calls to stepfunctions is implemented) By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
…oad (aws#2246) This PR implement the function to generate a run task request from a deployed job, and the functions to support it. This PR is rebased from aws#2201 (which is not merged yet). The real changes to this PR are at - `ecs/run_task_request.go` (where the information needed to generated a `task run` command is grabbed from a Copilot job) - `ecs/run_task_request_test.go` - `aws/stepfunctions/*` (where the client to make API calls to stepfunctions is implemented) By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
This PR implements `--generate-cmd` for `task run` given either a non-Copilot ECS service or a Copilot service. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
…oad (aws#2246) This PR implement the function to generate a run task request from a deployed job, and the functions to support it. This PR is rebased from aws#2201 (which is not merged yet). The real changes to this PR are at - `ecs/run_task_request.go` (where the information needed to generated a `task run` command is grabbed from a Copilot job) - `ecs/run_task_request_test.go` - `aws/stepfunctions/*` (where the client to make API calls to stepfunctions is implemented) By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
This PR implements
--generate-cmdfortask rungiven either a non-Copilot ECS service or a Copilot service.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.