-
Notifications
You must be signed in to change notification settings - Fork 324
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
Set up /website Vercel deployment #3092
Conversation
This pull request is being automatically deployed with Vercel (learn more). nusmods-website – ./website🔍 Inspect: https://vercel.com/nusmodifications/nusmods-website/q9f8zf3vo nusmods-export – ./export🔍 Inspect: https://vercel.com/nusmodifications/nusmods-export/mwgktcnya |
I wonder if we can replace this with the GitHub action or CircleCI orb - https://github.com/packtracker/report |
Great idea! Let me try configuring a CircleCI Orb |
1. Use new executors key. 2. Also: "workflows no longer have a version number. Make sure to take the version key out of your workflows section or bad things will happen. The only version key in 2.1 is the top-level key." -- https://discuss.circleci.com/t/circleci-2-1-config-overview/26057
Don't use GitHub Action because (I believe) that'll need to rebuild website again, and we don't want to diversify our CI over too many separate systems as that'll make it harder to reason about.
a98e733
to
757cb79
Compare
So it's a job that builds and runs independently of our build job... this isn't looking good.
Their docs were a little inconsistent
So I think we can't use either the orb or the GitHub Action:
I'll add the Webpack plugin back to our Webpack config after lunch. |
Irrelevant again, now that all targets will be built and used by the same worker.
We currently redirect /news to https://blog.nusmods.com in our Caddyfile; I'll add that to our vercel.json tomorrow, but this PR is ready for review. |
@@ -2,7 +2,7 @@ | |||
"brandName": "NUSMods", | |||
"defaultDescription": "NUSMods is a timetable builder and knowledge platform, providing students with a better way to plan their school timetable and useful module-related information that are community-driven.", | |||
"academicYear": "2020/2021", | |||
"apiBaseUrl": "https://nusmods.com/api", | |||
"apiBaseUrl": "https://api.nusmods.com", |
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.
Should add this as a DNS prefetch into either our website or our headers
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.
Never knew this existed! But because we already preload the module list endpoint and thus presumably already perform this DNS resolution very early, will this have any significant effect? I'm not too familiar with prefetching in general, but if the improvement is negligible I'm concerned that the cost of sending down that additional DNS prefetching line will negate any gains. Plus there's some (minimal) eng cost to adding more fields to our HTML Webpack Plugin config.
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 was thinking Vercel would have a config for that in the headers field
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 we can add a header to our Vercel config, but I'm still not sure if it's worth it. It'll still be one extra line sent down to the client, plus now we'll have api.nusmods.com
in multiple places in our codebase. Very minimal issues of course, but if the gains are negligible these may cost more
website/vercel.json
Outdated
"headers": [ | ||
{ | ||
"key": "Cache-Control", | ||
"value": "public, max-age=31536000, immutable" |
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 think 7 days (604800) is the most I would cache this for. We've definitely had bugs in this file before, and it would be awkward for this file to be borked for an entire year. Also I just took another look at the file and it's somehow 164kb (!?) will investigate
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.
Actually hold on, all the files in the /assets/ folder have content hashes in their filenames. I think we potentially may have a problem if we accidentally produce unhashed files, but I think that'll be unlikely?
My intention with this 1 year cache is to help with our "Error loading chunk xxx" errors, by basically letting the CDN serve them even after they're outdated. Maybe 1 year is too long, but given that students tend to keep NUSMods open for a really long time I think 1 week may be a bit too short. Maybe a month?
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've changed it to a month. Let's discuss this again if there's a better choice :)
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'm not sure why you'd think the browser cache would help with the error? We've always kept the older versions of our assets on our current server and it never seem to help. But yeah the URL must contain hash, in which case a 1 year expiration date actually make sense and we can use immutable
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#Revalidation_and_reloading
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'm thinking the proxy cache/CDN (i.e. Vercel) can help with this. I'm not sure if our previous Caddy/Traefik set up was ever configured to continue serving cached versions of these files after they were deleted by the build script, but I doubt they were. I know the pre-Docker setup had all the old files sitting around, but I don't recall whether we had these errors then.
And yep this uses immutable
. I'll bump the max-age back to 1 year in another PR
]); | ||
const errors = results.filter((r) => r.status === 'rejected').map((r) => r.reason); | ||
if (errors.length > 0) { | ||
throw errors; |
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.
A bit awkward since you're throwing an array not an Error, but not a huge issue
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'm a bit desensitized to this now after seeing React throw *promises* 😆
Figured it should be fine since we do want to keep track of multiple errors, and creating an Errors extends Error
class seemed a bit overkill since these thrown errors are only used by this file.
/news and /api now redirect to blog.nusmods.com and api.nusmods.com respectively, with a 307 status code. Merging now to unblock #3095, but we can continue discussing the unresolved comments |
#3098.
Goal
Setting up Vercel now, which may be able to replace Netlify (though we're on the old free plan that has unlimited team members but only a meagre 2 build hours) and even our Docker website setup.
The commit history is rather messed up -- it'll be easier to review this just by looking at the diff.
Also ignore the changes to the CircleCI config; that has been spun out to #3094 to reduce the mess in this PR.#3094 has been mergedBreakdown
Fix Vercel build failure caused by Packtracker plugin.
Overhaul scripts/build.js to parallelize website and timetable-only builds. There's now a ~15% reduction in build time when built locally.
Nest timetable-only website within the main website's
dist
folder. This will allow one Vercel project to serve both projects. (Edit: done: https://nusmods-website-git-eliang-vercel.nusmodifications.vercel.app/timetable-only)Configure caching headers.
assets
folder.assets
.This should only be merged until after we can confirm that the export server can consume the new timetable-only bundle hosted by Vercel. (EDIT: it can! 🎉 see #3095)
What's purposely not done
/api
toapi.nusmods.com
. Visiting /api in the browser still works as React Router has a redirect configured,but it won't be redirected at the proxy level as imo it's unnecessary./website will use api.nusmods.com directly. EDIT: we'll redirect /api to api.nusmods.com since it's convenient.