Repository: pharindoko/cdk-internal-gateway (language: python)

Issue:
A flag to enable/disable copy of website content to s3 bucket
Hi,
Is it possible to add a flag to prevent the source being copied in to s3 bucket. we are using this in code pipeline and everytime we do a commit the s3 bucket hosting website get overwritten. 


Discussion / hints:

Fix patch:
diff --git a/.gitattributes b/.gitattributes
index 63d07f3..69d6eeb 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -16,6 +16,7 @@
 /.projen/deps.json linguist-generated
 /.projen/files.json linguist-generated
 /.projen/tasks.json linguist-generated
+/.vscode/settings.json linguist-generated
 /API.md linguist-generated
 /LICENSE linguist-generated
 /package.json linguist-generated
diff --git a/.gitignore b/.gitignore
index f7f36f1..8f0ef00 100644
--- a/.gitignore
+++ b/.gitignore
@@ -55,3 +55,4 @@ junit.xml
 .jsii
 tsconfig.json
 !/API.md
+!/.vscode/settings.json
diff --git a/.projen/files.json b/.projen/files.json
index 9ee1939..d141928 100644
--- a/.projen/files.json
+++ b/.projen/files.json
@@ -13,6 +13,7 @@
     ".projen/deps.json",
     ".projen/files.json",
     ".projen/tasks.json",
+    ".vscode/settings.json",
     "LICENSE",
     "tsconfig.dev.json"
   ],
diff --git a/.projenrc.js b/.projenrc.js
index 2453cac..ae0486e 100644
--- a/.projenrc.js
+++ b/.projenrc.js
@@ -63,4 +63,13 @@ const project = new awscdk.AwsCdkConstructLibrary({
   majorVersion: 1,
 });
 
+project.vscode.settings.addSettings({
+  "editor.formatOnSave": true,
+  "eslint.format.enable": false,
+  "prettier.enable": true,
+  "[typescript]": {
+    "editor.defaultFormatter": "esbenp.prettier-vscode",
+  },
+});
+
 project.synth();
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..c525f10
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,9 @@
+{
+  "editor.formatOnSave": true,
+  "eslint.format.enable": false,
+  "prettier.enable": true,
+  "[typescript]": {
+    "editor.defaultFormatter": "esbenp.prettier-vscode"
+  },
+  "//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"npx projen\"."
+}
diff --git a/API.md b/API.md
index 2f2cafd..bab1fa5 100644
--- a/API.md
+++ b/API.md
@@ -742,6 +742,7 @@ const internalWebsiteProps: InternalWebsiteProps = { ... }
 | <code><a href="#cdk-internal-gateway.InternalWebsiteProps.property.minimumCompressionSize">minimumCompressionSize</a></code> | <code>number</code> | minimum compression size for the internal api gateway. |
 | <code><a href="#cdk-internal-gateway.InternalWebsiteProps.property.sourcePath">sourcePath</a></code> | <code>string</code> | Path of website folder containing the website`s sources. |
 | <code><a href="#cdk-internal-gateway.InternalWebsiteProps.property.bucketName">bucketName</a></code> | <code>string</code> | Name of s3 bucket to use for the website deployment. |
+| <code><a href="#cdk-internal-gateway.InternalWebsiteProps.property.enableSourceDeployment">enableSourceDeployment</a></code> | <code>boolean</code> | Enable/disable automatic sync of the website`s sources to the S3bucket. |
 | <code><a href="#cdk-internal-gateway.InternalWebsiteProps.property.websiteIndexDocument">websiteIndexDocument</a></code> | <code>string</code> | Name of html index document used for the website. |
 
 ---
@@ -844,6 +845,19 @@ Name of s3 bucket to use for the website deployment.
 
 ---
 
+##### `enableSourceDeployment`<sup>Optional</sup> <a name="enableSourceDeployment" id="cdk-internal-gateway.InternalWebsiteProps.property.enableSourceDeployment"></a>
+
+```typescript
+public readonly enableSourceDeployment: boolean;
+```
+
+- *Type:* boolean
+- *Default:* true
+
+Enable/disable automatic sync of the website`s sources to the S3bucket.
+
+---
+
 ##### `websiteIndexDocument`<sup>Optional</sup> <a name="websiteIndexDocument" id="cdk-internal-gateway.InternalWebsiteProps.property.websiteIndexDocument"></a>
 
 ```typescript
