This folder contains the infrastructure-as-code and CI/CD pipeline configurations for deploying a conversational Generative AI application on Google Cloud.
The application leverages Terraform to define and provision the underlying infrastructure, while Cloud Build orchestrates the continuous integration and continuous deployment (CI/CD) pipeline.
Description:
-
CI Pipeline (
deployment/ci/pr_checks.yaml
):- Triggered on pull request creation/update
- Runs unit and integration tests
-
CD Pipeline (
deployment/cd/staging.yaml
):- Triggered on merge to
main
branch - Builds and pushes application to Artifact Registry
- Deploys to staging environment (Cloud Run)
- Performs load testing
- Triggered on merge to
-
Production Deployment (
deployment/cd/deploy-to-prod.yaml
):- Triggered after successful staging deployment
- Requires manual approval
- Deploys to production environment
Prerequisites:
-
A set of Google Cloud projects:
- Staging project
- Production project
- CI/CD project (can be the same as staging or production)
-
Terraform installed on your local machine
-
Enable required APIs in the CI/CD project. This will be required for the Terraform deployment:
gcloud config set project $YOUR_CI_CD_PROJECT_ID gcloud services enable serviceusage.googleapis.com cloudresourcemanager.googleapis.com cloudbuild.googleapis.com secretmanager.googleapis.com
-
Create a Git Repository using your favorite Git provider (GitHub, GitLab, Bitbucket, etc.)
-
Connect Your Repository to Cloud Build For detailed instructions, visit: Cloud Build Repository Setup.
-
Configure Terraform Variables
- Edit
deployment/terraform/vars/env.tfvars
with your Google Cloud settings.
Variable Description Required prod_project_id Production Google Cloud Project ID for resource deployment. Yes staging_project_id Staging Google Cloud Project ID for resource deployment. Yes cicd_runner_project_id Google Cloud Project ID where CI/CD pipelines will execute. Yes region Google Cloud region for resource deployment. Yes host_connection_name Name of the host connection you created in Cloud Build Yes repository_name Name of the repository you added to Cloud Build Yes Other optional variables include: telemetry and feedback BigQuery dataset IDs, log filters, sink names, service account names, bucket name suffixes, artifact registry repository name, and various role assignments for Cloud Run and CICD.
- Edit
-
Deploy Infrastructure with Terraform
- Open a terminal and navigate to the Terraform directory:
cd deployment/terraform
- Initialize Terraform:
terraform init
- Apply the Terraform configuration:
terraform apply --var-file vars/env.tfvars
- Type 'yes' when prompted to confirm
After completing these steps, your infrastructure will be set up and ready for deployment!
For End-to-end testing of the application, including tracing and feedback sinking to BigQuery, without the need to trigger a CI/CD pipeline.
After you edited the relative env.tfvars
file, follow the following instructions:
cd deployment/terraform/dev
terraform init
terraform apply --var-file vars/env.tfvars
Then deploy the application using the following command (from the root of the repository):
gcloud run deploy genai-app-sample --source . --project $YOUR_DEV_PROJECT_ID --service-account genai-app-sample-cr-sa@$YOUR_DEV_PROJECT_ID.iam.gserviceaccount.com