Google Cloud Functions serverless deployments
Google Cloud Functions serverless deployments
This tutorial will get you started with Harness Continuous Delivery (CD). We will guide you through deploying new Google Cloud Functions to Google Cloud using a Harness CD pipeline.
Harness CD pipelines help you to orchestrate and automate your Google Cloud Function deployments and push updated functions to Google Cloud.
Pipelines allow extensive control over how you want to progress functions through various dev/test/stage/prod environments while running a variety of scans and tests to ensure your quality and stability standards.
Before you begin
Verify that you have the following:
Obtain GitHub personal access token with the repo scope. See the GitHub documentation on creating a personal access token.
A Kubernetes cluster. Use your own Kubernetes cluster or we recommend using K3D for installing a Harness Delegate.
Check Delegate system requirements.
Install the Docker in order to install the Docker delegate.
Fork the harnesscd-example-apps repository through the GitHub website.
For details on Forking a GitHub repository, go to GitHub docs for more information on forking a GitHub repository.
** Google Cloud Function and Google Cloud Storage permissions**. Harness supports Google Cloud Functions 1st gen and 2nd gen. There are minor differences in the permissions required by each generation. For a detailed breakdown, go to Access control with IAM from Google.
Google Cloud Function Support
Cloud Functions offers two product versions: Cloud Functions 1st gen, the original version, and Cloud Functions 2nd gen, a new version built on Cloud Run and Eventarc to provide an enhanced feature set. Harness supports deploying Google Functions 1st gen and 2nd gen.
To get more information on Google Functions 1st gen and 2nd gen, go to Cloud Functions version comparison.
We suggest opting for Cloud Functions 2nd gen whenever feasible for new functions, as it offers a range of additional features. For more information, go to New in Cloud Functions(2nd Gen).
Cloud Functions Limitations
For Google Cloud Functions 2nd gen, Harness does not support Google Cloud Source Repository at this time. Only Google Cloud Storage is supported.
For Google Cloud Functions 1st gen, Harness supports both Google Cloud Storage and Google Cloud Source.
Steps to perform on Google Cloud
Make sure your Google Cloud account credentials have the required permissions for Google Cloud Function and Google Cloud Storage, as mentioned above.
Download the hello_world.zip for 1st gen and helloHttp.zip for 2nd gen files from GitHub.
Log into the Google Cloud console and create a Google Cloud Storage bucket. For details, go to Create a new bucket.
Once the bucket is created, select UPLOAD FILES and upload the file hello_world.zip for 1st gen or helloHttp.zip for 2nd gen.
Getting Started with Harness CD
Log into Harness.
Select Projects, and then select Default Project.
For the pipeline to run successfully, please follow the remaining steps as they are, including the naming conventions.
Delegate
Under Project Setup, select Delegates.
Select Delegates.
Select New Delegate.
Select Docker. For this tutorial, let's explore how to install a delegate using Docker.
In the command provided,
ACCOUNT_IDandMANAGER_ENDPOINTare auto-populated values that you can obtain from the delegate installation wizard.Replace DELEGATE_TOKEN in the command with the token from the wizard.
Select Verify to verify that the delegate is installed successfully and can connect to the Harness Manager.
Secrets
Under Project Setup, select Secrets.
Select New Secret, and then select Text.
Enter the secret name
harness_gitpat.For the secret value, paste the GitHub personal access token you saved earlier.
Select Save.
Under Project Setup, select Secrets.
Select New Secret, and then select File.
Enter the secret name
gcpsecret.For the secret value, upload the Google Cloud's account service key file for your service account, which you can download from your GCP project.
Select Save.
Connectors
Create the GitHub connector.
Copy the contents of github-connector.yml.
In your Harness project in the Harness Manager, under Project Setup, select Connectors.
Select Create via YAML Builder and paste the copied YAML.
Assuming you have already forked the harnesscd-example-apps repository mentioned earlier, replace
GITHUB_USERNAMEwith your GitHub account username in the YAML.In
projectIdentifier, verify that the project identifier is correct. You can see the Id in the browser URL (afteraccount). If it is incorrect, the Harness YAML editor will suggest the correct Id.Select Save Changes and verify that the new connector named harness_gitconnector is successfully created.
Finally, select Connection Test under Connectivity Status to ensure the connection is successful.
Create the GCP connector.
Copy the contents of gcp-connector.yml.
In your Harness project, under Project Setup, select Connectors.
Select Create via YAML Builder and paste the copied YAML.
Select Save Changes and verify that the new connector named gcpconnector is successfully created.
Finally, select Connection Test under Connectivity Status to verify the connection is successful.
Environment
In your Harness project, select Environments.
Select New Environment, and then select YAML.
Copy the contents of environment.yml, paste it into the YAML editor, and select Save.
In your new environment, select the Infrastructure Definitions tab.
Select Infrastructure Definition, and then select YAML.
Copy the contents of infrastructure-definition.yml and paste it into the YAML editor.
Replace
CLOUD PROJECT NAMEwith your GCP project name.Replace
REGIONwith your GCP region name.Select Save and verify that the environment and infrastructure definition are created successfully.
Services
In your Harness project, select Services.
Select New Service.
Enter the name
hello_http.Select Save, and then YAML (on the Configuration tab).
Select Edit YAML, copy the contents of service.yml, and paste the into the YAML editor.
Replace
CLOUD PROJECT NAMEwith your GCP project name.Replace
CLOUD BUCKET NAMEwith your GCP bucket name.Select Save, and verify that the service hello_http is successfully created.
Pipeline
In your Harness project, select Pipelines.
Select Create a Pipeline.
Enter the name
hello_http.Select Inline to store the pipeline in Harness.
Select Start.
In Pipeline Studio, select YAML.
Select Edit YAML and choose any of the following execution strategies. Paste the respective YAML based on your selection.
Copy the contents of canary-pipeline.yml.
In your Harness pipeline YAML editor, paste the YAML.
Select Save. You can switch to the Visual editor and confirm the pipeline stage and execution steps as shown below.

