quantified-uncertainty / metaforecast

Fetch forecasts from prediction markets/forecasting platforms to make them searchable. Integrate these forecasts into other services.
https://metaforecast.org/
MIT License
56 stars 5 forks source link

Vercel and Terraform #55

Closed berekuk closed 2 years ago

berekuk commented 2 years ago

This PR addresses #52 and #54.

Terraformed: Vercel; Postgres DB on DO; Heroku.

On vars and state management:

Other notes on vars:

On Vercel:

vercel[bot] commented 2 years ago

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/quantified-uncertainty/metaforecast/GiKJxR9LAWzcNM8QtuLvBDLJ7Hjp
✅ Preview: https://metaforecast-git-vercel-quantified-uncertainty.vercel.app

netlify[bot] commented 2 years ago

Deploy Preview for metaforecast ready!

Name Link
Latest commit f64a5c04c3d40fe3a51f6a0dda91e91f24fca83a
Latest deploy log https://app.netlify.com/sites/metaforecast/deploys/6255da13f03faa0008590fab
Deploy Preview https://deploy-preview-55--metaforecast.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

NunoSempere commented 2 years ago

For Ozzie's benefit:

config

I worry that Terraform is a bit of overengineering. I'm fine with it and it probably leaves the project in a better position in the long term, but I'd prefer to have the graphql interface up first. thoughts?

berekuk commented 2 years ago

I worry that Terraform is a bit of overengineering.

Here are the reasons I did this now:

Also, if you count the number of lines of code in this PR but subtract the number of lines in metaforecast-notes-and-secrets that can be removed, the diff size is probably negative; in a sense, terraform configuration is documentation, and it doesn't get stale since it's used as a source of truth.

OAGr commented 2 years ago

I was on the fence about it still, but then Ozzie liked https://github.com/quantified-uncertainty/metaforecast/issues/54 and I considered it to be "just do it" signal :)

This wasn't meant as a strong endorsement, sorry! I wasn't sure, but was showing support for discussing it, not for fully implementing it

OAGr commented 2 years ago

I'm really not familiar with Terraform.

However, my impression is that:

  1. Terraform helps organize the deployment.
  2. Using terraform would streamline the process and make deployments simpler and cleaner.
  3. Once iteration is done with terraform, it wouldn't be that much more difficult to go back on this, then it would be to just not begin with it. (Not much lock-in)

Are these three things correct? If so, I wouldn't mind much.

berekuk commented 2 years ago

I'm really not familiar with Terraform.

Yes, my priors about this for you and Nuño are why I went with implementation instead of discussion.

Are these three things correct?

Yes, all three are correct.


I'll give a short primer, since I suspect that my original description in this PR can be too terse to parse for someone who is not familiar with Terraform.

Terraform allows you to automate the configuration for any cloud service for which the "provider" exists, and there are providers for everything, including Dominos Pizza.

It's not so much for day-to-day code deployments as for wiring everything together at the higher level, and for reconfiguring the wiring whenever necessary (when we switch from Netlify to Vercel, or change env configuration, or move the database to another provider).

For example, terraform configs from this PR set up a Digital Ocean database and then add its URI to the metaforecast env on Heroku and Vercel. So if you move the DO database you don't have to 1) set it up in DO UI; 2) copy the postgres URI; 3) insert it into Vercel/Netlify env UI; 4) insert it into Heroku UI. Instead, you just add a resource for a new database in terraform config, apply the new config, and you're done (well, if you need to migrate the data then it's a bit more complicated, but still much easier).

Ideally, when/if we migrate everything to terraform, someone could roll up their own metaforecast2.org from scratch with a single command (after they set up API tokens for all cloud services in its tfvars config).


To be clear: this can be merged now even if we don't adopt terraform-centered workflow yet. What do you think about this roadmap?

OAGr commented 2 years ago

That sounds fine to me, thanks for the summary there.

NunoSempere commented 2 years ago

Thanks as well. Before merging, could you add the latest commit from #53? E.g., https://deploy-preview-53--metaforecast.netlify.app/dashboards/embed/561472e0d2 works but https://deploy-preview-55--metaforecast.netlify.app/dashboards/embed/561472e0d2 doesn't.

berekuk commented 2 years ago

Before merging, could you add the latest commit

I already did, in f64a5c04c3d40fe3a51f6a0dda91e91f24fca83a, but Netlify doesn't redeploy new commits for PRs (another reason to move to Vercel...)

NunoSempere commented 2 years ago

Great, merging

NunoSempere commented 2 years ago

Ok, merged

berekuk commented 2 years ago

Minor note: I got rid of NEXT_PUBLIC_SITE_URL in this PR by replacing it with NEXT_PUBLIC_VERCEL_URL that Vercel provides automatically (see src/web/utils.ts and vercel docs). I realized just a minute ago that it won't work on Netlify... but it works fine for some reason. Probably because "http://" + req.headers.host; redirects to https.

The only place this code is used for now is on /dashboards/view/[id] page, in getServerSideProps. It's probably broken for POST requests, but we'll move to Vercel soon enough that it shouldn't be an issue.

OAGr commented 2 years ago
image