sunrisemvmtnyc / legislation-tracker

Easy, intuitive legislation tracker made by the Sunrise Digital Tools team
0 stars 1 forks source link

Dockerizing containers for AWS deployment #72

Open afnanhaq opened 3 weeks ago

afnanhaq commented 3 weeks ago

afnan's work done so far exists here.

Please ensure the Dockerfiles are set up in a way that they can be used to run the containers on AWS but does not mess with local setup. Please also clarify how to connect the frontend and backend especially the API keys. We can easily store API keys in AWS and call them via environment variables etc.

elliott-king commented 2 weeks ago

Hosting frontend & backend

The backend was built as a docker image & hosted on AWS App Runner. The frontend was built into a static site (npm build) and hosted on S3.

The guides on how to do this are below.

Pricing: S3: 724K @ $0.023 per GB/Month = negligible Apprunner: More complicated, because the pricing is different if people are hitting your App vs it being asleep. It can also scale up even more than shown if there are a huge number of parallel requests.

Backend: deploy nodejs to aws using docker, ecr & app runner

Guide

docker image setup:

;docker build . -t elliottking/legislation-tracker-backend
;docker run -p 3000:3000 -e NODE_ENV=production --env-file ../.env docker.io/elliottking/legislation-tracker-backend

Pushing image to ecr:

;aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 888096637450.dkr.ecr.us-east-1.amazonaws.com/sunrise-test
;docker image list
;docker tag b4ec9a7d0e4e 888096637450.dkr.ecr.us-east-1.amazonaws.com/sunrise-test
;docker push 888096637450.dkr.ecr.us-east-1.amazonaws.com/sunrise-test

Don't forget your regular env vars, plus NODE_ENV=production & CLIENT_URL=http://sunrise-website-deployment-test.s3-website-us-east-1.amazonaws.com:

Screenshot 2024-09-17 at 11 41 15 AM

other references:

extensions:

Frontend: deploy mono-repo react app with Vite to S3 using GH actions

guide

I only created the S3 bucket & uploaded the required files. I didn't create a GH action. I also had to manually select the bucket items & update to public ACL. Also had to set the error page as index.html to get react router to work.

;VITE_SERVER_URL=https://pkyzwf27mv.us-east-1.awsapprunner.com/ npm run build

other references:

extensions:

Frontend: SSL on the website

guide

For now, I only did the Distributing an AWS S3 Static Website via CloudFront section. This puts an https-enabled URL in front of the non-https s3 site. In that step, I ignored anything that pertained to a personal domain.

other references:

extensions: