-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Scripts were added to simplify the work environment creation (#…
…187) * feat: added scripts to simplify work env setup * fixes for the scripts Co-authored-by: tetiana-karasova <[email protected]> Co-authored-by: Anthonios Partheniou <[email protected]>
- Loading branch information
1 parent
eb8badb
commit dd5e55b
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
packages/google-cloud-retail/samples/interactive-tutorials/user_environment_setup.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2022 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# get the project_id from gcloud config | ||
project_id=$(gcloud config get-value project) | ||
echo $project_id | ||
timestamp=$(date +%s) | ||
echo $timestamp | ||
service_account_id="service-acc-"$timestamp | ||
|
||
# create service account (your project_id+timestamp) | ||
gcloud iam service-accounts create $service_account_id | ||
|
||
# assign needed roles to your new service account | ||
for role in {retail.admin,storage.admin,bigquery.admin} | ||
do | ||
gcloud projects add-iam-policy-binding $project_id --member="serviceAccount:"$service_account_id"@"$project_id".iam.gserviceaccount.com" --role="roles/${role}" | ||
done | ||
|
||
# upload your service account key file | ||
service_acc_email=$service_account_id"@"$project_id".iam.gserviceaccount.com" | ||
gcloud iam service-accounts keys create ~/key.json --iam-account $service_acc_email | ||
|
||
# activate the service account using the key | ||
gcloud auth activate-service-account --key-file ~/key.json | ||
|
||
# set the key as GOOGLE_APPLICATION_CREDENTIALS | ||
export GOOGLE_APPLICATION_CREDENTIALS=~/key.json | ||
|
||
# install needed Google client libraries | ||
virtualenv -p python3 myenv | ||
source myenv/bin/activate | ||
|
||
pip install google | ||
pip install google-cloud-retail | ||
pip install google-cloud.storage | ||
pip install google-cloud.bigquery | ||
|
||
echo "Your working environment is set up now!" |
33 changes: 33 additions & 0 deletions
33
packages/google-cloud-retail/samples/interactive-tutorials/user_import_data_to_catalog.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2022 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Change the working directory | ||
current_path=$(pwd) | ||
temp_path="${current_path%cloudshell_open*}" | ||
full_path=temp_path"cloudshell_open/python-retail/samples/interactive-tutorials/product" | ||
|
||
# Create a GCS bucket and upload the product data to the bucket | ||
output=$(python setup_product/products_create_gcs_bucket.py) | ||
|
||
# Get the bucket name and store it in the env variable BUCKET_NAME | ||
temp="${output#*The gcs bucket }" | ||
bucket_name="${temp% was created*}" | ||
export BUCKET_NAME=$bucket_name | ||
|
||
# Import products to the Retail catalog | ||
python import_products_gcs.py | ||
echo "Products are successfully imported to catalog" | ||
echo "Your Retail catalog is ready to use!" |