Copy the contents of bluegreen-pipeline.yml.
In your Harness pipeline YAML editor, paste the YAML.
Select Save.
You can switch to the Visual pipeline editor and confirm the pipeline stage and execution steps as shown below.

Copy the contents of basic-pipeline.yml.
In your Harness pipeline YAML editor, paste the YAML.
Select Save.
You can switch to the Visual pipeline editor and confirm the pipeline stage and execution steps as shown below.

Click to view full size image
Download and configure the Harness CLI.
Clone the Forked harnesscd-example-apps repo and change directory.
Log into Harness from the CLI.
Create the GitHub connector.
In
projectIdentifier, verify that the project identifier is correct. You can see the Id in the browser URL (afteraccount). If it is incorrect, the Harness YAML editor will suggest the correct Id.Now create the GitHub connector using the following CLI command:
Create the GCP connector.
In
projectIdentifier, verify that the project identifier is correct. You can see the Id in the browser URL (afteraccount). If it is incorrect, the Harness YAML editor will suggest the correct Id.Now create the AWS Connector using the following CLI command:
Environment
Use the following CLI command to create Environments in your Harness project:
In your new environment, add an Infrastructure Definitions using the following CLI command:
Services
Use the following CLI command to create Services in your Harness project.
Pipeline
Enter this CLI command to create a canary deployment using the example YAML file:
In Harness, you can switch to the Visual editor and confirm the pipeline stage and execution steps as shown below.

Enter this CLI command to create a blue green deployment using the example YAML file:
You can switch to the Visual pipeline editor and confirm the pipeline stage and execution steps as shown below.

Enter this CLI command to create a basic deployment using the example YAML file:
You can switch to the Visual pipeline editor and confirm the pipeline stage and execution steps as shown below.

