Skip to content

Commit

Permalink
chore: Scripts were added to simplify the work environment creation (#…
Browse files Browse the repository at this point in the history
…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
3 people authored Mar 15, 2022
1 parent eb8badb commit dd5e55b
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
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!"
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!"

0 comments on commit dd5e55b

Please sign in to comment.