diff --git a/busybox/setup-workflow.sh b/busybox/setup-workflow.sh index 003a914..ed3cb38 100755 --- a/busybox/setup-workflow.sh +++ b/busybox/setup-workflow.sh @@ -31,6 +31,10 @@ gcloud projects add-iam-policy-binding $PROJECT_ID \ --member serviceAccount:$SERVICE_ACCOUNT@$PROJECT_ID.iam.gserviceaccount.com \ --role roles/batch.jobsAdmin +gcloud projects add-iam-policy-binding $PROJECT_ID \ + --member serviceAccount:$SERVICE_ACCOUNT@$PROJECT_ID.iam.gserviceaccount.com \ + --role roles/iam.serviceAccountUser + gcloud projects add-iam-policy-binding $PROJECT_ID \ --member serviceAccount:$SERVICE_ACCOUNT@$PROJECT_ID.iam.gserviceaccount.com \ --role roles/logging.logWriter diff --git a/busybox/workflow.yaml b/busybox/workflow.yaml index af431b3..7a90105 100644 --- a/busybox/workflow.yaml +++ b/busybox/workflow.yaml @@ -18,72 +18,42 @@ main: assign: - projectId: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")} - region: "us-central1" - - batchApi: "batch.googleapis.com/v1" - - batchApiUrl: ${"https://" + batchApi + "/projects/" + projectId + "/locations/" + region + "/jobs"} - jobId: ${"job-busybox-" + string(int(sys.now()))} - logCreateBatchJob: call: sys.log args: data: ${"Creating and running the batch job " + jobId} - createAndRunBatchJob: - call: http.post + call: googleapis.batch.v1.projects.locations.jobs.create args: - url: ${batchApiUrl} - query: - job_id: ${jobId} - headers: - Content-Type: application/json - auth: - type: OAuth2 - body: - taskGroups: - - taskSpec: - runnables: - - container: - imageUri: busybox - entrypoint: "/bin/sh" - commands: - - "-c" - - "echo task index: ${BATCH_TASK_INDEX} bucket: ${BUCKET}" - environment: - variables: - BUCKET: batch-test-bucket - taskCount: 3 - logsPolicy: - destination: CLOUD_LOGGING + parent: ${"projects/" + projectId + "/locations/" + region} + jobId: ${jobId} + body: + taskGroups: + - taskSpec: + runnables: + - container: + imageUri: busybox + entrypoint: "/bin/sh" + commands: + - "-c" + - "echo task index: ${BATCH_TASK_INDEX} bucket: ${BUCKET}" + environment: + variables: + BUCKET: batch-test-bucket + taskCount: 3 + logsPolicy: + destination: CLOUD_LOGGING result: createAndRunBatchJobResponse - - getJob: - call: http.get - args: - url: ${batchApiUrl + "/" + jobId} - auth: - type: OAuth2 - result: getJobResult - - logState: - call: sys.log - args: - data: ${"Current job state " + getJobResult.body.status.state} - - assertSucceeded: - switch: - - condition: ${getJobResult.body.status.state == "SUCCEEDED"} - next: logDeleteBatchJob - next: sleep - - sleep: - call: sys.sleep - args: - seconds: 10 - next: getJob - logDeleteBatchJob: call: sys.log args: data: ${"Deleting the batch job " + jobId} - deleteBatchJob: - call: http.delete + call: googleapis.batch.v1.projects.locations.jobs.delete args: - url: ${batchApiUrl + "/" + jobId} - auth: - type: OAuth2 - result: deleteBatchJob + name: ${"projects/" + projectId + "/locations/" + region + "/jobs/" + jobId} + result: deleteResult - returnResult: return: jobId: ${jobId}