diff --git a/src/internal-website.ts b/src/internal-website.ts
index 8771216..b90bbd6 100644
--- a/src/internal-website.ts
+++ b/src/internal-website.ts
@@ -17,6 +17,13 @@ import {
  * Properties for InternalService
  */
 export interface InternalWebsiteProps extends InternalApiGatewayProps {
+  /**
+   * Enable/disable automatic sync of the website`s sources to the S3bucket
+   *
+   * @default true
+   */
+  readonly enableSourceDeployment?: boolean;
+
   /**
    * Path of website folder containing the website`s sources
    */
@@ -49,10 +56,14 @@ export class InternalWebsite extends InternalApiGateway {
       autoDeleteObjects: true,
     });
 
-    new s3deploy.BucketDeployment(this, `WebsiteDeployment-${id}`, {
-      sources: [s3deploy.Source.asset(path.normalize(props.sourcePath))],
-      destinationBucket: bucket,
-    });
+    const enableSourceDeployment = props.enableSourceDeployment ?? true;
+
+    if (enableSourceDeployment) {
+      new s3deploy.BucketDeployment(this, `WebsiteDeployment-${id}`, {
+        sources: [s3deploy.Source.asset(path.normalize(props?.sourcePath))],
+        destinationBucket: bucket,
+      });
+    }
 
     const role = new iam.Role(this, `ApiGatewayReadOnlyRole-${id}`, {
       assumedBy: new iam.ServicePrincipal("apigateway.amazonaws.com"),


Test patch:
diff --git a/test/internal-website.test.ts b/test/internal-website.test.ts
index 5a72a10..8dfcebb 100644
--- a/test/internal-website.test.ts
+++ b/test/internal-website.test.ts
@@ -1053,6 +1053,27 @@ test("Internal Website provider - set default values", () => {
       },
     }
   `);
+
+  template.resourcePropertiesCountIs(
+    "Custom::CDKBucketDeployment",
+    Match.objectLike({
+      ServiceToken: {
+        "Fn::GetAtt": [
+          "CustomCDKBucketDeployment8693BB64968944B69AAFB0CC9EB8756C81C01536",
+          "Arn",
+        ],
+      },
+      SourceBucketNames: ["cdk-hnb659fds-assets-123456789012-us-east-1"],
+      SourceObjectKeys: [
+        "387c754ea2daf522842e23f74232b2c455937afe2e90e7c8d173275b0706342a.zip",
+      ],
+      DestinationBucketName: {
+        Ref: "internalGatewayStackWebsiteBucketinternalGatewayStackBF609A09",
+      },
+      Prune: true,
+    }),
+    1
+  );
 });
 
 test("Api Gateway Stack provider - set optional parameters", () => {
@@ -1063,6 +1084,7 @@ test("Api Gateway Stack provider - set optional parameters", () => {
     sourcePath: "./test/website-sample",
     websiteIndexDocument: "test.html",
     bucketName: "test-bucket",
+    enableSourceDeployment: false,
   });
 
   const template = Template.fromStack(stack);
@@ -1075,6 +1097,27 @@ test("Api Gateway Stack provider - set optional parameters", () => {
     })
   );
 
+  template.resourcePropertiesCountIs(
+    "Custom::CDKBucketDeployment",
+    Match.objectLike({
+      ServiceToken: {
+        "Fn::GetAtt": [
+          "CustomCDKBucketDeployment8693BB64968944B69AAFB0CC9EB8756C81C01536",
+          "Arn",
+        ],
+      },
+      SourceBucketNames: ["cdk-hnb659fds-assets-123456789012-us-east-1"],
+      SourceObjectKeys: [
+        "387c754ea2daf522842e23f74232b2c455937afe2e90e7c8d173275b0706342a.zip",
+      ],
+      DestinationBucketName: {
+        Ref: "internalApiGatewayStackOptionalParametersWebsiteBucketinternalApiGatewayStackOptionalParameters2269B1C9",
+      },
+      Prune: true,
+    }),
+    0
+  );
+
   template.hasResourceProperties(
     "AWS::S3::Bucket",
     Match.objectLike({