cloudbuild.yaml 1.99 KB
Newer Older
zhanggzh's avatar
zhanggzh committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
substitutions:
  # GCS bucket name.
  _GCS_BUCKET: 'gs://keras-cv-github-test'
  # GKE cluster name.
  _CLUSTER_NAME: 'keras-cv-test-cluster'
  # Location of GKE cluster.
  _CLUSTER_ZONE: 'us-west1-b'
  # Image name.
  _IMAGE_NAME: 'us-west1-docker.pkg.dev/keras-team-test/keras-cv-test/keras-cv-image'
steps:
- name: 'docker'
  id: build-image
  args: [
    'build',
    '.',
    '-f', 'cloudbuild/Dockerfile',
    '-t', '$_IMAGE_NAME:$BUILD_ID',
  ]
- name: 'docker'
  id: push-image
  waitFor:
  - build-image
  args: ['push', '$_IMAGE_NAME:$BUILD_ID']
- name: 'golang'
  id: download-jsonnet
  waitFor: ['-']
  entrypoint: 'go'
  args: [
    'install',
    'github.com/google/go-jsonnet/cmd/jsonnet@latest',
  ]
- name: 'google/cloud-sdk'
  id: clone-templates
  waitFor: ['-']
  entrypoint: 'git'
  args: [
    'clone',
    'https://github.com/GoogleCloudPlatform/ml-testing-accelerators.git',
  ]
- name: 'golang'
  id: build-templates
  waitFor:
  - download-jsonnet
  - clone-templates
  entrypoint: 'jsonnet'
  args: [
    'cloudbuild/unit_test_jobs.jsonnet',
    '--string',
    '-J', 'ml-testing-accelerators',
    '--ext-str', 'image=$_IMAGE_NAME',
    '--ext-str', 'tag_name=$BUILD_ID',
    '--ext-str', 'gcs_bucket=$_GCS_BUCKET',
    '-o', 'output.yaml',
  ]
- name: 'google/cloud-sdk'
  id: create-job
  waitFor:
  - push-image
  - build-templates
  entrypoint: bash
  args:
  - -c
  - |
    set -u
    set -e
    set -x
    gcloud container clusters get-credentials $_CLUSTER_NAME --zone $_CLUSTER_ZONE --project keras-team-test
    job_name=$(kubectl create -f output.yaml -o name)
    sleep 5
    pod_name=$(kubectl wait --for condition=ready --timeout=10m pod -l job-name=${job_name#job.batch/} -o name)
    kubectl logs -f $pod_name --container=train
    sleep 5
    gcloud artifacts docker images delete $_IMAGE_NAME:$BUILD_ID
    exit $(kubectl get $pod_name -o jsonpath={.status.containerStatuses[0].state.terminated.exitCode})
timeout: 1800s  # 30 minutes
options:
  volumes:
  - name: go-modules
    path: /go