Harness CICD Google Cloud Function Series 1 (Http)

Varunkumar Inbaraj
3 min readMar 22, 2024

Deploying 2nd Gen GCP Cloud Function with Http Trigger

GCF is now powered by Cloud Run and Eventarc

gcloud config set project [YOUR-PROJECT-ID]
PROJECT_ID=$(gcloud config get-value project)
REGION=us-west1

Enable all necessary services:

gcloud services enable \
artifactregistry.googleapis.com \
cloudfunctions.googleapis.com \
cloudbuild.googleapis.com \
eventarc.googleapis.com \
run.googleapis.com \
logging.googleapis.com \
pubsub.googleapis.com

Set up

To use Cloud Audit Log functions, you must enable Audit Logs for Eventarc. You also need to use a service account with the eventarc.eventReceiver role.

  1. Enable Cloud Audit Logs Admin Read, Data Read, and Data Write log types for the Compute Engine API:
  2. Grant the default Compute Engine service account the eventarc.eventReceiver IAM role:
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member serviceAccount:$PROJECT_NUMBER-compute@developer.gserviceaccount.com \
--role roles/eventarc.eventReceiver

2nd gen function definition(service)

Harness service manifest for Google Cloud Function deployment. deploying a Google Cloud Function using the Harness service.

function:
name: <function-name>
build_config:
runtime: python39
entry_point: main
environment: GEN_2
service_config:
environment_variables:
PROJECT_ID: <gcp-project-id>
PROCESSED BUCKET_NAME: <some-bucket-name>
TOPIC_NAME: <some-topic-name>
service_account_email: <custom-cloud-function-service-name@<gcp-project-id>.iam.gserviceaccount.com>
vpc_connector: "projects/host-networking123456/locations/<location>/connectors/<connector-name>"
vpc_connector_egress_settings: "PRIVATE_RANGES_ONLY"
ingress_settings: "ALLOW_INTERNAL_ONLY"
available_memory: 512M
available_cpu: 2
min_instance_count: 1
max_instance_count: 1000
max_instance_request_concurrency: 10
timeout: 180s

Function Configuration:

  • name: The name of the Cloud Function.
  • build_config: Configuration related to building the function.
  • runtime: The runtime environment for the function (Python 3.9 in this case).
  • entry_point: The name of the function that will be executed when the Cloud Function is triggered.
  • environment: The type of environment for the function, which seems to be specified as "GEN_2".

Service Configuration:

  • environment_variables: Environment variables that will be available to the function.
  • PROJECT_ID: The ID of the Google Cloud Platform project.
  • PROCESSED_BUCKET_NAME: The name of a bucket.
  • TOPIC_NAME: The name of a topic.
  • service_account_email: The email address of the service account used by the Cloud Function.
  • vpc_connector: The specification of a VPC connector, enabling the function to connect securely to a VPC network.
  • vpc_connector_egress_settings: Specifies the egress settings for the VPC connector, allowing only traffic to private ranges.
  • ingress_settings: Specifies the ingress settings, allowing only internal traffic.
  • available_memory: The amount of memory available to the function (512 megabytes in this case).
  • available_cpu: The number of CPU cores available to the function (2 cores in this case).
  • min_instance_count: The minimum number of instances of the function to keep running (1 in this case).
  • max_instance_count: The maximum number of instances that can be created for the function (1000 in this case).
  • max_instance_request_concurrency: The maximum number of concurrent requests that each instance of the function can handle (10 in this case).

Event Trigger Configuration:

  • There’s no event trigger configuration provided in this snippet, as HTTP-triggered functions do not require event triggers. Instead, they’re invoked directly via HTTP requests.

Timeout:

  • timeout: The maximum amount of time the function is allowed to run before being terminated (180 seconds in this case).

This configuration file defines how the Cloud Function will be deployed and how it will respond to events triggered in Google Cloud Storage.

Refer:

https://codelabs.developers.google.com/codelabs/cloud-starting-cloudfunctions-v2

https://developer.harness.io/docs/continuous-delivery/get-started/cd-tutorials/gcp-cloud-func/?generation=2g

Follow Me →

--

--