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

fix(sdk): fix cloud.website not deploying s3 objects changes for tf-aws target #3778

Merged
merged 4 commits into from
Aug 11, 2023
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
2 changes: 2 additions & 0 deletions libs/wingsdk/src/target-tf-aws/website.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { readdirSync } from "fs";
import { extname, join, posix, resolve, sep } from "path";

import { Fn } from "cdktf";
import { Construct } from "constructs";
import mime from "mime-types";
import { createEncryptedBucket } from "./bucket";
Expand Down Expand Up @@ -159,6 +160,7 @@ export class Website extends cloud.Website {
key: this.formatPath(filePath.replace(this.path, "")),
bucket: this.bucket.bucket,
source: resolve(filePath),
sourceHash: Fn.filemd5(resolve(filePath)),
contentType: mime.contentType(extname(filePath)) || undefined,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ exports[`default website behavior 1`] = `
\\"aws_s3_bucket.Website_WebsiteBucket_3C0321F0\\"
],
\\"key\\": \\"/b.html\\",
\\"source\\": \\"<source>\\"
\\"source\\": \\"<source>\\",
\\"source_hash\\": \\"\${filemd5(\\\\\\"/home/runner/work/wing/wing/libs/wingsdk/test/target-tf-aws/website/b.html\\\\\\")}\\"
},
\\"Website_File--inner-folder--ahtml_7D20A7EF\\": {
\\"bucket\\": \\"\${aws_s3_bucket.Website_WebsiteBucket_3C0321F0.bucket}\\",
Expand All @@ -152,7 +153,8 @@ exports[`default website behavior 1`] = `
\\"aws_s3_bucket.Website_WebsiteBucket_3C0321F0\\"
],
\\"key\\": \\"/inner-folder/a.html\\",
\\"source\\": \\"<source>\\"
\\"source\\": \\"<source>\\",
\\"source_hash\\": \\"\${filemd5(\\\\\\"/home/runner/work/wing/wing/libs/wingsdk/test/target-tf-aws/website/inner-folder/a.html\\\\\\")}\\"
}
}
}
Expand Down Expand Up @@ -477,7 +479,8 @@ exports[`website with add_json 1`] = `
\\"aws_s3_bucket.Website_WebsiteBucket_3C0321F0\\"
],
\\"key\\": \\"/b.html\\",
\\"source\\": \\"<source>\\"
\\"source\\": \\"<source>\\",
\\"source_hash\\": \\"\${filemd5(\\\\\\"/home/runner/work/wing/wing/libs/wingsdk/test/target-tf-aws/website/b.html\\\\\\")}\\"
},
\\"Website_File--inner-folder--ahtml_7D20A7EF\\": {
\\"bucket\\": \\"\${aws_s3_bucket.Website_WebsiteBucket_3C0321F0.bucket}\\",
Expand All @@ -486,7 +489,8 @@ exports[`website with add_json 1`] = `
\\"aws_s3_bucket.Website_WebsiteBucket_3C0321F0\\"
],
\\"key\\": \\"/inner-folder/a.html\\",
\\"source\\": \\"<source>\\"
\\"source\\": \\"<source>\\",
\\"source_hash\\": \\"\${filemd5(\\\\\\"/home/runner/work/wing/wing/libs/wingsdk/test/target-tf-aws/website/inner-folder/a.html\\\\\\")}\\"
},
\\"Website_File-configjson_1F1498B9\\": {
\\"bucket\\": \\"\${aws_s3_bucket.Website_WebsiteBucket_3C0321F0.bucket}\\",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ module.exports = function({ $http_Util, $w1_url, $w2_url }) {
"variables": {
"WING_FUNCTION_NAME": "Handler-c8683851",
"WING_TARGET": "tf-aws",
"WING_TOKEN_TFTOKEN_TOKEN_14": "${jsonencode(aws_cloudfront_distribution.cloudWebsite_Distribution_083B5AF9.domain_name)}",
"WING_TOKEN_TFTOKEN_TOKEN_28": "${jsonencode(aws_cloudfront_distribution.website-2_Distribution_F1FA4680.domain_name)}"
"WING_TOKEN_TFTOKEN_TOKEN_16": "${jsonencode(aws_cloudfront_distribution.cloudWebsite_Distribution_083B5AF9.domain_name)}",
"WING_TOKEN_TFTOKEN_TOKEN_32": "${jsonencode(aws_cloudfront_distribution.website-2_Distribution_F1FA4680.domain_name)}"
}
},
"function_name": "Handler-c8683851",
Expand Down Expand Up @@ -477,7 +477,8 @@ module.exports = function({ $http_Util, $w1_url, $w2_url }) {
"aws_s3_bucket.cloudWebsite_WebsiteBucket_EB03D355"
],
"key": "/index.html",
"source": "<SOURCE>"
"source": "<SOURCE>",
"source_hash": "${filemd5(<SOURCE>)}"
},
"cloudWebsite_File--inner-folder--otherhtml_72DA631C": {
"//": {
Expand All @@ -492,7 +493,8 @@ module.exports = function({ $http_Util, $w1_url, $w2_url }) {
"aws_s3_bucket.cloudWebsite_WebsiteBucket_EB03D355"
],
"key": "/inner-folder/other.html",
"source": "<SOURCE>"
"source": "<SOURCE>",
"source_hash": "${filemd5(<SOURCE>)}"
},
"testdeployingtwowebsites_Handler_S3Object_E54888BB": {
"//": {
Expand All @@ -518,7 +520,8 @@ module.exports = function({ $http_Util, $w1_url, $w2_url }) {
"aws_s3_bucket.website-2_WebsiteBucket_59576A0C"
],
"key": "/index.html",
"source": "<SOURCE>"
"source": "<SOURCE>",
"source_hash": "${filemd5(<SOURCE>)}"
},
"website-2_File--inner-folder--otherhtml_2D74B50A": {
"//": {
Expand All @@ -533,7 +536,8 @@ module.exports = function({ $http_Util, $w1_url, $w2_url }) {
"aws_s3_bucket.website-2_WebsiteBucket_59576A0C"
],
"key": "/inner-folder/other.html",
"source": "<SOURCE>"
"source": "<SOURCE>",
"source_hash": "${filemd5(<SOURCE>)}"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ module.exports = function({ }) {
"variables": {
"WING_FUNCTION_NAME": "Handler-c867c4e0",
"WING_TARGET": "tf-aws",
"WING_TOKEN_TFTOKEN_TOKEN_14": "${jsonencode(aws_cloudfront_distribution.cloudWebsite_Distribution_083B5AF9.domain_name)}"
"WING_TOKEN_TFTOKEN_TOKEN_16": "${jsonencode(aws_cloudfront_distribution.cloudWebsite_Distribution_083B5AF9.domain_name)}"
}
},
"function_name": "Handler-c867c4e0",
Expand Down Expand Up @@ -328,7 +328,8 @@ module.exports = function({ }) {
"aws_s3_bucket.cloudWebsite_WebsiteBucket_EB03D355"
],
"key": "/index.html",
"source": "<SOURCE>"
"source": "<SOURCE>",
"source_hash": "${filemd5(<SOURCE>)}"
},
"cloudWebsite_File--inner-folder--otherhtml_72DA631C": {
"//": {
Expand All @@ -343,7 +344,8 @@ module.exports = function({ }) {
"aws_s3_bucket.cloudWebsite_WebsiteBucket_EB03D355"
],
"key": "/inner-folder/other.html",
"source": "<SOURCE>"
"source": "<SOURCE>",
"source_hash": "${filemd5(<SOURCE>)}"
},
"cloudWebsite_File-configjson_591A81BA": {
"//": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ module.exports = function({ }) {
},
"rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}",
"triggers": {
"redeployment": "cdd4e9e04bfdff956629a1812b4cef862849e475"
"redeployment": "53d34a77ebc006529cbee88240e663619396c753"
}
}
},
Expand Down Expand Up @@ -611,7 +611,8 @@ module.exports = function({ }) {
"aws_s3_bucket.cloudWebsite_WebsiteBucket_EB03D355"
],
"key": "/index.html",
"source": "<SOURCE>"
"source": "<SOURCE>",
"source_hash": "${filemd5(<SOURCE>)}"
},
"cloudWebsite_File-configjson_591A81BA": {
"//": {
Expand Down
5 changes: 4 additions & 1 deletion tools/hangar/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ export function sanitize_json_paths(path: string) {
const assetKeyRegex = /"asset\..+?"/g;
const assetSourceRegex = /"assets\/.+?"/g;
const sourceRegex = /(?<=\"source\"\:)\"([A-Z]:|\/|\\)[\/\\\-\w\.]+\"/g;
const sourceHashRegex =
/(?<=\"source_hash\"\:)\"\${filemd5\(\\\"([A-Z]:|\/|\\)[\/\\\-\w\.]+\\\"\)}\"/g;
const json = JSON.parse(fs.readFileSync(path, "utf-8"));

const jsonText = JSON.stringify(json);
const sanitizedJsonText = jsonText
.replace(assetKeyRegex, '"<ASSET_KEY>"')
.replace(assetSourceRegex, '"<ASSET_SOURCE>"')
.replace(sourceRegex, '"<SOURCE>"');
.replace(sourceRegex, '"<SOURCE>"')
.replace(sourceHashRegex, '"${filemd5(<SOURCE>)}"');
const finalObj = JSON.parse(sanitizedJsonText);
delete finalObj.terraform;

Expand Down
Loading