Skip to content
This repository was archived by the owner on Nov 19, 2025. It is now read-only.

Conversation

@PettitWesley
Copy link
Contributor

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

@PettitWesley PettitWesley changed the title Support Docker Volume Configuration in ECS Params WIP: Support Docker Volume Configuration in ECS Params Aug 21, 2018
@PettitWesley PettitWesley force-pushed the params-docker-volumes branch from 6a17850 to 3a7339b Compare August 21, 2018 17:37
@PettitWesley PettitWesley changed the title WIP: Support Docker Volume Configuration in ECS Params Support Docker Volume Configuration in ECS Params Aug 21, 2018
- name: string
scope: string ("shared" or "task")
autoprovision: boolean (only valid if scope = "shared")
driver: string
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 discrete list of valid entries for this field (or others) and we can call out with a comment? Thinking about how we annotated task placement args.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a bunch of volume plugins out there (aka volume 'drivers'), and new ones will be created in the future; and putting a list here would be misleading because ECS accepts any string for this value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

I was referring to having comments versus parentheticals, e.g. scope: string // Valid values: "shared" | "task"

for _, dockerVol := range ecsParams.TaskDefinition.DockerVolumes {
if dockerVol.Name != "" {
log.Info("is it right here:")
log.Info(dockerVol)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing the 2 comment above were for debugging and should be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops...

if dockerVol.Name != "" {
log.Info("is it right here:")
log.Info(dockerVol)
volumesWithoutHost[dockerVol.Name] = dockerVol
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems this would override the value of a volume name specified in composeVolumes with the value of a vol with the same name specified in ecs-params. In this case, do we want to log a msg like "Using ecs-params values specified for volume %s" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With this PR, there are no fields valid except for name from Compose, so ECS Params is adding fields, not duplicated anything, so at the moment there is no overriding happening. This might change if we support more fields from compose volumes.

ecsVolume := &ecs.Volume{
Name: aws.String(volName),
}
if dVol.Name != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have validation before this that any volume specified in ecs-params includes a Name (or other required fields) ?

Copy link
Contributor

Choose a reason for hiding this comment

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

...and can we add a test for error case(s) handling if/when we do add validation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point

}
options := map[string]string{
"pudding": "is Clyde's best friend",
"clyde": "is too nervous to tell her that he loves her",
Copy link
Contributor

Choose a reason for hiding this comment

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

😭

Copy link
Contributor Author

@PettitWesley PettitWesley Aug 22, 2018

Choose a reason for hiding this comment

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

😉

if dockerVol.Name != "" {
volumesWithoutHost[dockerVol.Name] = dockerVol
} else {
return nil, fmt.Errorf("docker_volume.name is a required field")
Copy link
Contributor

Choose a reason for hiding this comment

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

Since docker_volume.name is not the name of a specific ECS volume field (and the closest volume.name is listed as not required), can we rephrase this err msg to something like: "Name is required when specifying a docker volume" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I'll change it to that. I was thinking that user's would understand that docker_volume.name is the ECS Params yaml.

- name: string
scope: string ("shared" or "task")
autoprovision: boolean (only valid if scope = "shared")
driver: string
Copy link
Contributor

Choose a reason for hiding this comment

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

I was referring to having comments versus parentheticals, e.g. scope: string // Valid values: "shared" | "task"

README.md Outdated
* In Docker compose version 2, the `cpu_shares`, `mem_limit`, and `mem_reservation` fields can be specified in either the compose or ECS params file. If they are specified in the ECS params file, the values will override values present in the compose file.

* `docker_volumes` allows you to create volumes with a [DockerVolumeConfiguration](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-volumes.html). The volumes can be referenced in your compose file by name, even if they were not also specified in the compose file.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this should be moved to after the example, since line 463 says "Example ecs-params.yml with service resources specified:" and it's a little confusing for that to come after the section that talks about docker_volumes when there is no example of docker volumes.

Also, the link you provide here shows the JSON for how to specify dockerVolumeConfiguration as a top-level member of a volume undervolumes, but our schema doesn't seem to quite match that. It might be useful to have a bulleted list that explains each of our fields explicitly if we're breaking from the ECS JSON schema.

Also, can you remind me again why we aren't nesting the relevant fields under the dockerVolumeConfiguration subkey?

Finally, I see in the docs there is field called host. Is that not needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We decided in the design review that docker_volumes looks nicer than having docker_volume_configuration as the key. We also decided that it looked better if all of the fields were under that key, and not to have an extra layer of nesting (which the Task Def does for backwards compatibility with the old volumes and forwards compatibility with any other types of non-docker volumes that could hypothetically be used in the future).

Host is not compatible with docker volume configuration, AFAIK. The ECS docs might actually need to be edited... let me get back to you on this.

- name: my_volume
scope: shared
autoprovision: true
driver: doggyromcom
Copy link
Contributor

Choose a reason for hiding this comment

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

🐶 ❤️ 🐶

for _, volName := range hostPaths.VolumeEmptyHost {

// process docker volumes
dockerVolumes := make(map[string]DockerVolume)
Copy link
Contributor

Choose a reason for hiding this comment

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

dockerVolumes does not appear to be used after it's populated?

Copy link
Contributor Author

@PettitWesley PettitWesley Aug 22, 2018

Choose a reason for hiding this comment

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

oh ughh oops, this is because I originally wrote this as one function and then did a bad job of copy pasting it into the separate function...

}

if ecsParams != nil {
for _, dockerVol := range ecsParams.TaskDefinition.DockerVolumes {
Copy link
Contributor

Choose a reason for hiding this comment

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

This code seems to be a repeat of the code in lines 312-318. Could we extract that code into its own method that just has the responsibility of processing Docker Volumes from the ecs params? Then if you choose to call it before mergeVolumesWithoutHost, you can pass it into that function directly instead of re-parsing it here.

Copy link
Contributor Author

@PettitWesley PettitWesley Aug 22, 2018

Choose a reason for hiding this comment

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

oh ughh oops, this is because I originally wrote this as one function and then did a bad job of copy pasting it into the separate function...

it: does-not-go-well
this: is-not-a-movie
labels:
pudding: mad
Copy link
Contributor

Choose a reason for hiding this comment

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

i mean, i feel like tum tum would be the mad pup in this scenario...🐶

@PettitWesley PettitWesley force-pushed the params-docker-volumes branch from d70b3a0 to a872cfe Compare August 22, 2018 23:03
@PettitWesley
Copy link
Contributor Author

Tested it:

Compose file:

version: '2'
services:
  container1:
    image: nginx
    volumes:
      - shared:/shared
      - notshared:/notshared
      - /var/log:/sharedwithhost
  container2:
    image: nginx
    volumes:
      - shared:/sharedwithmetoo

volumes:
  shared:
  notshared:

ECS Params:

task_definition:
  docker_volumes:
    - name: shared
      scope: shared
      autoprovision: true
      driver: local
      driver_opts:
        some_option: some_value
      labels:
        testing: dockervolumes

Mountpoints on containers:

{
"mountPoints": [
        {
          "readOnly": false,
          "containerPath": "/shared",
          "sourceVolume": "shared"
        },
        {
          "readOnly": false,
          "containerPath": "/notshared",
          "sourceVolume": "notshared"
        },
        {
          "readOnly": false,
          "containerPath": "/sharedwithhost",
          "sourceVolume": "volume-2"
        }
      ],
"name": "container1"
}
...
{
"mountPoints": [
        {
          "readOnly": false,
          "containerPath": "/sharedwithmetoo",
          "sourceVolume": "shared"
        }
      ],
"name": "container2"
}

Task Def Volumes section:

  "volumes": [
    {
      "name": "volume-2",
      "host": {
        "sourcePath": "/var/log"
      },
      "dockerVolumeConfiguration": null
    },
    {
      "name": "notshared",
      "host": {
        "sourcePath": null
      },
      "dockerVolumeConfiguration": null
    },
    {
      "name": "shared",
      "host": null,
      "dockerVolumeConfiguration": {
        "autoprovision": true,
        "labels": {
          "testing": "dockervolumes"
        },
        "scope": "shared",
        "driver": "local",
        "driverOpts": {
          "some_option": "some_value"
        }
      }
    }
  ]

* In Docker compose version 2, the `cpu_shares`, `mem_limit`, and `mem_reservation` fields can be specified in either the compose or ECS params file. If they are specified in the ECS params file, the values will override values present in the compose file.
* If you are using a private repository for pulling images, `repository_credentials` allows you to specify an AWS Secrets Manager secret ARN for the name of the secret containing your private repository credentials as a `credential_parameter`.

Example `ecs-params.yml` with service resources specified:
Copy link
Contributor

Choose a reason for hiding this comment

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

since you're removing this services example, can you add another sub-bullet under services that says something like: "See sample ecs-params.yml below for example uses."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is that really needed? The way it reads right now is that we have the schema, then we have explanations, then we have a bunch of examples. I think that makes complete sense and there doesn't need to be a special bullet under services noting that there are examples for this field.

Copy link
Contributor

Choose a reason for hiding this comment

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

If this is the case of all schema field examples (and not just that you moved or omitted the service one) than I agree it's fine as is.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants