w3c / webcodecs

WebCodecs is a flexible web API for encoding and decoding audio and video.
https://w3c.github.io/webcodecs/
Other
978 stars 136 forks source link

Setup Netlify for hosting (some) samples #531

Open chcunningham opened 2 years ago

chcunningham commented 2 years ago

PR #530 adds a sample that uses SharedArrayBuffer, which requires that the web server use specific HTTP headers to enable cross origin isolation.

I'd like to use Netlify to host this sample and serve the correct headers. I think we'll be fine w/ the free tier. Their service uses a very simple _headers) config file and can be configured to re-deploy the sample automatically as the github folder changes.

@tidoust - I almost set this up, but I don't have the right privileges to enable the integration for this repository. Can you help?

tidoust commented 2 years ago

I'm not familiar with Netlify and still trying to figure out how to properly link the deployment with W3C. In the meantime, importing it into Netlify UI seems to have done the right thing, and the gh-pages branch is now automatically published to https://webcodecs.netlify.app/ as well. Does that achieve what you wanted to do?

chcunningham commented 2 years ago

Almost!

It looks like the netlify server is not using our _headers file to configure the response HTTP headers. You can see this manifest in the https://webcodecs.netlify.app/samples/audio-video-player/audio_video_player.html demo (ringbuf.js:12 Uncaught (in promise) ReferenceError: SharedArrayBuffer is not defined)

This file was located in the samples/ directory, but I just moved it to the top level directory to see if that would help. Sadly it seems still not to be working.

chcunningham commented 2 years ago

Ah, I'm noticing that the gh-pages branch doesn't include the _headers file. I'm not immediately finding the setting for how gh-pages gets updated. Can we either (1) add this file on that branch or (2) publish netlify from main instead of gh-pages?

tidoust commented 2 years ago

Any file under the samples folder will be deployed to the gh-pages branch but not static files under the root repository, indeed.

Since we're only interested in publishing samples with Netlify, I propose that we stick to that. And we indeed don't need to hook into the gh-pages branch to deploy samples with Netlify.

I created https://webcodecs-examples.netlify.app/ instead (webcodecs-samples was already taken, I suspect that you might own it ;) Happy to switch to webcodecs-samples if the name becomes available again). The site contains the contents of the samples folder published from the main branch.

Sadly, that still does not seem to be enough: the _headers file does not seem to be taken into account and the COOP/COEP HTTP headers are not returned. And yet I see that the headers are correctly returned under http://webcodecs-samples.netlify.app/ Did I miss a setting in the Netlify UI?

(Note I also killed https://webcodecs.netlify.app/ since we don't need that in the end)

Aren't we going to quickly hit the limits of Netlify's free tier in any case? Bandwidth is limited to 100GB per month, the AVC file in the sample is ~100MB and it seems to be downloaded in full.

tidoust commented 2 years ago

Sadly, that still does not seem to be enough: the _headers file does not seem to be taken into account and the COOP/COEP HTTP headers are not returned. And yet I see that the headers are correctly returned under http://webcodecs-samples.netlify.app/ Did I miss a setting in the Netlify UI?

OK, I just had to force a cache reset and a new deploy action trough the Netlify admin UI. I confirm custom headers are now returned and example successfully runs in Chrome.

chcunningham commented 2 years ago

Nice!

webcodecs-samples was already taken, I suspect that you might own it ;) Happy to switch to webcodecs-samples if the name becomes available again

Sounds good. I've just released that name :)

Aren't we going to quickly hit the limits of Netlify's free tier in any case? Bandwidth is limited to 100GB per month, the AVC file in the sample is ~100MB and it seems to be downloaded in full.

I'd be very pleasantly surprised to see our samples have that many monthly hits. But we can definitely compress it a bit more. #537

tidoust commented 2 years ago

Sounds good. I've just released that name :)

I updated the site name. Samples are now served under https://webcodecs-samples.netlify.app/

I'd be very pleasantly surprised to see our samples have that many monthly hits. But we can definitely compress it a bit more. https://github.com/w3c/webcodecs/issues/537

No doubt WebCodecs samples will get showcased in theaters across the world! ;) That said, in just 3 days, with probably just you and I running the samples, Netlify reports that 1GB of the 100GB monthly bandwidth was used. I'll monitor evolution and see if I can get rid of that limit. And it's fine if we have that problem in any case, that would prove that many people actually play with the samples ;)

chcunningham commented 2 years ago

@tidoust, i noticed your PR had a really nice netlify preview, but my recent PR didn't get that. Is this still enabled for future PRs? Can I trigger it?

tidoust commented 2 years ago

I disabled this feature when I noticed it because I'm not familiar with it and didn't know whether editors would want that and whether Netlify would be smart enough not to add previews to PR that don't touch on samples. I just re-enabled previews for future PRs.

tidoust commented 2 years ago

Argh, Netlify does not seem to be smart enough to avoid adding preview links to pull requests that don't touch on samples, in other words those that don't touch on what Netlify calls the "Publish directory": see #552.

I find that rather confusing as this would add useless links to all PRs that touch on the specs. I disabled the preview feature again. Let me know what you prefer.