0
votes

Does anyone know how to handle deployments automatically in Google Compute Engine ? I would like to issue a command like npm run deploy-to-gce and it would pull all the files from git, compile and start the node app

I know that it is possible to run a startup script when creating the instance but then running npm install (and git clone) etc takes a lot of time everytime I create the instance. It seems a bit excessive to create everything from scratch everytime I want to deploy.

There is no way to run a script from outside the instance or issue commands to the VM without logging in ?

-Jani

1

1 Answers

0
votes

If you want to create new instances using automatic deployments, you can use Deployment Manager, please see [1].

On the other hand if you have a list of software that you always install every time you create an instance, then you can create an image from the boot disks of your existing Compute Engine instance(s). Then use that image to create new boot disks for your instances, please see [2], and if you need to install additional software you can use the startup scripts.

The good news is that with Deployment Manager you can combine these 3 functionalities: Create new instances, add existing boot disks (as I mentioned above) and include startup scripts in case you need to install additional software, please see [3].

In addition, you can store your startup scripts in Google Cloud Storage by using a bucket and call it from there, this enables you to access your startup script from anywhere and bypass the metadata server limit. please see [4] for more details.

Here's some Deploy Manager samples (templates), for other tasks that you might find useful, please see [5].

RESOURCES:

[1] https://cloud.google.com/deployment-manager/docs/how-to

[2] https://cloud.google.com/compute/docs/images#custom_images

[3] https://cloud.google.com/deployment-manager/docs/step-by-step-guide/setting-metadata-and-startup-scripts

[4] https://cloud.google.com/compute/docs/startupscript#cloud-storage

[5] https://github.com/GoogleCloudPlatform/deploymentmanager-samples