# In this directory, run the following command to build this builder.
# $ gcloud builds submit . --config=cloudbuild.yaml

steps:
# Build the alpine and debian versions.
- name: 'gcr.io/cloud-builders/docker'
  args:
  - 'build'
  - '-f'
  - 'Dockerfile.alpine'
  - '--tag=gcr.io/$PROJECT_ID/go'
  - '--tag=gcr.io/$PROJECT_ID/go:1.15'
  - '--tag=gcr.io/$PROJECT_ID/go:alpine'
  - '--tag=gcr.io/$PROJECT_ID/go:alpine-1.15'
  - '.'
- name: 'gcr.io/cloud-builders/docker'
  args:
  - 'build'
  - '-f'
  - 'Dockerfile.debian'
  - '--tag=gcr.io/$PROJECT_ID/go:debian'
  - '--tag=gcr.io/$PROJECT_ID/go:debian-1.15'
  - '.'

# Go 1.16
- name: 'gcr.io/cloud-builders/docker'
  args:
  - 'build'
  - '-f'
  - 'Dockerfile.alpine'
  - '--build-arg=VERSION=1.16'
  - '--tag=gcr.io/$PROJECT_ID/go:alpine-1.16'
  - '--tag=gcr.io/$PROJECT_ID/go:1.16'
  - '.'
- name: 'gcr.io/cloud-builders/docker'
  args:
  - 'build'
  - '-f'
  - 'Dockerfile.debian'
  - '--build-arg=VERSION=1.16'
  - '--tag=gcr.io/$PROJECT_ID/go:debian-1.16'
  - '.'

# Go 1.17
- name: 'gcr.io/cloud-builders/docker'
  args:
  - 'build'
  - '-f'
  - 'Dockerfile.alpine'
  - '--build-arg=VERSION=1.17'
  - '--tag=gcr.io/$PROJECT_ID/go:alpine-1.17'
  - '--tag=gcr.io/$PROJECT_ID/go:1.17'
  - '.'
- name: 'gcr.io/cloud-builders/docker'
  args:
  - 'build'
  - '-f'
  - 'Dockerfile.debian'
  - '--build-arg=VERSION=1.17'
  - '--tag=gcr.io/$PROJECT_ID/go:debian-1.17'
  - '.'

# Go 1.18
- name: 'gcr.io/cloud-builders/docker'
  args:
  - 'build'
  - '-f'
  - 'Dockerfile.alpine'
  - '--build-arg=VERSION=1.18'
  - '--tag=gcr.io/$PROJECT_ID/go:alpine-1.18'
  - '--tag=gcr.io/$PROJECT_ID/go:1.18'
  - '.'
- name: 'gcr.io/cloud-builders/docker'
  args:
  - 'build'
  - '-f'
  - 'Dockerfile.debian'
  - '--build-arg=VERSION=1.18'
  - '--tag=gcr.io/$PROJECT_ID/go:debian-1.18'
  - '.'

  # Go 1.19
- name: 'gcr.io/cloud-builders/docker'
  args:
    - 'build'
    - '-f'
    - 'Dockerfile.alpine'
    - '--build-arg=VERSION=1.19'
    - '--tag=gcr.io/$PROJECT_ID/go:alpine-1.19'
    - '--tag=gcr.io/$PROJECT_ID/go:1.19'
    - '.'
- name: 'gcr.io/cloud-builders/docker'
  args:
    - 'build'
    - '-f'
    - 'Dockerfile.debian'
    - '--build-arg=VERSION=1.19'
    - '--tag=gcr.io/$PROJECT_ID/go:debian-1.19'
    - '.'

  # Go 1.20
- name: 'gcr.io/cloud-builders/docker'
  args:
    - 'build'
    - '-f'
    - 'Dockerfile.alpine'
    - '--build-arg=VERSION=1.20'
    - '--tag=gcr.io/$PROJECT_ID/go:alpine-1.20'
    - '--tag=gcr.io/$PROJECT_ID/go:1.20'
    - '.'
- name: 'gcr.io/cloud-builders/docker'
  args:
    - 'build'
    - '-f'
    - 'Dockerfile.debian'
    - '--build-arg=VERSION=1.20'
    - '--tag=gcr.io/$PROJECT_ID/go:debian-1.20'
    - '.'

  # Go 1.21
- name: 'gcr.io/cloud-builders/docker'
  args:
    - 'build'
    - '-f'
    - 'Dockerfile.alpine'
    - '--build-arg=VERSION=1.21'
    - '--tag=gcr.io/$PROJECT_ID/go:alpine-1.21'
    - '--tag=gcr.io/$PROJECT_ID/go:1.21'
    - '.'
- name: 'gcr.io/cloud-builders/docker'
  args:
    - 'build'
    - '-f'
    - 'Dockerfile.debian'
    - '--build-arg=VERSION=1.21'
    - '--tag=gcr.io/$PROJECT_ID/go:debian-1.21'
    - '.'

  # Go 1.22
- name: 'gcr.io/cloud-builders/docker'
  args:
    - 'build'
    - '-f'
    - 'Dockerfile.alpine'
    - '--build-arg=VERSION=1.22'
    - '--tag=gcr.io/$PROJECT_ID/go:alpine-1.22'
    - '--tag=gcr.io/$PROJECT_ID/go:1.22'
    - '.'
- name: 'gcr.io/cloud-builders/docker'
  args:
    - 'build'
    - '-f'
    - 'Dockerfile.debian'
    - '--build-arg=VERSION=1.22'
    - '--tag=gcr.io/$PROJECT_ID/go:debian-1.22'
    - '.'

# Ensure that "go get" works
- name: 'gcr.io/$PROJECT_ID/go:1.20'
  args: ['get', 'golang.org/x/net/context']
  env: ['GOPATH=/tmp']

# Test the examples.

- name: 'golang'
  args: ['go', 'build', '.']
  dir: 'examples/module'
- name: 'busybox'
  args: ['./module']
  dir: 'examples/module'

# examples/hello_world
- name: 'gcr.io/$PROJECT_ID/go:1.20'
  args: ['test', 'hello']
  env: ['PROJECT_ROOT=hello']
  dir: 'examples/hello_world'
- name: 'gcr.io/$PROJECT_ID/go:1.20'
  args: ['install', '.']
  env: ['PROJECT_ROOT=hello']
  dir: 'examples/hello_world'
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '.']
  dir: 'examples/hello_world'

# examples/whole_workspace
- name: 'gcr.io/$PROJECT_ID/go:1.20'
  args: ['test', 'hello']
  env: ['GOPATH=.']
  dir: 'examples/whole_workspace'
- name: 'gcr.io/$PROJECT_ID/go:1.20'
  args: ['install', 'hello']
  env: ['GOPATH=.']
  dir: 'examples/whole_workspace'
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '.']
  dir: 'examples/whole_workspace'

# examples/whole_workspace with an absolute path
- name: 'gcr.io/$PROJECT_ID/go:1.20'
  args: ['test', 'hello']
  env: ['GOPATH=/workspace/examples/whole_workspace']
  dir: 'examples/whole_workspace'
- name: 'gcr.io/$PROJECT_ID/go:1.20'
  args: ['install', 'hello']
  env: ['GOPATH=/workspace/examples/whole_workspace']
  dir: 'examples/whole_workspace'
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '.']
  dir: 'examples/whole_workspace'

# examples/import_workspace
- name: 'gcr.io/$PROJECT_ID/go:1.20'
  args: ['test', 'hello']
  dir: 'examples/import_workspace'
- name: 'gcr.io/$PROJECT_ID/go:1.20'
  args: ['build', 'hello']
  dir: 'examples/import_workspace'
- name: 'gcr.io/$PROJECT_ID/go:1.20'
  args: ['install', 'hello']
  dir: 'examples/import_workspace'
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '.']
  dir: 'examples/import_workspace'

# examples/nested_workspace
- name: 'gcr.io/$PROJECT_ID/go:1.20'
  args: ['test', 'hello']
  env: ['GOPATH=subproject']
  dir: 'examples/nested_workspace'
- name: 'gcr.io/$PROJECT_ID/go:1.20'
  args: ['install', 'hello']
  env: ['GOPATH=subproject']
  dir: 'examples/nested_workspace'
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '.']
  dir: 'examples/nested_workspace'

# examples/https_test
# with alpine/default
- name: 'gcr.io/$PROJECT_ID/go:alpine-1.20'
  args: ['install', 'https_test']
  dir: 'examples/https_test'
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '-f', 'Dockerfile.alpine', '--tag=https_test:alpine', '.']
  dir: 'examples/https_test'
- name: 'gcr.io/cloud-builders/docker'
  args: ['run', 'https_test:alpine']
# clear out the alpine binary.
- name: 'alpine'
  args: ['rm', 'gopath/bin/https_test']
  dir: 'examples/https_test'
# with debian
- name: 'gcr.io/$PROJECT_ID/go:debian'
  args: ['install', 'https_test']
  dir: 'examples/https_test'
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '-f', 'Dockerfile.ubuntu', '--tag=https_test:ubuntu', '.']
  dir: 'examples/https_test'
- name: 'gcr.io/cloud-builders/docker'
  args: ['run', 'https_test:ubuntu']

options:
  env: ['GO111MODULE=auto']
images:
- 'gcr.io/$PROJECT_ID/go'
- 'gcr.io/$PROJECT_ID/go:alpine'
- 'gcr.io/$PROJECT_ID/go:debian'
- 'gcr.io/$PROJECT_ID/go:1.15'
- 'gcr.io/$PROJECT_ID/go:1.16'
- 'gcr.io/$PROJECT_ID/go:1.17'
- 'gcr.io/$PROJECT_ID/go:1.18'
- 'gcr.io/$PROJECT_ID/go:1.19'
- 'gcr.io/$PROJECT_ID/go:1.20'
- 'gcr.io/$PROJECT_ID/go:1.21'
- 'gcr.io/$PROJECT_ID/go:1.22'
- 'gcr.io/$PROJECT_ID/go:alpine-1.15'
- 'gcr.io/$PROJECT_ID/go:debian-1.15'
- 'gcr.io/$PROJECT_ID/go:alpine-1.16'
- 'gcr.io/$PROJECT_ID/go:debian-1.16'
- 'gcr.io/$PROJECT_ID/go:alpine-1.17'
- 'gcr.io/$PROJECT_ID/go:debian-1.17'
- 'gcr.io/$PROJECT_ID/go:alpine-1.18'
- 'gcr.io/$PROJECT_ID/go:debian-1.18'
- 'gcr.io/$PROJECT_ID/go:alpine-1.19'
- 'gcr.io/$PROJECT_ID/go:debian-1.19'
- 'gcr.io/$PROJECT_ID/go:alpine-1.20'
- 'gcr.io/$PROJECT_ID/go:debian-1.20'
- 'gcr.io/$PROJECT_ID/go:alpine-1.21'
- 'gcr.io/$PROJECT_ID/go:debian-1.21'
- 'gcr.io/$PROJECT_ID/go:alpine-1.22'
- 'gcr.io/$PROJECT_ID/go:debian-1.22'

timeout: 2400s
