Skip to content

Commit ed14638

Browse files
SoManyHsrix0rrr
authored andcommitted
fix: Remove DockerHub constructor class (#1153)
We always recommended using `ContainerImage.fromDockerHub()` in the README, but examples were still showing the old syntax. BREAKING CHANGE: If you were using `DockerHub.image()` to reference docker hub images, use `ContainerImage.fromDockerHub()` instead.
1 parent fbb091a commit ed14638

File tree

13 files changed

+55
-65
lines changed

13 files changed

+55
-65
lines changed

examples/cdk-examples-typescript/hello-cdk-ecs/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ class BonjourECS extends cdk.Stack {
2222
const ecsService = new ecs.LoadBalancedEc2Service(this, "Ec2Service", {
2323
cluster,
2424
memoryLimitMiB: 512,
25-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
25+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
2626
});
2727

28+
// ecsService.addTracing
29+
2830
// Output the DNS where you can access your service
2931
new cdk.Output(this, 'LoadBalancerDNS', { value: ecsService.loadBalancer.dnsName });
3032
}

examples/cdk-examples-typescript/hello-cdk-fargate/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class BonjourFargate extends cdk.Stack {
1414
// Instantiate Fargate Service with just cluster and image
1515
const fargateService = new ecs.LoadBalancedFargateService(this, "FargateService", {
1616
cluster,
17-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
17+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
1818
});
1919

2020
// Output the DNS where you can access your service

packages/@aws-cdk/aws-ecs/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ const taskDefinition = new ecs.TaskDefinition(this, 'TaskDef', {
166166
#### Images
167167

168168
Images supply the software that runs inside the container. Images can be
169-
obtained from either DockerHub or from ECR repositories:
169+
obtained from either DockerHub or from ECR repositories, or built directly from a local Dockerfile.
170170

171171
* `ecs.ContainerImage.fromDockerHub(imageName)`: use a publicly available image from
172172
DockerHub.
173-
* `ecs.ContaienrImage.fromEcrRepository(repo, tag)`: use the given ECR repository as the image
174-
to start.
173+
* `ecs.ContainerImage.fromEcrRepository(repo, tag)`: use the given ECR repository as the image
174+
to start. If no tag is provided, "latest" is assumed.
175175
* `ecs.ContainerImage.fromAsset(this, 'Image', { directory: './image' })`: build and upload an
176176
image directly from a `Dockerfile` in your source directory.
177177

@@ -240,4 +240,4 @@ EC2 instance group so that your instance count scales with demand.
240240

241241
- [ ] Instance AutoScaling
242242
- [ ] Service Discovery Integration
243-
- [ ] Private registry authentication
243+
- [ ] Private registry authentication

packages/@aws-cdk/aws-ecs/lib/images/dockerhub.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
import { ContainerDefinition } from "../container-definition";
22
import { IContainerImage } from "../container-image";
33

4-
/**
5-
* Factory for DockerHub images
6-
*/
7-
export class DockerHub {
8-
/**
9-
* Reference an image on DockerHub
10-
*/
11-
public static image(name: string): IContainerImage {
12-
return new DockerHubImage(name);
13-
}
14-
}
15-
164
/**
175
* A DockerHub image
186
*/

packages/@aws-cdk/aws-ecs/lib/load-balanced-fargate-service-applet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ec2 = require('@aws-cdk/aws-ec2');
22
import cdk = require('@aws-cdk/cdk');
33
import { Cluster } from './cluster';
4-
import { DockerHub } from './images/dockerhub';
4+
import { ContainerImage } from './container-image';
55
import { LoadBalancedFargateService } from './load-balanced-fargate-service';
66

77
/**
@@ -97,7 +97,7 @@ export class LoadBalancedFargateServiceApplet extends cdk.Stack {
9797
memoryMiB: props.memoryMiB,
9898
publicLoadBalancer: props.publicLoadBalancer,
9999
publicTasks: props.publicTasks,
100-
image: DockerHub.image(props.image),
100+
image: ContainerImage.fromDockerHub(props.image),
101101
desiredCount: props.desiredCount,
102102
});
103103
}

packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-awsvpc-nw.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TaskDef', {
1919
});
2020

2121
const container = taskDefinition.addContainer('web', {
22-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
22+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
2323
memoryLimitMiB: 256,
2424
});
2525

@@ -42,4 +42,4 @@ listener.addTargets('ECS', {
4242

4343
new cdk.Output(stack, 'LoadBalancerDNS', { value: lb.dnsName, });
4444

45-
app.run();
45+
app.run();

packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-bridge-nw.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TaskDef', {
2121
});
2222

2323
const container = taskDefinition.addContainer('web', {
24-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
24+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
2525
memoryLimitMiB: 256,
2626
});
2727
container.addPortMappings({

packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-service.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export = {
1717
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef');
1818

1919
taskDefinition.addContainer("web", {
20-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
20+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
2121
memoryLimitMiB: 512
2222
});
2323

@@ -97,7 +97,7 @@ export = {
9797
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef');
9898

9999
taskDefinition.addContainer("web", {
100-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
100+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
101101
memoryLimitMiB: 512
102102
});
103103

@@ -127,7 +127,7 @@ export = {
127127
});
128128

129129
taskDefinition.addContainer("web", {
130-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
130+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
131131
memoryLimitMiB: 512
132132
});
133133

@@ -159,7 +159,7 @@ export = {
159159
});
160160

161161
taskDefinition.addContainer("web", {
162-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
162+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
163163
memoryLimitMiB: 512
164164
});
165165

@@ -210,7 +210,7 @@ export = {
210210
});
211211

212212
taskDefinition.addContainer("web", {
213-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
213+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
214214
memoryLimitMiB: 512
215215
});
216216

@@ -236,7 +236,7 @@ export = {
236236
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef');
237237

238238
taskDefinition.addContainer("web", {
239-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
239+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
240240
memoryLimitMiB: 512
241241
});
242242

@@ -265,7 +265,7 @@ export = {
265265
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef');
266266

267267
taskDefinition.addContainer("web", {
268-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
268+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
269269
memoryLimitMiB: 512
270270
});
271271

@@ -296,7 +296,7 @@ export = {
296296
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef');
297297

298298
taskDefinition.addContainer("web", {
299-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
299+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
300300
memoryLimitMiB: 512
301301
});
302302

@@ -327,7 +327,7 @@ export = {
327327
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef');
328328

329329
taskDefinition.addContainer("web", {
330-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
330+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
331331
memoryLimitMiB: 512
332332
});
333333

@@ -354,7 +354,7 @@ export = {
354354
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef');
355355

356356
taskDefinition.addContainer("web", {
357-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
357+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
358358
memoryLimitMiB: 512
359359
});
360360

@@ -384,7 +384,7 @@ export = {
384384
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef');
385385

386386
taskDefinition.addContainer("web", {
387-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
387+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
388388
memoryLimitMiB: 512
389389
});
390390

@@ -411,7 +411,7 @@ export = {
411411
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef');
412412

413413
taskDefinition.addContainer("web", {
414-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
414+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
415415
memoryLimitMiB: 512
416416
});
417417

@@ -442,7 +442,7 @@ export = {
442442
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef');
443443

444444
taskDefinition.addContainer("web", {
445-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
445+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
446446
memoryLimitMiB: 512
447447
});
448448

@@ -470,7 +470,7 @@ export = {
470470
cluster.addDefaultAutoScalingGroupCapacity({ instanceType: new ec2.InstanceType('t2.micro') });
471471
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TD', { networkMode: ecs.NetworkMode.Host });
472472
const container = taskDefinition.addContainer('web', {
473-
image: ecs.DockerHub.image('test'),
473+
image: ecs.ContainerImage.fromDockerHub('test'),
474474
memoryLimitMiB: 1024,
475475
});
476476
container.addPortMappings({ containerPort: 808 });

packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-task-definition.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export = {
4848
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef');
4949

5050
const container = taskDefinition.addContainer("web", {
51-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
51+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
5252
memoryLimitMiB: 512 // add validation?
5353
});
5454

@@ -104,7 +104,7 @@ export = {
104104
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef');
105105

106106
const container = taskDefinition.addContainer("web", {
107-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
107+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
108108
memoryLimitMiB: 512
109109
});
110110

@@ -154,7 +154,7 @@ export = {
154154
});
155155

156156
const container = taskDefinition.addContainer("web", {
157-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
157+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
158158
memoryLimitMiB: 512
159159
});
160160

@@ -200,7 +200,7 @@ export = {
200200

201201
taskDefinition.addContainer("web", {
202202
memoryLimitMiB: 1024,
203-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample")
203+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample")
204204
});
205205

206206
// THEN
@@ -226,7 +226,7 @@ export = {
226226
// });
227227

228228
// taskDefinition.addContainer("web", {
229-
// image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
229+
// image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
230230
// memoryLimitMiB: 512
231231
// });
232232

@@ -243,7 +243,7 @@ export = {
243243
// const stack = new cdk.Stack();
244244
// const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef', {});
245245
// const container = taskDefinition.addContainer("web", {
246-
// image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
246+
// image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
247247
// memoryLimitMiB: 512 // add validation?
248248
// });
249249

packages/@aws-cdk/aws-ecs/test/fargate/integ.lb-awsvpc-nw.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const taskDefinition = new ecs.FargateTaskDefinition(stack, 'TaskDef', {
1616
});
1717

1818
const container = taskDefinition.addContainer('web', {
19-
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"),
19+
image: ecs.ContainerImage.fromDockerHub("amazon/amazon-ecs-sample"),
2020
});
2121

2222
container.addPortMappings({

0 commit comments

Comments
 (0)