Skip to content

Commit

Permalink
busybox sample: Fix and update to use connector GoogleCloudPlatform#30
Browse files Browse the repository at this point in the history
  • Loading branch information
meteatamel committed May 25, 2023
1 parent d026683 commit 134e1ca
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 52 deletions.
4 changes: 4 additions & 0 deletions busybox/setup-workflow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
74 changes: 22 additions & 52 deletions busybox/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 134e1ca

Please sign in to comment.