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

feat: allow to use custom LLRT binary with llrtBinaryPath #12

Merged
merged 8 commits into from
Dec 3, 2024

Conversation

georeeve
Copy link
Contributor

Adds a llrtCustomBinaryDirectory property to allow users to use their own LLRT bootstrap binary.

This could be implemented in a few different ways. I tried to keep as much of the existing solution as possible:
If llrtCustomBinaryDirectory is set, it looks for a "bootstrap" binary in that directory, and errors if it cannot find one.
If llrtCustomBinaryDirectory is not set, the binary is downloaded from GitHub and cached in the .tmp directory as before.

@tmokmss
Copy link
Owner

tmokmss commented Nov 21, 2024

@georeeve hi thanks for the PR! to clarify, what is the usecase for this feature? (Why do you want to configure the cache directory?) Thanks.

@georeeve
Copy link
Contributor Author

georeeve commented Nov 21, 2024

@tmokmss Hi, sorry if I didn't make it clear in the docs. My use case was that I wanted to test out a commit from LLRT's main branch, so I built the bootstrap binary locally. I then wanted to deploy this in my stack. I could have tricked LLRT CDK into deploying the binary by saving it as the .tmp/llrt/v0.3.0-beta/arm64/standard/bootstrap file, but thought that that was a bit of a hack and it'd make more sense to make a specific property for it.

So with this PR, you can set llrtCustomBinaryDirectory to .llrt for example, and then you only need to save it as .llrt/bootstrap. I would've normally created an issue first and then a PR, but given that I had changed the code anyway so that I could test the LLRT commit, I thought I'd just raise a PR. No worries if you don't think it's a necessary feature though.

@tmokmss
Copy link
Owner

tmokmss commented Nov 21, 2024

@georeeve Thanks for the detailed clarification! Actually I have some concerns about this proposed feature:

  1. The bootstrap cache path becomes the same regardless of architecture, version, or binary type. It can confuse some users when they naively set llrtCustomBinaryDirectory prop.
  2. This feature can prevent future changes in the caching strategy. I'd like to hide this part as implementation detail that users don't need to care.

Instead, I'd just overwrite .tmp/llrt/**/bootstrap file for testing purpose as you originally did. The path may change in the future indeed, but you can then adjust the binary path to overwrite.

@georeeve
Copy link
Contributor Author

Those concerns are valid, I still think there's a use case for some projects to want to use a custom binary permanently in their project, perhaps if they apply some specific patches on top of LLRT. Would you accept a llrtCustomBinary property which specifies a file path to a specific bootstrap binary, and use this instead of altering the cache directory logic? We could then leave the caching strategy alone, and completely bypass the afterBundling step if llrtCustomBinary is provided.

@tmokmss
Copy link
Owner

tmokmss commented Nov 21, 2024

I see. then let's add the feature! I'll take a close look at the PR tomorrow so just a moment please 🙏

src/llrt-function.ts Outdated Show resolved Hide resolved
src/llrt-function.ts Outdated Show resolved Hide resolved
src/llrt-function.ts Outdated Show resolved Hide resolved
@georeeve
Copy link
Contributor Author

georeeve commented Dec 2, 2024

@tmokmss Sorry for the delay, I've added the llrtBinaryPath prop now, let me know how it looks.

@georeeve georeeve changed the title feat: add llrtCustomBinaryDirectory property feat: add llrtBinaryPath property Dec 2, 2024
Copy link
Owner

@tmokmss tmokmss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @georeeve! I'll confirm the detailed behavior in my local env tomorrow. I think we can merge this after that :)

@@ -130,7 +137,7 @@ export class LlrtFunction extends NodejsFunction {
rm -rf llrt_temp.zip
fi`,
`cp ${posix.join(i, cacheDir, 'bootstrap')} ${o}`,
],
] : [`cp ${posix.join(i, props.llrtBinaryPath)} ${o}`],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this works well in some edge cases. Does it work whenforceDockerBundling: true and/or depsLockFilePath: 'some/child/packege-lock.json'? I'll test those cases later.

Copy link
Owner

@tmokmss tmokmss Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we may need an integration test to maintain this feature. I'll add one along the above test.
edit) @georeeve If you are willing to add it, that is totally welcome though!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot, I'm not sure if it would work with forceDockerBundling. I imagine you would have to mount the directory somehow but I don't know if there's an option for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tmokmss I can take a look at the integration tests, does it just run with yarn integ-runner?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. you may need to run yarn build for tsc though.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed that as long as llrtBinaryPath is relative to the projectRoot directory, it works even with Docker. I added that information to jsdoc.

@@ -38,6 +38,13 @@ export interface LlrtFunctionProps extends NodejsFunctionProps {
* @default LlrtBinaryType.STANDARD
*/
readonly llrtBinaryType?: LlrtBinaryType;

/**
* A custom relative path to use as a local LLRT bootstrap binary.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@georeeve have you tried to support absolute paths as well? Ideally we want to support them but I suspect it is difficult.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't, I can try but I'm not able to test the behaviour on Windows, which I imagine would be different. If Windows requires Docker builds then I suppose that's a different problem entirely though.

@tmokmss
Copy link
Owner

tmokmss commented Dec 3, 2024

@georeeve I made some minor modification to the code and doc, as well as adding an integ-test. If you are okay with these changes, I'll merge this! :)

@georeeve
Copy link
Contributor Author

georeeve commented Dec 3, 2024

@tmokmss LGTM, thanks for doing that.

@tmokmss tmokmss changed the title feat: add llrtBinaryPath property feat: allow to use custom LLRT binary with llrtBinaryPath Dec 3, 2024
@tmokmss tmokmss merged commit 90b20b7 into tmokmss:main Dec 3, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants