This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(samples): the bash scripts for environment setup are added (#392)
* Update README * the bash scripts are added * Update README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Update user_environment_setup.sh * Update user_import_data_to_catalog.sh * Update README.md Co-authored-by: tetiana-karasova <tetiana.karasova@gmail.com> Co-authored-by: Sergey Borisenko <78493601+sborisenkox@users.noreply.github.com> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Karl Weinmeister <11586922+kweinmeister@users.noreply.github.com>
- Loading branch information
1 parent
27fda5f
commit a20b6fb
Showing
3 changed files
with
180 additions
and
49 deletions.
There are no files selected for viewing
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
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,53 @@ | ||
#!/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. | ||
|
||
# set the Google Cloud Project ID | ||
project_id=$1 | ||
echo "Project ID: $project_id" | ||
gcloud config set project "$project_id" | ||
|
||
timestamp=$(date +%s) | ||
|
||
service_account_id="service-acc-$timestamp" | ||
echo "Service Account: $service_account_id" | ||
|
||
# create service account (your service-acc-$timestamp) | ||
gcloud iam service-accounts create "$service_account_id" | ||
|
||
# assign necessary roles to your new service account | ||
for role in {retail.admin,editor,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 | ||
|
||
echo "Wait ~60 seconds to be sure the appropriate roles have been assigned to your service account" | ||
sleep 60 | ||
|
||
# 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 | ||
|
||
# install needed Google client libraries | ||
cd ~/cloudshell_open/java-retail/samples/interactive-tutorials || exit | ||
mvn clean install -DskipTests | ||
|
||
echo "========================================" | ||
echo "The Google Cloud setup is completed." | ||
echo "Please proceed with the Tutorial steps" | ||
echo "========================================" |
36 changes: 36 additions & 0 deletions
36
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,36 @@ | ||
#!/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. | ||
|
||
# set the key as GOOGLE_APPLICATION_CREDENTIALS | ||
export GOOGLE_APPLICATION_CREDENTIALS=~/key.json | ||
|
||
# Change the working directory | ||
cd ~/cloudshell_open/java-retail/samples/interactive-tutorials/ || exit | ||
|
||
# Run the sample for creating the GCS bucket and extract the output of that execution | ||
output=$(mvn compile exec:java -Dexec.mainClass="product.setup.ProductsCreateGcsBucket") | ||
|
||
# Get the bucket name and store it in the env variable BUCKET_NAME | ||
temp="${output#*gcs bucket }" | ||
bucket_name="${temp% was created*}" | ||
export BUCKET_NAME=$bucket_name | ||
|
||
# Import products to the Retail catalog | ||
mvn compile exec:java -Dexec.mainClass="product.ImportProductsGcs" | ||
|
||
echo "=====================================" | ||
echo "Your Retail catalog is ready to use!" | ||
echo "=====================================" |