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

Support "local down" to stop a running local task #783

Merged
merged 12 commits into from
Jun 6, 2019

Conversation

efekarakus
Copy link
Contributor

@efekarakus efekarakus commented May 31, 2019

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

  • Unit tests passed
  • Integration tests passed
  • Unit tests added for new functionality
  • Listed manual checks and their outputs in the comments (example)
  • Added an additional integ test

Documentation

  • [N/A] Contacted our doc writer
  • [N/A] Updated our README

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@efekarakus
Copy link
Contributor Author

Manual tests

1. Clean environment

The user never ran ecs-cli local up so they have no network or endpoints container running.

$ 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 task

3.1. Stopping using docker-compose.local.yml
$ ls
Dockerfile               docker-compose.local.yml
$ ecs-cli local ps
CONTAINER ID        IMAGE                   STATUS              PORTS                  NAMES                      TASKDEFINITIONARN                                               TASKFILEPATH
dbadc6235adb        ecs-local-other_app     Up 3 seconds        0.0.0.0:6001->80/tcp   /ecs-local-other_app_1     arn:aws:ecs:us-east-1:685593908319:task-definition/efe-test:1   
c8984b215f44        ecs-local-bugbash_app   Up 16 seconds       0.0.0.0:6000->80/tcp   /ecs-local-bugbash_app_1                                                                   /Users/karakuse/Development/ecs-local-apps/ecs-local-bugbash
$ ecs-cli local down
INFO[0000] Running Compose down on docker-compose.local.yml 
INFO[0011] Stopped and removed containers successfully  
INFO[0011] 1 other task(s) running locally, skipping network removal 
$
3.1. Stopping using --file flag
$ ecs-cli local down -f /Users/karakuse/Development/ecs-local-apps/ecs-local-bugbash
INFO[0010] Stopped container with id c8984b215f444cbf1d374ef13845de51d57e18e53d2d6e7b23f4d8d56c56f5ba 
INFO[0010] Removed container with id c8984b215f444cbf1d374ef13845de51d57e18e53d2d6e7b23f4d8d56c56f5ba 
INFO[0010] 1 other task(s) running locally, skipping network removal 
$
3.1. Stopping using --arn flag
$ ecs-cli local down -a arn:aws:ecs:us-east-1:685593908319:task-definition/efe-test:1
INFO[0010] Stopped container with id dbadc6235adbc89a128adb9dde033739d19f1c68c875faad031b235635d4a50c 
INFO[0010] Removed container with id dbadc6235adbc89a128adb9dde033739d19f1c68c875faad031b235635d4a50c 
INFO[0010] The network ecs-local-network has no more running tasks 
INFO[0011] Stopped container with name amazon-ecs-local-container-endpoints 
INFO[0011] Removed container with name amazon-ecs-local-container-endpoints 
INFO[0011] Removed network with name ecs-local-network  
$

@@ -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 {
Copy link
Contributor

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 {
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 use a context with a timeout

Copy link
Contributor Author

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)
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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"

Copy link
Contributor Author

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() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice use of defer 👍🏻

Copy link
Contributor

@PettitWesley PettitWesley left a comment

Choose a reason for hiding this comment

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

              |    |    |
             )_)  )_)  )_)
            )___))___))___)\
           )____)____)_____)\\
         _____|____|____|____\\\__
---------\                   /---------
  ^^^^^ ^^^^^^^^^^^^^^^^^^^^^
    ^^^^      ^^^^     ^^^    ^^
         ^^^^      ^^^

@efekarakus efekarakus merged commit 6d8674e into aws:ecs-local Jun 6, 2019
@efekarakus efekarakus deleted the local/down branch June 6, 2019 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants