-
Notifications
You must be signed in to change notification settings - Fork 125
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
Functions 7452: Bundling and uploading wasm file to GCS for function extension #4445
base: main
Are you sure you want to change the base?
Conversation
Thanks for your contribution! Depending on what you are working on, you may want to request a review from a Shopify team:
|
e0c4923
to
8c1179a
Compare
} | ||
|
||
await this.build(options) | ||
|
||
if (this.isFunctionExtension) { | ||
await copyFile(this.outputPath, joinPath(bundleDirectory, extensionId, 'index.wasm')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copying the wasm file generated from the function's dist
directory to the bundleDirectory for it to get zipped and uploaded later.
@@ -243,7 +243,7 @@ describe('deploy', () => { | |||
expect(updateAppIdentifiers).toHaveBeenCalledOnce() | |||
}) | |||
|
|||
test('uploads the extension bundle with 1 function', async () => { | |||
test('uploads the extension bundle with 1 function extension', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping the test names consistent.
@@ -290,7 +290,7 @@ describe('deploy', () => { | |||
], | |||
developerPlatformClient, | |||
extensionIds: {}, | |||
bundlePath: undefined, | |||
bundlePath: expect.stringMatching(/bundle.zip$/), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bundle path now has a zip file for functions' assets.
ad36761
to
04ce5e5
Compare
04ce5e5
to
c5a48a8
Compare
Coverage report
Show files with reduced coverage 🔻
Test suite run success1891 tests passing in 857 suites. Report generated by 🧪jest coverage report action from c1c12ea |
We detected some changes at either packages/*/src or packages/cli-kit/assets/cli-ruby/** and there are no updates in the .changeset. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great! My comments are mostly around Isaac's concerns 😄
a53dfe6
to
16a1fca
Compare
if (extension.isJavaScript) { | ||
await runCommandOrBuildJSFunction(extension, options) | ||
} else { | ||
await buildOtherFunction(extension, options) | ||
} | ||
if (fileExistsSync(extension.outputPath)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to add this if condition because I see there are tests like succeeds when is a JS function and build command is not present
so I assume thats the intention.
16a1fca
to
c1c12ea
Compare
@@ -141,11 +142,18 @@ export async function buildFunctionExtension( | |||
} | |||
|
|||
try { | |||
const bundlePath = joinPath(extension.outputPath.split('/').slice(0, -2).join('/'), 'index.wasm') | |||
extension.outputPath = joinPath(extension.directory, joinPath('dist', 'function.wasm')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This little dance avoids isFunctionExtension?
in build
.
...config, | ||
serialized_script: encodedFile, | ||
}), | ||
config: JSON.stringify(draftableConfig), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean we can remove the custom wasm update then? or are we waiting until this is released and used for a bit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the latter!
@@ -107,4 +107,35 @@ describe('bundleAndBuildExtensions', () => { | |||
await expect(file.fileExists(bundlePath)).resolves.toBeTruthy() | |||
}) | |||
}) | |||
|
|||
test('creates a zip file with wasm file in it for a function extension', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are not really testing that the zip file includes a wasm file no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I really tried to unzip it and assert on the contents but would need to install some libraries for unzipping so I let it be. I did do end to end testing so I think just asserting a zip got generated here is sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is a good way to unzip files in cli? I didn't find any prior art for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decided to remove reference to wasm file in the test title.
if (fileExistsSync(extension.outputPath)) { | ||
const base64Contents = await readFile(extension.outputPath, {encoding: 'base64'}) | ||
await touchFile(bundlePath) | ||
await writeFile(bundlePath, base64Contents) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tested if you need the touchFile
line or is enough with writeFile
? (I don't think writeFile needs the file to exist, but I might be wrong)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do, it was complaining no such file or directory exists without it so I had to add it.
c1c12ea
to
4c9da9a
Compare
Issue: https://github.com/Shopify/script-service/issues/7452
WHY are these changes introduced?
To have a consistent way of uploading and obtaining extension data is core using the App Module Framework.
WHAT is this pull request doing?
This PR adds the "bundling" feature to functions and sets the output path for compilation to the bundle directory to ensure the wasm file generated is zipped and uploaded to GCS like every other extension.
The deployment plan is:
This version of CLI goes out which bundles the wasm file and uploads it (existing wasm blob upload stays in place).
Then on Core's side we verify we are able to obtain the wasm content and upload it to our runtime-engine bucket. Then we come back here and delete the uploadWasmBlob path and in core we throw an error when we fail to upload. TLDR: existing upload path stays in place till we can verify new path works.
How to test your changes?
pnpm run shopify app deploy --path [path to your app]
from cliUUID.wasm
type name of the file uploaded to the staging bucket. It should match your UUID in the previous step.pnpm run shopify app dev --path [path to your functions app]
from cli and ensure the wasm file is present in the staging bucket.Post-release steps
Measuring impact
How do we know this change was effective? Please choose one:
Checklist