Are you looking to deploy your NodeJS app to Google Cloud with the least maintenance possible? This tutorial will show you how to utilize GitLab’s Google Cloud integration to deploy your NodeJS app in less than 10 minutes.
Traditionally, deploying an application often requires assistance from production or DevOps engineers. This integration now empowers developers to handle deployments independently. Whether you’re a solo developer or part of a large team, this setup gives everyone the ability to deploy their applications efficiently.
Overview
- Create a new project in GitLab
- Set up your NodeJS application
- Use the Google Cloud integration to create a Service account
- Use the Google Cloud integration to configure Cloud Run via Merge Request
- Enjoy your newly deployed Java Spring Boot app
- Follow the cleanup guide
Prerequisites
- Owner access on a Google Cloud Platform project
- Working knowledge of JavaScript/TypeScript (not playing favorites here!)
- Working knowledge of GitLab CI
- 10 minutes
Step-by-step guide
1. Create a new project in GitLab
We decided to call our project nodejs–express-cloud-run
for simplicity.
2. Upload your NodeJS app or use this example to get started.
Note: Make sure to include the cloud-run
CI template within your project.
3. Use the Google Cloud integration to create a Service account.
Navigate to Operate > Google Cloud > Create Service account.
Also configure the region you would like the Cloud Run instance deployed to.
4. Go to the Deployments tab and use the Google Cloud integration to configure Cloud Run via Merge Request.
This will open a merge request – immediately merge it.
Note: GCP_PROJECT_ID
, GCP_REGION
, GCP_SERVICE_ACCOUNT
, and GCP_SERVICE_ACCOUNT_KEY
will all be automatically populated from the previous steps.
5. Voila! Check your pipeline and you will see you have successfully deployed to Google Cloud Run using GitLab CI.
Click the Service URL to view your newly deployed Node server.
In addition, you can navigate to Operate > Environments to see a list of deployments for your environments.
By clicking on the environment called main
, you’ll be able to view a complete list of deployments specific to that environment.
6. Next steps
To get started with developing your Node application, try adding another endpoint. For instance, in your index.js
file, you can add a /bye endpoint as shown below:
app.get('/bye', (req, res) => {
res.send(`Have a great day! See you!`);
});
Push the changes to the repo, and watch the deploy-to-cloud-run
job deploy the updates. Once it’s complete, go back to the Service URL and navigate to the /bye endpoint to see the new functionality in action.
Follow the cleanup guide
To prevent incurring charges on your Google Cloud account for the resources used in this tutorial, you can either delete the specific resources or delete the entire Google Cloud project. For detailed instructions, refer to the cleanup guide here.
Read more of these helpful tutorials from GitLab solutions architects.