Skip to content

Commit

Permalink
fix: add an error message on user environment setup in case of any er…
Browse files Browse the repository at this point in the history
…rors. (#292)

Co-authored-by: Anthonios Partheniou <partheniou@google.com>
  • Loading branch information
kchertenko and parthea authored Jul 19, 2022
1 parent fecd579 commit eaae346
Showing 1 changed file with 46 additions and 39 deletions.
85 changes: 46 additions & 39 deletions generated_samples/interactive-tutorials/user_environment_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,53 @@
# 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"
{
# set the Google Cloud Project ID
project_id=$1
echo "Project ID: $project_id"
gcloud config set project "$project_id"
} && {
timestamp=$(date +%s)

timestamp=$(date +%s)
service_account_id="service-acc-$timestamp"
echo "Service Account: $service_account_id"

service_account_id="service-acc-$timestamp"
echo "Service Account: $service_account_id"
# create service account
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

# create service account
gcloud iam service-accounts create "$service_account_id"
# 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 necessary Google client libraries
virtualenv -p python3 myenv
source myenv/bin/activate
sleep 2

# 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 necessary Google client libraries
virtualenv -p python3 myenv
source myenv/bin/activate
sleep 2

pip install google
pip install google-cloud-retail
pip install google-cloud.storage
pip install google-cloud.bigquery

echo "======================================="
echo "The Google Cloud setup is completed."
echo "Please proceed with the Tutorial steps"
echo "======================================="
pip install google &&
pip install google-cloud-retail &&
pip install google-cloud.storage &&
pip install google-cloud.bigquery
} && {
echo "======================================="
echo "The Google Cloud setup is completed."
echo "Please proceed with the Tutorial steps"
echo "======================================="
} || {
echo "======================================="
echo "The Google Cloud setup was not completed."
echo "Please fix the errors above!"
echo "======================================="
}

0 comments on commit eaae346

Please sign in to comment.