-
Notifications
You must be signed in to change notification settings - Fork 228
Migrate gsutil usage to gcloud storage #4314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
7e165da
7e2db68
8589909
50db888
427dcfc
bb31a00
38e3c2c
cff974d
69bf480
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,11 +154,10 @@ | |
| "if BUCKET_URI is None or BUCKET_URI.strip() == \"\" or BUCKET_URI == \"gs://\":\n", | ||
| " BUCKET_URI = f\"gs://{PROJECT_ID}-tmp-{now}-{str(uuid.uuid4())[:4]}\"\n", | ||
| " BUCKET_NAME = \"/\".join(BUCKET_URI.split(\"/\")[:3])\n", | ||
| " ! gsutil mb -l {REGION} {BUCKET_URI}\n", | ||
| "else:\n", | ||
| " ! gcloud storage buckets create --location {REGION} {BUCKET_URI}\n", "else:\n", | ||
| " assert BUCKET_URI.startswith(\"gs://\"), \"BUCKET_URI must start with `gs://`.\"\n", | ||
| " shell_output = ! gsutil ls -Lb {BUCKET_NAME} | grep \"Location constraint:\" | sed \"s/Location constraint://\"\n", | ||
| " bucket_region = shell_output[0].strip().lower()\n", | ||
| # Note: The format of the full listing output is different. gcloud storage uses a title case for keys and will not display a field if its value is "None". | ||
| " shell_output = ! gcloud storage ls --full --buckets {BUCKET_NAME} | grep \"Location constraint:\" | sed \"s/Location constraint://\"\n", " bucket_region = shell_output[0].strip().lower()\n", | ||
|
||
| " if bucket_region != REGION:\n", | ||
| " raise ValueError(\n", | ||
| " \"Bucket region %s is different from notebook region %s\"\n", | ||
|
|
@@ -182,8 +181,9 @@ | |
| "\n", | ||
| "\n", | ||
| "# Provision permissions to the SERVICE_ACCOUNT with the GCS bucket\n", | ||
| "! gsutil iam ch serviceAccount:{SERVICE_ACCOUNT}:roles/storage.admin $BUCKET_NAME\n", | ||
| "\n", | ||
| "! # Note: Migrating scripts using gsutil iam ch is more complex than get or set. You need to replace the single iam ch command with a series of gcloud storage bucket add-iam-policy-binding and/or gcloud storage bucket remove-iam-policy-binding commands, or replicate the read-modify-write loop.\n", | ||
| "! # Note: Conditions: gsutil iam ch does not support modifying IAM policies that contain conditions. gcloud storage commands do support conditions.\n", | ||
| "! gcloud storage buckets add-iam-policy-binding $BUCKET_NAME --member=serviceAccount:{SERVICE_ACCOUNT} --role=roles/storage.admin\n", "\n", | ||
| "! gcloud config set project $PROJECT_ID\n", | ||
| "! gcloud projects add-iam-policy-binding --no-user-output-enabled {PROJECT_ID} --member=serviceAccount:{SERVICE_ACCOUNT} --role=\"roles/storage.admin\"\n", | ||
| "! gcloud projects add-iam-policy-binding --no-user-output-enabled {PROJECT_ID} --member=serviceAccount:{SERVICE_ACCOUNT} --role=\"roles/aiplatform.user\"" | ||
|
|
@@ -238,8 +238,7 @@ | |
| "\n", | ||
| " ! mkdir -p ./codegemma\n", | ||
| " ! curl -X GET \"{signed_url}\" | tar -xzvf - -C ./codegemma/\n", | ||
| " ! gsutil -m cp -R ./codegemma/* {BUCKET_URI}\n", | ||
| "\n", | ||
| " ! gcloud storage cp --recursive ./codegemma/* {BUCKET_URI}\n", "\n", | ||
| " model_path_prefix = BUCKET_URI.strip(\"/\") + \"/codegemma\"\n", | ||
| "else:\n", | ||
| " model_path_prefix = \"google/\"" | ||
|
|
@@ -820,8 +819,7 @@ | |
| "\n", | ||
| "delete_bucket = False # @param {type:\"boolean\"}\n", | ||
| "if delete_bucket:\n", | ||
| " ! gsutil -m rm -r $BUCKET_NAME" | ||
| ] | ||
| " ! gcloud storage rm --recursive $BUCKET_NAME" ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -472,8 +472,7 @@ | |
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "! gsutil mb -l $REGION $BUCKET_NAME" | ||
| ] | ||
| "! gcloud storage buckets create --location=$REGION $BUCKET_NAME" ] | ||
|
||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
|
|
@@ -492,8 +491,7 @@ | |
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "! gsutil ls -al $BUCKET_NAME" | ||
| ] | ||
| "! gcloud storage ls --all-versions --long $BUCKET_NAME" ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
|
|
@@ -596,14 +594,11 @@ | |
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "count = ! gsutil cat $IMPORT_FILE | wc -l\n", | ||
| "print(\"Number of Examples\", int(count[0]))\n", | ||
| "count = ! gcloud storage cat $IMPORT_FILE | wc -l\n", "print(\"Number of Examples\", int(count[0]))\n", | ||
| "\n", | ||
| "print(\"First 10 rows\")\n", | ||
| "! gsutil cat $IMPORT_FILE | head\n", | ||
| "\n", | ||
| "heading = ! gsutil cat $IMPORT_FILE | head -n1\n", | ||
| "label_column = str(heading).split(\",\")[-1].split(\"'\")[0]\n", | ||
| "! gcloud storage cat $IMPORT_FILE | head\n", "\n", | ||
| "heading = ! gcloud storage cat $IMPORT_FILE | head -n1\n", "label_column = str(heading).split(\",\")[-1].split(\"'\")[0]\n", | ||
| "print(\"Label Column Name\", label_column)\n", | ||
| "if label_column is None:\n", | ||
| " raise Exception(\"label column missing\")" | ||
|
|
@@ -832,15 +827,12 @@ | |
| "source": [ | ||
| "print(\"Model Package:\", model_package)\n", | ||
| "print(\"Contents:\")\n", | ||
| "! gsutil ls $model_package\n", | ||
| "\n", | ||
| "! gcloud storage ls $model_package\n", "\n", | ||
| "print(\"\\nTF Saved Model\")\n", | ||
| "path = model_package + \"/predict\"\n", | ||
| "files = ! gsutil ls $path\n", | ||
| "saved_dir = files[1]\n", | ||
| "files = ! gcloud storage ls $path\n", "saved_dir = files[1]\n", | ||
| "print(saved_dir)\n", | ||
| "! gsutil ls $saved_dir" | ||
| ] | ||
| "! gcloud storage ls $saved_dir" ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
|
|
@@ -861,8 +853,7 @@ | |
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "! gsutil cp -r $model_package ." | ||
| ] | ||
| "! gcloud storage cp --recursive $model_package ." ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
|
|
@@ -1155,8 +1146,7 @@ | |
| " print(e)\n", | ||
| "\n", | ||
| " if \"BUCKET_NAME\" in globals():\n", | ||
| " ! gsutil rm -r $BUCKET_NAME" | ||
| ] | ||
| " ! gcloud storage rm --recursive $BUCKET_NAME" ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with other commands in this pull request and general
gcloudcommand-line style, it's better to use a space to separate the--locationflag and its value, rather than an equals sign.