Deploy a NodeJS application to Google App Engine and Cloud SQL from GitHub - Part 1: Brainstorming
Tags: github, googlecloud, devops, todayilearned
Published: 2022-02-06 06:33:42

This is more about describing my personal development and debugging experience, less of a step-by-step tutorial on the topic. Correction to any of the errors is welcome!

## Problem Statement 🍀

In my [Learning Journal 1](https://hungvu.tech/from-the-local-development-environment-to-google-cloud-where-to-start?utm_source=dev.to&utm_medium=referral&utm_campaign=devto_crossposting), I decided to deploy my React, NestJS, PostgreSQL web application to Google App Engine and Cloud SQL. I have experience with Heroku Dynos, so I assume Google Cloud will have something similar. This time, I want to deploy a "Hello World" application from GitHub just to test out the features and validate my assumption. Where should I start?

### Can I have a summary of the deployment process from GitHub to Heroku? 🤔

1. You need to create a new app in Heroku. 
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1644118380894/-lotGwvxs.png)

2. In the *Resources* tab, add a database instance to your app using Heroku Add-ons. 
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1644118430670/QpnmgDknD.png)

3. Get database secrets either via Heroku CLI or from the *Settings/Config Vars* interface. In there, I can also add more environment variables to use during runtime for our application. ![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1644119068000/QzakDgmBf.png)

4. In the *Deploy* tab, configure GitHub as a *Deployment method*, enable *Automatic Deploys*, and *Wait for CI to pass before deploy*. 
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1644118692315/8TXYQv9Gq.png)![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1644118744309/lGEM1USlV.png)

5. Now, there should be a new *Environments* in your GitHub repository. This is created from a Heroku integration and it represents an automatic deployment workflow.

### Great, GCP should provide something similar, right? 🤔

**Unfortunately, no**. At least, I could not find any equal "few-click deployment" feature.

### What are the alternatives? 🤔

In GitHub, there is a thing called *GitHub Actions*. In short, it is a tool to trigger commands based on specific events like code push, pull request, merge, etc., a CI/CD tool in other words. 

Each workflow consists of multiple commands or smaller actions such as *actions/checkout@v2* to check out the codebase. There are various pre-defined workflows that I can search for. Still, none matches our requirements. The only one from Google is for Google Kubernetes Engine deployment. 
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1644120611881/d-zO7-Q6n.png)

### If there is no *pre-defined* workflow, can I write one? 🤔

Yes, I can! GitHub Actions can run regular terminal commands. Meanwhile, Google Cloud has a CLI called [*gsutil tool*](https://cloud.google.com/storage/docs/gsutil). I assume there should be a way to run the CLI with GitHub Actions.

### How to run *gsutil tool* in GitHub Actions? 🤔

In the process of finding the answer, I discovered that the small actions are pretty much open-source. I can also go directly to their respective code repositories and learn about them. To run *gsutil*, I will need a [*setup-gcloud* action](https://github.com/google-github-actions/setup-gcloud).

### Okay, if *gsutil* is used to run barebone `gcloud` commands and is found from an open-source repository, maybe there is an action that abstracts away the command to further simplify the deployment process? 🤔

Yes, there is a [*deploy-appengine* action](https://github.com/google-github-actions/deploy-appengine) that automates the whole App Engine deployment process. Indeed, it uses `gcloud` commands underneath too. Either way, both approaches need an [*auth* action](https://github.com/google-github-actions/auth) to authenticate to GCP before any task can be performed. 

### There are 2 approaches, using *setup-gcloud* or *deploy-appengine*, which should I use? 🤔

I prefer to use *deploy-appengine* due to its simplicity. Down the road, I will consider tinkering with `gcloud` commands as it is a formal way to interact with GCP, and it offers a more granular control. 

Also a quick note, I have conflict comments on the actual maintainers of the *deploy-appengine* action. The action is in [Google GitHub Actions organization](https://github.com/google-github-actions), which means it should be managed by Google. The organization is also mentioned in [this article by Google](https://cloud.google.com/blog/products/identity-security/enabling-keyless-authentication-from-github-actions). However, from one of my conversations with the Google Cloud Support team for an unrelated matter, I brought up *deploy-appengine action* and they said (quoted): _"Please note that the Github repository that you are following is a 3rd party and not maintained by Google so I cannot vouch its accuracy."_

### There should be something like *deploy-appengine* for Cloud SQL deployment, right? 🤔

**Probably not**. I could not find anything similar. It appears for Cloud SQL, only using *gsutil* is viable. That said, it appears the deployment to Cloud SQL has to be done manually in my use case. I will discuss this in later posts. 

## Wrap Up 🍀

I learned that a regular GCP deployment process is not as straightforward as Heroku. This gave me a new perspective on how a CI/CD process can be formed. In the next article, I will discuss more on my experience when first creating a workflow and initial configurations on GCP. 

I also do not mention much about *secrets and environment variables*, even though I brought that up in the Heroku deployment process. Google App Engine in fact handles it differently, and I will mention that next time too.