https://cloud.google.com/batch/docs/locations?hl=ja
※東京リージョンはbatchを使用できない
-- 1. 前作業
gcloud init
gcloud auth list
gcloud --version
gcloud projects create project01-9999999 \
--name="project01"
gcloud config list
gcloud config set project project01-9999999
gcloud config set compute/region asia-southeast1 --quiet
gcloud config set compute/zone asia-southeast1-a --quiet
gcloud beta billing accounts list
gcloud beta billing projects link project01-9999999 --billing-account=111111-111111-111111
gcloud services enable compute.googleapis.com --project project01-9999999
gcloud components update
-- 2. Batch for APIs を有効にします
gcloud services list --enabled
gcloud services enable batch.googleapis.com \
--project project01-9999999
-- 3. 基本的なスクリプト ジョブを作成する
{
"taskGroups": [
{
"taskSpec": {
"runnables": [
{
"script": {
"text": "echo Hello world! This is task ${BATCH_TASK_INDEX}. This job has a total of ${BATCH_TASK_COUNT} tasks."
}
}
],
"computeResource": {
"cpuMilli": 1000,
"memoryMib": 16
},
"maxRetryCount": 1,
"maxRunDuration": "3600s"
},
"taskCount": 1,
"parallelism": 1
}
],
"allocationPolicy": {
"instances": [
{
"policy": { "machineType": "e2-micro" }
}
]
},
"labels": {
"department": "finance",
"env": "testing"
},
"logsPolicy": {
"destination": "CLOUD_LOGGING"
}
}
gcloud batch jobs submit job01 \
--location asia-southeast1 \
--config a.json
-- 4. ジョブとタスクを表示する
gcloud batch jobs list
gcloud batch jobs describe job01 \
--location asia-southeast1
gcloud batch tasks list \
--location asia-southeast1 \
--job job01
gcloud batch tasks describe 0 \
--location asia-southeast1 \
--job job01 \
--task_group group0
-- 5. ジョブのログを表示する
gcloud logging read "labels.job_uid=j-11111111-1111-1111-1111-111111111111"
-- 6. クリーンアップ
gcloud batch jobs delete job01 \
--location asia-southeast1
gcloud projects list
gcloud projects delete project01-9999999 \
--quiet