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

feat(aws-ecs): Added dockerVolumeConfiguration to Volume #1357

Merged
merged 7 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 51 additions & 3 deletions packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class TaskDefinition extends cdk.Construct {
/**
* All volumes
*/
private readonly volumes: CfnTaskDefinition.VolumeProperty[] = [];
private readonly volumes: Volume[] = [];

/**
* Execution role for this task definition
Expand Down Expand Up @@ -345,8 +345,12 @@ export interface Volume {
/**
* A name for the volume
*/
name?: string;
// FIXME add dockerVolumeConfiguration
name: string;

/**
* Specifies this configuration when using Docker volumes
*/
dockerVolumeConfiguration?: DockerVolumeConfiguration;
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 it makes sense to have these inline in the Volume struct.

As well as, why are the name and the configuration optional? Does it make sense to leave them optional?

I know @SoManyHs was working on a higher-level abstraction over volumes, so I'd like her to weigh in as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I will out of the office until the new year, but will try to take a look as soon as I can.

}

/**
Expand All @@ -359,6 +363,50 @@ export interface Host {
sourcePath?: string;
}

/**
* A configuration of a Docker volume
*/
export interface DockerVolumeConfiguration {
/**
* If true, the Docker volume is created if it does not already exist
*
* @default false
*/
autoprovision?: boolean;
/**
* The Docker volume driver to use
*/
cohalz marked this conversation as resolved.
Show resolved Hide resolved
driver: string;
/**
* A map of Docker driver specific options passed through
*
* @default No options
*/
driverOpts?: string[];
/**
* Custom metadata to add to your Docker volume
*
* @default No labels
*/
labels?: string[];
/**
* The scope for the Docker volume which determines it's lifecycle
*/
scope: Scope;
}

export enum Scope {
/**
* Docker volumes are automatically provisioned when the task starts and destroyed when the task stops
*/
Task = "task",

/**
* Docker volumes are persist after the task stops
*/
Shared = "shared"
}

/**
* A constraint on how instances should be placed
*/
Expand Down
36 changes: 36 additions & 0 deletions packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-task-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,41 @@ export = {

test.done();
},

"correctly sets dockerVolumeConfiguration"(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const volume = {
name: "scratch",
dockerVolumeConfiguration: {
driver: "local",
scope: ecs.Scope.Task
}
};

const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef', {
volumes: [volume]
});

taskDefinition.addContainer("web", {
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
memoryLimitMiB: 512
});

// THEN
expect(stack).to(haveResourceLike("AWS::ECS::TaskDefinition", {
Family: "Ec2TaskDef",
Volumes: [{
Name: "scratch",
DockerVolumeConfiguration: {
Driver: "local",
Scope: 'task'
}
}]
}));

test.done();
},

}
};