Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Deploying github repo app to GCP VM

I need to deploy github repository (nodejs application) into the GCP VM which will accessible on static IP of the VM but there is some additional requirement, I need to automate the whole process, if anything changes in the code then the VM automatically takes the github repo code and again start the NPM install and NPM start process. 

Anyone help me, I am stuck in the automate process.

0 1 1,638
1 REPLY 1

Howdy ... my initial thinking is that we can employ the Google "Cloud Build" technology.  Cloud Build can be configured to be evented (run/executed) when a change is made to a GitHub repository ... such as a push.  Cloud Build is configured with a YAML file that describes a sequence of steps to be performed when executed.  While Cloud Build is commonly used to create a new Docker image, there is nothing that would preclude us from running arbitrary "step commands" such as executing "gcloud" commands to stop and restart your Compute Engine instance.  The Compute Engine's startup script could then pull your GitHub repository and build/run the NodeJS application.

One thing that comes to mind would be to consider packaging your application as a Docker image and then run your Compute Engine to run the image. 

For example, write a Cloud Build script that builds a Docker image that contains your NodeJS app.  You could then "just run" that image in a Compute Engine.  This would remove all the "stuff" of Git Pulls and scripts.

Another thought ... what is the nature of your application?  Does it respond to REST or Web requests?  If yes, then another option springs to mind which is not to use a Compute Engine at all but instead use Cloud Run.   Cloud Run automatically uses the "latest" Docker image to run logic.  If your Cloud Build now builds a new image that will automatically be picked up by Cloud Run.  This also has the advantage that it "may" be cheaper for you in that you are only charged for actively processed requests rather than for a continuously running Compute Engine.