This demo adds a new service to Online Boutique called shoppingassistantservice
which, alongside an Alloy-DB backed products catalog, adds a RAG-featured AI assistant to the frontned experience, helping users suggest products matching their home decor.
Note: This demo requires a Google Cloud project where you to have the owner
role, else you may be unable to enable APIs or modify VPC rules that are needed for this demo.
-
Set some environment variables.
export PROJECT_ID=<project_id> export PROJECT_NUMBER=<project_number> export PGPASSWORD=<pgpassword>
Note: The project ID and project number of your Google Cloud project can be found in the Console. The PostgreSQL password can be set to anything you want, but make sure to note it down.
-
Change your default Google Cloud project.
gcloud auth login gcloud config set project $PROJECT_ID
-
Enable the Google Kubernetes Engine (GKE) and Artifact Registry (AR) APIs.
gcloud services enable container.googleapis.com gcloud services enable artifactregistry.googleapis.com
-
Create a GKE Autopilot cluster. This may take a few minutes.
gcloud container clusters create-auto cymbal-shops \ --region=us-central1
-
Change your Kubernetes context to your newly created GKE cluster.
gcloud container clusters get-credentials cymbal-shops \ --region us-central1
-
Create an Artifact Registry container image repository.
gcloud artifacts repositories create images \ --repository-format=docker \ --location=us-central1
-
Clone the
microservices-demo
repository locally.git clone https://github.com/GoogleCloudPlatform/microservices-demo \ && cd microservices-demo/
-
Run script #1. If it asks about policy bindings, select the option
None
. This may take a few minutes../kustomize/components/shopping-assistant/scripts/1_deploy_alloydb_infra.sh
Note: If you are on macOS and use a non-GNU version of
sed
, you may have to tweak the script to usegsed
instead. -
Create a Linux VM in Compute Engine (GCE).
gcloud compute instances create gce-linux \ --zone=us-central1-a \ --machine-type=e2-micro \ --image-family=debian-12 \ --image-project=debian-cloud
-
SSH into the VM. From here until we exit, all steps happen in the VM.
gcloud compute ssh gce-linux \ --zone "us-central1-a"
-
Install the Postgres client and set your default Google Cloud project.
sudo apt-get install -y postgresql-client gcloud auth login gcloud config set project <PROJECT_ID>
-
Copy script #2, the python script, and the products.json to the VM. Make sure the scripts are executable.
nano 2_create_populate_alloydb_tables.sh # paste content nano generate_sql_from_products.py # paste content nano products.json # paste content chmod +x 2_create_populate_alloydb_tables.sh chmod +x generate_sql_from_products.py
Note: You can find the files at the following places:
kustomize/components/shopping-assistant/scripts/2_create_populate_alloydb_tables.sh
kustomize/components/shopping-assistant/scripts/generate_sql_from_products.py
src/productcatalogservice/products.json
-
Run script #2 in the VM. If it asks for a postgres password, it should be the same that you set in script #1 earlier. This may take a few minutes.
./2_create_populate_alloydb_tables.sh
-
Exit SSH.
exit
-
Create an API key in the Credentials page with permissions for "Generative Language API", and make note of the secret key.
-
Replace the Google API key placeholder in the shoppingassistant service.
export GOOGLE_API_KEY=<google_api_key> sed -i "s/GOOGLE_API_KEY_VAL/${GOOGLE_API_KEY}/g" kustomize/components/shopping-assistant/shoppingassistantservice.yaml
-
Edit the root Kustomize file to enable the
alloydb
andshopping-assistant
components.nano kubernetes-manifests/kustomization.yaml # make the modifications below
# ...head of the file components: # remove this comment # - ../kustomize/components/cymbal-branding # - ../kustomize/components/google-cloud-operations # - ../kustomize/components/memorystore # - ../kustomize/components/network-policies - ../kustomize/components/alloydb # remove this comment - ../kustomize/components/shopping-assistant # remove this comment # - ../kustomize/components/spanner # - ../kustomize/components/container-images-tag # - ../kustomize/components/container-images-tag-suffix # - ../kustomize/components/container-images-registry
-
Deploy to the GKE cluster.
skaffold run --default-repo=us-central1-docker.pkg.dev/$PROJECT_ID/images
-
Wait for all the pods to be up and running. You can then find the external IP and navigate to it.
kubectl get pods kubectl get services