Skip to content

Commit

Permalink
feat(aws-ecs): add additional configuration to Volume (#1357)
Browse files Browse the repository at this point in the history
  • Loading branch information
cohalz authored and rix0rrr committed Jan 15, 2019
1 parent e291d37 commit ff96f3f
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 3 deletions.
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;
}

/**
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
*/
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();
},

}
};

0 comments on commit ff96f3f

Please sign in to comment.