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).

martin_omander

If you are doing this to learn Terraform, Compute Engine, nginx, pm2, etc, keep going down the path you are already on.

But if your goal is to get your React+Express application running in the cloud with minimum fuss and cost, go with Cloud Run. It can serve your static files and your Express API. It takes a single gcloud command to deploy your application and there will be no infrastructure to worry about.

NetFutility [OP]

I do have that cloud run configured but the load balancer cost 18$ at a minimum in addition to cloud armor costs, whereas an e2-micro with nginx whitelist will cost just 8$ a month.

Just wondering if there's a popular ci/cd pipeline I can look into for the bare minimum cost setup for a low traffic site

martin_omander

Got it. I didn't know about your whitelist requirement. Many developers run nginx in Cloud Run and skip the load balancer. Here is a video that shows a sample three-tier application using nginx with Cloud Run: https://youtu.be/4URpj0h3mv8

I have used GitHub Actions for my CI/CD pipelines. Google Cloud Build is another great alternative. Both come with generous free tiers. If you're using Cloud Run, it even has built-in deployments from GitHub that you can set up without writing any scripts at all.

A low traffic app will most likely come in under Cloud Run's free tier. The only potential blocker would be your database. If your current e2-micro server also hosts a relational database, that would not work well on Cloud Run.

Best of luck with your project!

kaeshiwaza

In the example they run a Go app, they don't need two CloudRun instances, it's very easy to serve the assets in the same Go app and don't need Nginx at all.

BehindTheMath

One option is to use Docker Compose with a CI/CD pipeline. First create container images and a Docker Compose setup. Then set up a CO/CD pipeline that will build the images, SSH into the VM and push the changes, and then restart the server.

Abother option is to use Dokku, where you just push to a Git remote and everything is built and set up.

You can also use App Engine or Cloud Run, which might be simpler.

NetFutility [OP]

Are there any ci/cd pipelines you'd recommend? I'm currently using private github repo

BehindTheMath

You can use Github Actions.