Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dd5e55b

Browse filesBrowse files
t-karasovatetiana-karasovaparthea
authored
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 <tetiana.karasova@gmail.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent eb8badb commit dd5e55b
Copy full SHA for dd5e55b

File tree

Expand file treeCollapse file tree

2 files changed

+85
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+85
-0
lines changed
+52Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
# Copyright 2022 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# get the project_id from gcloud config
18+
project_id=$(gcloud config get-value project)
19+
echo $project_id
20+
timestamp=$(date +%s)
21+
echo $timestamp
22+
service_account_id="service-acc-"$timestamp
23+
24+
# create service account (your project_id+timestamp)
25+
gcloud iam service-accounts create $service_account_id
26+
27+
# assign needed roles to your new service account
28+
for role in {retail.admin,storage.admin,bigquery.admin}
29+
do
30+
gcloud projects add-iam-policy-binding $project_id --member="serviceAccount:"$service_account_id"@"$project_id".iam.gserviceaccount.com" --role="roles/${role}"
31+
done
32+
33+
# upload your service account key file
34+
service_acc_email=$service_account_id"@"$project_id".iam.gserviceaccount.com"
35+
gcloud iam service-accounts keys create ~/key.json --iam-account $service_acc_email
36+
37+
# activate the service account using the key
38+
gcloud auth activate-service-account --key-file ~/key.json
39+
40+
# set the key as GOOGLE_APPLICATION_CREDENTIALS
41+
export GOOGLE_APPLICATION_CREDENTIALS=~/key.json
42+
43+
# install needed Google client libraries
44+
virtualenv -p python3 myenv
45+
source myenv/bin/activate
46+
47+
pip install google
48+
pip install google-cloud-retail
49+
pip install google-cloud.storage
50+
pip install google-cloud.bigquery
51+
52+
echo "Your working environment is set up now!"
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
# Copyright 2022 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Change the working directory
18+
current_path=$(pwd)
19+
temp_path="${current_path%cloudshell_open*}"
20+
full_path=temp_path"cloudshell_open/python-retail/samples/interactive-tutorials/product"
21+
22+
# Create a GCS bucket and upload the product data to the bucket
23+
output=$(python setup_product/products_create_gcs_bucket.py)
24+
25+
# Get the bucket name and store it in the env variable BUCKET_NAME
26+
temp="${output#*The gcs bucket }"
27+
bucket_name="${temp% was created*}"
28+
export BUCKET_NAME=$bucket_name
29+
30+
# Import products to the Retail catalog
31+
python import_products_gcs.py
32+
echo "Products are successfully imported to catalog"
33+
echo "Your Retail catalog is ready to use!"

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.