Click to view full size image
Finally, it's time to execute your pipeline.
Select Run, and then select Run Pipeline to initiate the deployment.
Observe the execution logs as Harness deploys the function.
After a successful execution, you can check the deployment on your Google Cloud Function console.
Congratulations!🎉
You've just learned how to use Harness CD to deploy a Google Cloud Function to Google Cloud.
Keep learning about Harness CD. For example, add Triggers to your pipeline that initiate pipeline deployments in response to Git events.
Getting Started with Harness CD
Log into Harness.
Select Projects, and then select Default Project
For the pipeline to run successfully, please follow the remaining steps as they are, including the naming conventions.
Delegate
Under Project Setup, select Delegates.
Select Delegates.
Select New Delegate.
For this tutorial, let's explore how to install a delegate using Docker.
In the command provided,
ACCOUNT_IDandMANAGER_ENDPOINTare auto-populated values that you can obtain from the delegate installation wizard.Replace DELEGATE_TOKEN in the command with the token from the wizard.
Select Verify to verify that the delegate is installed successfully and can connect to the Harness Manager.
Select Verify to verify that the delegate is installed successfully and can connect to the Harness Manager.
Secrets
Under Project Setup, select Secrets.
Select New Secret, and then select Text.
Enter the secret name
harness_gitpat.For the secret value, paste the GitHub personal access token you saved earlier.
Select Save.
Under Project Setup, select Secrets.
Select New Secret, and then select File.
Enter the secret name
gcpsecret.For the secret value, upload the Google Cloud's account service key file for your service account, which you can download from your GCP project.
Select Save.
Connectors
Create the GitHub connector.
Copy the contents of github-connector.yml
In your Harness project in the Harness Manager, under Project Setup, select Connectors.
Select Create via YAML Builder and paste the copied YAML.
Assuming you have already forked the harnesscd-example-apps repository mentioned earlier, replace GITHUB_USERNAME with your GitHub account username in the YAML.
In
projectIdentifier, verify that the project identifier is correct. You can see the Id in the browser URL (afteraccount). If it is incorrect, the Harness YAML editor will suggest the correct Id.Select Save Changes and verify that the new connector named harness_gitconnector is successfully created.
Finally, select Connection Test under Connectivity Status to ensure the connection is successful.
Create the GCP connector.
Copy the contents of gcp-connector.yml.
In your Harness project, under Project Setup, select Connectors.
Select Create via YAML Builder and paste the copied YAML.
Select Save Changes and verify that the new connector named gcpconnector is successfully created.
Finally, select Connection Test under Connectivity Status to verify the connection is successful.
Environment
In your Harness project, select Environments.
Select New Environment, and then select YAML.
Copy the contents of environment.yml, paste it into the YAML editor, and select Save.
In your new environment, select the Infrastructure Definitions tab.
Select Infrastructure Definition, and then select YAML.
Copy the contents of infrastructure-definition.yml and paste it into the YAML editor.
Replace
CLOUD PROJECT NAMEwith your GCP project name.Replace
REGIONwith your GCP region name.Select Save and verify that the environment and infrastructure definition are created successfully.
Services
In your Harness project, select Services.
Select New Service.
Enter the name
hello_world.Select Save, and then YAML (on the Configuration tab).
Select Edit YAML, copy the contents of service.yml, and paste the into the YAML editor.
Replace
CLOUD PROJECT NAMEwith your GCP project name.Replace
CLOUD BUCKET NAMEwith your GCP bucket name.Select Save, and verify that the service hello_world is successfully created.
Pipeline
In your Harness project, select Pipelines.
Select Create a Pipeline.
Enter the name
hello_world.Select Inline to store the pipeline in Harness.
Select Start.
In Pipeline Studio, select YAML.
Select Edit YAML and Paste the below Rolling deployment YAML.
Copy the contents of basic-pipeline.yml.
In your Harness pipeline YAML editor, paste the YAML.
Select Save.
You can switch to the Visual pipeline editor and confirm the pipeline stage and execution steps as shown below.

Download and Configure Harness CLI.
a. Open Windows Powershell and run the command below to download the Harness CLI.
b. Extract the downloaded zip file and change directory to extracted file location.
c. Follow the steps below to make it accessible via terminal.
d. Restart terminal.
2. Clone the Forked harnesscd-example-apps repo and change directory.
Log in to Harness from the CLI.
Create the GitHub connector.
In
projectIdentifier, verify that the project identifier is correct. You can see the Id in the browser URL (afteraccount). If it is incorrect, the Harness YAML editor will suggest the correct Id.Now create the GitHub connector using the following CLI command:
Create the GCP connector.
In
projectIdentifier, verify that the project identifier is correct. You can see the Id in the browser URL (afteraccount). If it is incorrect, the Harness YAML editor will suggest the correct Id.Now create the AWS Connector using the following CLI command:
Environment
Use the following CLI Command to create Environments in your Harness project:
In your new environment, add Infrastructure Definitions using the following CLI command:
Services
Use the following CLI command to create Services in your Harness Project.
Pipeline
CLI Command for basic deployment:
You can switch to the Visual pipeline editor and confirm the pipeline stage and execution steps as shown below.

Click to view full size image
Finally, it's time to execute your pipeline.
Select Run, and then select Run Pipeline to initiate the deployment.
Observe the execution logs as Harness deploys the workload and checks for steady state.
After a successful execution, you can check the deployment on your Google Cloud Function console.
Congratulations!🎉
You've just learned how to use Harness CD to deploy an application using a Google Cloud Functions gen 1 to Google Cloud.
Keep learning about Harness GitOps. Create a GitOps ApplicationSet and PR Pipeline in Harness GitOps by following this guide.
Last updated
Was this helpful?