mit-jp / mit-climate-data-viz

Plotting climate data for the MIT Joint Program on the Science and Policy of Global Change
https://cypressf.shinyapps.io/eppa-dashboard/
0 stars 0 forks source link

Test out AWS deploys #226

Open cypressf opened 2 years ago

cypressf commented 2 years ago

In preparation for potentially using AWS, I'm going to set up a test EC2 server and familiarize myself with the deployment process. It looks like it's possible to automate deploying a service to EC2 using AWS CodeDeploy after building it using Github Actions. See https://docs.aws.amazon.com/codedeploy/latest/userguide/tutorials-github.html

cypressf commented 2 years ago

I set up an AWS account, created an EC2 instance, and followed directions to set up the Identity and Access Management users, roles, and polices needed for CodeDeploy.

cypressf commented 2 years ago

I set up a github action to build the Rust backend, but it failed because sqlx requires either a live running database, or a cached schema for offline mode. I will set up offline mode for the purposes of building more easily on Github.

cypressf commented 2 years ago

With sqlx offline mode, the rust build succeeded on github! https://github.com/cypressf/climate-risk-map/actions/runs/1445069086

it took 4min 19sec. Github's freemium pricing for actions includes 2,000 minutes / month, which would give me 461 builds per month at this speed. I think it will be sufficient for now, but I think there's caching available too. I'll check to see if I can speed it up.

cypressf commented 2 years ago

I added a frontend build to my github actions https://github.com/cypressf/climate-risk-map/commit/7b9f9be0daa5a4ffdd774f9f2f6441d70687c464

cypressf commented 2 years ago

Notes on automated infrastructure on AWS

I found this useful history of infrastructure-as-code.

I've been reading about ways to automate deploying to AWS. There's a large number of tools that overlap in functionality:

CloudFormation: Oldest, lowest level, declarative templates SAM: Dev and lambda focused, declarative templates CloudFormation extension CDK: Dev and infra focused, typescript that generates templates Copilot: Dev & container focused, wizard-like command-line interface, can export to CloudFormation template Proton: Operator & Infra, Dev & App focused (but usually for larger orgs that separate dev and infra)

The PNNL team is using SAM because they're making serverless apps, so I might want to learn that. I'd have to rewire the backend to use lambda instead of a Rust binary. Maybe I could copy my rust endpoints to lambda functions? Copilot also looks like something I could use, while keeping my existing backend service.

Storage and compute

EC2: A VPS ECR: Storage for containers ECS: Manage and scale container instances

cypressf commented 2 years ago

I'm going to continue, with AWS CodeDeploy for now until I can get a basic version of that working.

cypressf commented 2 years ago

I deployed a test app from github to an EC2 instance using CodeDeploy

http://ec2-52-207-244-77.compute-1.amazonaws.com https://github.com/cypressf/test-code-deploy

Next up I want to make a proof of concept connection with github actions