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

Add way to opt in to uploading assets with signed URLs #328

Merged
merged 1 commit into from
Feb 14, 2025
Merged

Conversation

lencioni
Copy link
Contributor

@lencioni lencioni commented Feb 13, 2025

Add way to opt in to uploading assets with signed URLs

This will allow folks to opt in to using signed URLs by setting the
HAPPO_SIGNED_URL env var.

This requires a separate change to land on the server side before it can
be used.

To support this change, I ended up doing some bigger refactoring to the
react integration test. This change should make the test a lot more
realistic, because it now avoids mocking the makeRequest method in favor
of spinning up a server that responds with mock responses.

@lencioni lencioni force-pushed the signed-urls branch 2 times, most recently from c73ae85 to c1d1f5b Compare February 14, 2025 18:53
@lencioni lencioni requested a review from trotzig February 14, 2025 18:53
@lencioni lencioni marked this pull request as ready for review February 14, 2025 18:54
This will allow folks to opt in to using signed URLs by setting the
HAPPO_SIGNED_URL env var.

This requires a separate change to land on the server side before it can
be used.

To support this change, I ended up doing some bigger refactoring to the
react integration test. This change should make the test a lot more
realistic, because it now avoids mocking the makeRequest method in favor
of spinning up a server that responds with mock responses.
@@ -252,7 +351,8 @@ describe('with multiple targets', () => {

it('resolves assets correctly', async () => {
await subject();
const zip = new AdmZip(config.targets.chrome.assetsPackage);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was pretty confusing for me, but I believe that the previous version of the tests were cramming in the location of the local zip file in the API response, which the domRunner would then eventually store in the chrome target under the assetsPackage property.

In this commit I ended up changing it so the mock server responds in the same way that the actual server would, which means that the path in the response is now where it is stored on S3. And then to find the zip file, I'm looking in the formData that was posted in the request more directly.

This makes these tests more realistic and removes a number of layers of confusing indirection.

Comment on lines +107 to +114
// Upload the assets to the signed URL using node's built-in fetch.
const putRes = await fetch(signedUrlRes.signedUrl, {
method: 'PUT',
body: streamOrBuffer,
headers: {
'Content-Type': 'application/zip',
},
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we want to retry this request if it fails?

Comment on lines +136 to +138
if (process.env.HAPPO_SIGNED_URL) {
return uploadAssetsWithSignedUrl(streamOrBuffer, options);
}
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 am doing this as an opt-in for now. Once we are confident with this approach, we can roll it out as the default option or perhaps the only option.

@lencioni lencioni merged commit c8fccc8 into main Feb 14, 2025
4 checks passed
@lencioni lencioni deleted the signed-urls branch February 14, 2025 19:14
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.

1 participant