1 | ;
|
2 | var _a;
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | exports.TagParameterContainerImage = void 0;
|
5 | const jsiiDeprecationWarnings = require("../../.warnings.jsii.js");
|
6 | const JSII_RTTI_SYMBOL_1 = Symbol.for("jsii.rtti");
|
7 | const cdk = require("@aws-cdk/core");
|
8 | const container_image_1 = require("../container-image");
|
9 | /**
|
10 | * A special type of {@link ContainerImage} that uses an ECR repository for the image,
|
11 | * but a CloudFormation Parameter for the tag of the image in that repository.
|
12 | * This allows providing this tag through the Parameter at deploy time,
|
13 | * for example in a CodePipeline that pushes a new tag of the image to the repository during a build step,
|
14 | * and then provides that new tag through the CloudFormation Parameter in the deploy step.
|
15 | *
|
16 | * @see #tagParameterName
|
17 | */
|
18 | class TagParameterContainerImage extends container_image_1.ContainerImage {
|
19 | constructor(repository) {
|
20 | super();
|
21 | this.repository = repository;
|
22 | }
|
23 | bind(scope, containerDefinition) {
|
24 | try {
|
25 | jsiiDeprecationWarnings._aws_cdk_aws_ecs_ContainerDefinition(containerDefinition);
|
26 | }
|
27 | catch (error) {
|
28 | if (process.env.JSII_DEBUG !== "1" && error.name === "DeprecationError") {
|
29 | Error.captureStackTrace(error, this.bind);
|
30 | }
|
31 | throw error;
|
32 | }
|
33 | this.repository.grantPull(containerDefinition.taskDefinition.obtainExecutionRole());
|
34 | const imageTagParameter = new cdk.CfnParameter(scope, 'ImageTagParam');
|
35 | this.imageTagParameter = imageTagParameter;
|
36 | return {
|
37 | imageName: this.repository.repositoryUriForTag(imageTagParameter.valueAsString),
|
38 | };
|
39 | }
|
40 | /**
|
41 | * Returns the name of the CloudFormation Parameter that represents the tag of the image
|
42 | * in the ECR repository.
|
43 | */
|
44 | get tagParameterName() {
|
45 | return cdk.Lazy.string({
|
46 | produce: () => {
|
47 | if (this.imageTagParameter) {
|
48 | return this.imageTagParameter.logicalId;
|
49 | }
|
50 | else {
|
51 | throw new Error('TagParameterContainerImage must be used in a container definition when using tagParameterName');
|
52 | }
|
53 | },
|
54 | });
|
55 | }
|
56 | /**
|
57 | * Returns the value of the CloudFormation Parameter that represents the tag of the image
|
58 | * in the ECR repository.
|
59 | */
|
60 | get tagParameterValue() {
|
61 | return cdk.Lazy.string({
|
62 | produce: () => {
|
63 | if (this.imageTagParameter) {
|
64 | return this.imageTagParameter.valueAsString;
|
65 | }
|
66 | else {
|
67 | throw new Error('TagParameterContainerImage must be used in a container definition when using tagParameterValue');
|
68 | }
|
69 | },
|
70 | });
|
71 | }
|
72 | }
|
73 | exports.TagParameterContainerImage = TagParameterContainerImage;
|
74 | _a = JSII_RTTI_SYMBOL_1;
|
75 | TagParameterContainerImage[_a] = { fqn: "@aws-cdk/aws-ecs.TagParameterContainerImage", version: "1.204.0" };
|
76 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFnLXBhcmFtZXRlci1jb250YWluZXItaW1hZ2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJ0YWctcGFyYW1ldGVyLWNvbnRhaW5lci1pbWFnZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFDQSxxQ0FBcUM7QUFFckMsd0RBQTBFO0FBTTFFOzs7Ozs7OztHQVFHO0FBQ0gsTUFBYSwwQkFBMkIsU0FBUSxnQ0FBYztJQUk1RCxZQUFtQixVQUEyQjtRQUM1QyxLQUFLLEVBQUUsQ0FBQztRQUNSLElBQUksQ0FBQyxVQUFVLEdBQUcsVUFBVSxDQUFDO0tBQzlCO0lBRU0sSUFBSSxDQUFDLEtBQWdCLEVBQUUsbUJBQXdDOzs7Ozs7Ozs7O1FBQ3BFLElBQUksQ0FBQyxVQUFVLENBQUMsU0FBUyxDQUFDLG1CQUFtQixDQUFDLGNBQWMsQ0FBQyxtQkFBbUIsRUFBRSxDQUFDLENBQUM7UUFDcEYsTUFBTSxpQkFBaUIsR0FBRyxJQUFJLEdBQUcsQ0FBQyxZQUFZLENBQUMsS0F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