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 ps" to list running local ECS task containers #779

Merged
merged 9 commits into from
May 29, 2019

Conversation

efekarakus
Copy link
Contributor

@efekarakus efekarakus commented May 24, 2019

Description of changes: Lists the running containers part of the ECS tasks running locally.


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)
  • Integration tests added for new functionality

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. Nothing running locally

$ dev-ecs-cli local ps         
CONTAINER ID        IMAGE               STATUS              PORTS               NAMES               TASKDEFINITIONARN   TASKFILEPATH
$ dev-ecs-cli local ps --json           
[]

2. With a task container running

$ dev-ecs-cli local ps     
CONTAINER ID        IMAGE                 STATUS              PORTS                  NAMES                    TASKDEFINITIONARN                                               TASKFILEPATH
2ddaeed688aa        ecs-local-other_app   Up 2 seconds        0.0.0.0:6000->80/tcp   /ecs-local-other_app_1   arn:aws:ecs:us-east-1:685593908319:task-definition/efe-test:1  
$ dev-ecs-cli local ps --json                                                                                                                                                                                                       local/ps ⬆ ✭
[
  {
    "Id": "2ddaeed688aac5297d13dd1dc2dda4e9a8a1baebeb4b4fc2198da783e122a023",
    "Names": [
      "/ecs-local-other_app_1"
    ],
    "Image": "ecs-local-other_app",
    "ImageID": "sha256:0ac30848f74a68b442cee205df0b20e8a038bb061776a1786363510dbc2c6f85",
    "Command": "/bin/sh -c '/bin/bash -c 'while true; do sleep 30; done;''",
    "Created": 1558723259,
    "Ports": [
      {
        "IP": "0.0.0.0",
        "PrivatePort": 80,
        "PublicPort": 6000,
        "Type": "tcp"
      }
    ],
    "Labels": {
      "ECSLocalTask": "True",
      "com.docker.compose.config-hash": "1d67f24db5737d34353d6112e9cf51d9fd5713e7e52eae81eb6c0bd9873caafc",
      "com.docker.compose.container-number": "1",
      "com.docker.compose.oneoff": "False",
      "com.docker.compose.project": "ecs-local-other",
      "com.docker.compose.service": "app",
      "com.docker.compose.version": "1.23.2",
      "taskDefinitionARN": "arn:aws:ecs:us-east-1:685593908319:task-definition/efe-test:1"
    },
    "State": "running",
    "Status": "Up 34 seconds",
    "HostConfig": {
      "NetworkMode": "ecs-local-network"
    },
    "NetworkSettings": {
      "Networks": {
        "ecs-local-network": {
          "IPAMConfig": null,
          "Links": null,
          "Aliases": null,
          "NetworkID": "cb43b4445f11ac4e8f337f68904e3d1eb2b900b80deabe4c62cea56c063ad029",
          "EndpointID": "a4b718d0cc53f171e5e5220f81d6647d24990724b7439d78be0438c2decdab97",
          "Gateway": "169.254.170.1",
          "IPAddress": "169.254.170.3",
          "IPPrefixLen": 24,
          "IPv6Gateway": "",
          "GlobalIPv6Address": "",
          "GlobalIPv6PrefixLen": 0,
          "MacAddress": "02:42:a9:fe:aa:03",
          "DriverOpts": null
        }
      }
    },
    "Mounts": []
  }
]


// TODO These labels should be defined part of the local.Create workflow.
// Refactor to import these constants instead of re-defining them here.
const (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SoManyHs These are the Docker object labels that I'm expecting to be part of each container. Let me know if you're planing to use a different value for them :)

tests := map[string]struct {
sequence []commandTest
}{
"clean state": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason why this is a table driven test?

Looks like it only has one test case...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

soon™ we'll have full ecs-cli local workflows as integration tests :P.

This sequence for example will make up on test case: "ecs-cli local create --arn" -> "ecs-cli local up" -> "ecs-cli local ps" -> "ecs-cli local stop"

Copy link
Contributor

Choose a reason for hiding this comment

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

😎

// 1. read in task def (from file or arn)
// 2. parse task def into go object
// 3. write to docker-compose.local.yml file
fmt.Println("foo") // placeholder
Copy link
Contributor

Choose a reason for hiding this comment

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

lol


const (
// minDockerAPIVersion is the oldest Docker API version supporting the operations used by "local" sub-commands.
minDockerAPIVersion = "1.27"
Copy link
Contributor

Choose a reason for hiding this comment

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

How'd you pick this version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I picked the same version that the endpoints container requires. The operations that we use so far in "ecs local" are all supported in v1.27.

I can say that the endpoints container uses 1.27 and link to the code ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure 👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I'd prefer it if the comment also said that all the operations in ecs local are supported in v1.27

Its hypothetically possible that the "ecs local" commands would need a newer Docker client version than the endpoints container.

The current comment might lead future maintainers to think that the commands and the endpoints container have to use the same Docker Client version. And that's not true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 makes sense, done!

@efekarakus efekarakus merged commit 0faf4cf into aws:ecs-local May 29, 2019
@efekarakus efekarakus deleted the local/ps branch June 6, 2019 18:44
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.

2 participants