-
Notifications
You must be signed in to change notification settings - Fork 302
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
Support "local down" to stop a running local task #783
Conversation
Manual tests1. Clean environmentThe user never ran $ ecs-cli local down
WARN[0000] Compose file docker-compose.local.yml does not exist in current directory
WARN[0000] Network ecs-local-network not found, skipping network removal
$ 2. No running local tasks, but network and endpoints container is up$ ecs-cli local down
WARN[0000] Compose file docker-compose.local.yml does not exist in current directory
INFO[0000] The network ecs-local-network has no more running tasks
INFO[0000] Stopped container with name amazon-ecs-local-container-endpoints
INFO[0000] Removed container with name amazon-ecs-local-container-endpoints
INFO[0000] Removed network with name ecs-local-network
$ 3. Stop a running task3.1. Stopping using
|
@@ -46,6 +49,16 @@ func GetCommand(args []string) *exec.Cmd { | |||
return exec.Command(cmdPath, args...) | |||
} | |||
|
|||
// RunCmd runs a command with args and returns its Stdout. | |||
func RunCmd(t *testing.T, args []string) stdout.Stdout { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
} | ||
|
||
for _, container := range containers { | ||
if err = docker.ContainerStop(context.Background(), container.ID, nil); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use a context with a timeout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! 🙈 done, moved docker.go to its own sub-package with an exported timeout constant.
// Has other containers running in the network | ||
logrus.Infof("%d other task(s) running locally, skipping network removal.", len(resp.Containers)-1) | ||
// Has other containers running in the network, skip teardown. | ||
logrus.Infof("%d other task(s) running locally, skipping network removal", len(resp.Containers)-1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we know that the number of running tasks is equal to len(resp.Containers)-1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The LocalEndpoints container should always be running in the network, so I subtract it to show the actual number of running containers for ECS local.
Updated the comment to:
// Don't count the endpoints container part of the running containers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. But tasks != containers. So I think it should say "other container(s) running locally"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I updated that too :)
// Down stops and removes a running local ECS task. | ||
// If the user stops the last running task in the local network then also remove the network. | ||
func Down(c *cli.Context) error { | ||
defer func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of defer 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| | |
)_) )_) )_)
)___))___))___)\
)____)____)_____)\\
_____|____|____|____\\\__
---------\ /---------
^^^^^ ^^^^^^^^^^^^^^^^^^^^^
^^^^ ^^^^ ^^^ ^^
^^^^ ^^^
Description of changes:
ecs-cli local down
stops a running local task. If the stopped task is the last running ECS local task, then also teardown the network.Enter
[N/A]
in the box, if an item is not applicable to your change.Testing
Documentation
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.