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): cloud deployment fails if root directory contains spaces #7188

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
24 changes: 16 additions & 8 deletions packages/@winglang/sdk/.projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions packages/@winglang/sdk/.projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,16 @@ const project = new cdk.JsiiProject({
// env
"dotenv",
"dotenv-expand",
"adm-zip",
"@types/adm-zip",
"fs-extra",
"@types/fs-extra",
],
devDeps: [
`@cdktf/provider-aws@^19`, // only for testing Wing plugins
"wing-api-checker",
"bump-pack",
"@types/aws-lambda",
"@types/fs-extra",
"@types/mime-types",
"mock-gcs@^1.2.0",
"@types/express",
Expand All @@ -112,7 +115,7 @@ const project = new cdk.JsiiProject({
"[email protected]",
`cdktf-cli@${CDKTF_VERSION}`,
"eslint-plugin-sort-exports",
"fs-extra",

"vitest",
"@types/uuid",
"nanoid", // for ESM import test in target-sim/function.test.ts
Expand Down
10 changes: 8 additions & 2 deletions packages/@winglang/sdk/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 24 additions & 7 deletions packages/@winglang/sdk/src/target-tf-aws/function.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { join } from "path";
import { AssetType, Lazy, TerraformAsset } from "cdktf";
import { Construct } from "constructs";
import { ensureDirSync } from "fs-extra";
import { App } from "./app";
import { CloudwatchLogGroup } from "../.gen/providers/aws/cloudwatch-log-group";
import { IamRole } from "../.gen/providers/aws/iam-role";
Expand All @@ -26,6 +28,7 @@ import {
import { makeAwsLambdaHandler } from "../shared-aws/function-util";
import { IInflightHost, Resource } from "../std";
import { Duration } from "../std/duration";
import AdmZip from "adm-zip";

/**
* Function names are limited to 64 characters.
Expand Down Expand Up @@ -284,15 +287,29 @@ export class Function extends cloud.Function implements IAwsFunction {

const bundle = createBundle(this.entrypoint, externalLibraries);

// would prefer to create TerraformAsset in the constructor, but using a CDKTF token for
// the "path" argument isn't supported
const asset = new TerraformAsset(this, "Asset", {
path: bundle.directory,
type: AssetType.ARCHIVE,
});
if (bundle.directory.includes(" ")) {
//since terraformAsset can't handle file paths that contain spaces- we create the bundle zip manually.
const zip = new AdmZip();
zip.addLocalFolder(bundle.directory);

const folderPath = join(App.of(this).outdir, "assets");
const filename = `${this.node.addr}.zip`;
ensureDirSync(folderPath);
zip.writeZip(join(folderPath, filename));

this.assetPath = join("assets", filename);
} else {
// would prefer to create TerraformAsset in the constructor, but using a CDKTF token for
// the "path" argument isn't supported
const asset = new TerraformAsset(this, "Asset", {
path: bundle.directory,
type: AssetType.ARCHIVE,
});

this.assetPath = asset.path;
}

this.bundleHash = bundle.hash;
this.assetPath = asset.path;
}

/** @internal */
Expand Down
51 changes: 32 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/valid/folder with spaces/main.test.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bring cloud;

let bucket = new cloud.Bucket();

test "Bucket is empty" {
assert(bucket.list().length == 0);
}
Loading
Loading