nusmodifications / nusmodifications/nusmods
Migrate /website and /export from Docker to Vercel
@taneliang is already working on this.
Since Dec 30, 2020.
- Dominant language
- JavaScript
- Stars
- 689
- Forks
- 364
- Avg merge
- 7h 5m
- Merged PRs (30d)
- 14
Description
Context
About 1.5 years ago, we moved both projects to Docker (#1826). Our goal was to make it easier for new contributors to get started by simplifying their getting started steps to a simple docker-compose up.
My secondary vision was also to be able to start all of NUSMods' services with a single command, and even potentially have deploy previews that previewed the entire suite of services instead of just /website. This would have been useful as we intended to write a new GraphQL API server.
Problems with Docker
While the docker-compose up experience was pretty sweet, it did not quite live up to its promises.
- As of now, only /website and /export were moved to Docker. It turns out that porting the scraper, Matomo, and other services that live on our 1.nusmods.com droplet was just not easy or not worth the effort. Also, although our Elasticsearch server was originally in our Docker setup, we moved them to Elastic Cloud.
- Because only 2 services were started, and most NUSMods work happens in our /website project, there wasn't much point using
docker-compose upfor most dev work. - Deployment was much slower and messier. The script would build our services from scratch, a process which takes about 15 minutes, before doing a blue-green deployment. For a simple SPA and service, this seemed a little extreme.
- Using Docker to serve the /website SPA was inefficient. We didn't really need an instance-level Caddy reverse proxy to serve them behind a machine-level Traefik reverse proxy to serve a simple static site, but we had them so that it would be easy to start multiple instances of NUSMods (because of our vision).
As a result, I think we should drop our unified Docker set up. We should definitely maintain Docker setups for each individual project, including project-specific docker-compose.yml configs.
Solution
Moving forward, I think both Dockerized services can be moved to Vercel. Here's why:
/website
/website is a simple SPA, and Vercel/Netlify have both been serving SPAs well for years. Although we have Netlify already set up, they've introduced build minute limits recently, forcing us to work around them. Vercel doesn't have these limits as they currently charge by team seats. Though, we're on a grandfathered Free plan with limits, so we may hit those limits. We'll see.
/export
The biggest problem with /export is Puppeteer, as it's big and resource-heavy. Thankfully, with third party packages, it looks like it's still possible to run them in a serverless environment. The choice now is between the following serverless function providers:
- AWS Lambda/GCP: the OG serverless function providers, but they're a real pain to work with.
- Netlify Functions: seems good, with 125k free invocations per month.
- Vercel Serverless Functions: seems good, but our grandfathered Free plan may have a 120 min/month limit. However, it'll be slightly easier than working with Netlify as we'll be able to have everything on 1 Vercel team.
In summary, moving forward, we'll want to use Vercel as it slightly edges out its competition, but we'll want to make sure we'll be able to easily switch to Netlify (or any other similar product).
Migration Steps
- Set up /website to use Vercel (#3092)
- Fix build errors
- Add Vercel config for redirects and caching
- Nest the timetable-only website in the deployment
- Set up /export to be hosted on Vercel (#3095)
- Point export.nusmods.com to the /export project on Vercel (i.e. nusmods-export)
- Update /website's export base URL to
https://export.nusmods.com/api/export(#3099) - Point nusmods.com to the /website project on Vercel (i.e. nusmods-website)
- Update nusmods-export's
PAGEenv var to point tonusmods.com - Wait a while (1-2 weeks?) to make sure everything works
- Remove Docker deployment configs.
- Update docs.
- Destroy 3.nusmods.com droplet.
Rollback Plan
If there are catastrophic, unrecoverable problems with Vercel, we can revert back to our Docker setup.
- Point nusmods.com back to our 3.nusmods.com server.
- Revert codebase changes.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.