Help deploying to compute engine instance

I have a react and express app that I want to deploy to my e2-micro instance. Currently I'm going in there and installing nginx and then gcloud scp my files over. I know I can use terraform to spin up the instance and use tpl to setup and configure my nginx but how are ppl deploying their react builds and express api and set up pm2 to manage the express api?

8 comments · 100% upvoted · other discussions

comments

trial_and_err

You can create an VM instance running container-optimized OS (COS) and attach a docker container to it.

  1. Dockerize your app and push it to artifact registry (you might want to use cloudbuild for docker build + push)
  2. Create a VM running COS
  3. Attach the container image to it. COS will automatically pull and start the container on VM startup

A little more complex: Create an instance template (also running COS) and create a managed instance group from that template. You can also autoscale the managed instance group based on ingress, CPU or RAM usage.

Cloud run might be an alternative as well that is easy to setup (no Terraform required for this, just a cloudbuild.yaml).