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

# Increase timeout to 30 minutes
timeout: 1800s

# Use a bigger machine type to support concurrent docker builds
options:
  machineType: 'N1_HIGHCPU_32'

steps:

##############################################################################
# GPDB 5 Images
##############################################################################

# An image for gpdb5 running on CentOS7
- name: 'gcr.io/cloud-builders/docker'
  id: gpdb5-centos7-test-pxf-image-cache
  entrypoint: 'bash'
  args:
  - '-c'
  - |
    mkdir -p /workspace/build
    docker pull gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb5-centos7-test-pxf:latest || exit 0
  waitFor: ['-']

- name: 'gcr.io/cloud-builders/docker'
  id: gpdb5-centos7-test-pxf-image
  args:
  - 'build'
  - '--build-arg=BASE_IMAGE=${_BASE_IMAGE_REPOSITORY}/gpdb5-centos7-build-test:latest'
  - '--build-arg=GINKGO_VERSION=${_GINKGO_VERSION}'
  - '--tag=gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb5-centos7-test-pxf:$COMMIT_SHA'
  - '--cache-from'
  - 'gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb5-centos7-test-pxf:latest'
  - '-f'
  - 'concourse/docker/pxf-dev-base/gpdb5/centos7/Dockerfile'
  - '/workspace/build/'
  waitFor:
    - gpdb5-centos7-test-pxf-image-cache

##############################################################################
# GPDB 6 Images
##############################################################################

# Corresponds to the docker-gpdb-pxf-dev-centos7 job in the docker pipeline
- name: 'gcr.io/cloud-builders/docker'
  id: gpdb6-centos7-test-pxf-image-cache
  entrypoint: 'bash'
  args:
  - '-c'
  - |
    mkdir -p /workspace/build
    docker pull gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb6-centos7-test-pxf:latest || exit 0
  waitFor: ['-']

- name: 'gcr.io/cloud-builders/docker'
  id: gpdb6-centos7-test-pxf-image
  args:
  - 'build'
  - '--build-arg=BASE_IMAGE=${_BASE_IMAGE_REPOSITORY}/gpdb6-centos7-test:latest'
  - '--build-arg=GO_VERSION=${_GO_VERSION}'
  - '--build-arg=GINKGO_VERSION=${_GINKGO_VERSION}'
  - '--tag=gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb6-centos7-test-pxf:$COMMIT_SHA'
  - '--cache-from'
  - 'gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb6-centos7-test-pxf:latest'
  - '-f'
  - 'concourse/docker/pxf-dev-base/gpdb6/centos7/Dockerfile'
  - '/workspace/build/'
  waitFor:
    - gpdb6-centos7-test-pxf-image-cache

# Corresponds to the docker-gpdb-pxf-dev-rhel8 job in the docker pipeline
- name: 'gcr.io/cloud-builders/docker'
  id: gpdb6-rhel8-test-pxf-image-cache
  entrypoint: 'bash'
  args:
  - '-c'
  - |
    mkdir -p /workspace/build
    docker pull gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb6-rhel8-test-pxf:latest || exit 0
  waitFor: ['-']

- name: 'gcr.io/cloud-builders/docker'
  id: gpdb6-rhel8-test-pxf-image
  args:
  - 'build'
  - '--build-arg=BASE_IMAGE=${_PRIVATE_BASE_IMAGE_REPOSITORY}/gpdb6-rhel8-test:latest'
  - '--build-arg=GINKGO_VERSION=${_GINKGO_VERSION}'
  - '--tag=gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb6-rhel8-test-pxf:$COMMIT_SHA'
  - '--cache-from'
  - 'gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb6-rhel8-test-pxf:latest'
  - '-f'
  - 'concourse/docker/pxf-dev-base/gpdb6/rhel8/Dockerfile'
  - '/workspace/build/'
  waitFor:
    - gpdb6-rhel8-test-pxf-image-cache

# Corresponds to the docker-gpdb-pxf-dev-ubuntu18 job in the docker pipeline
- name: 'gcr.io/cloud-builders/docker'
  id: gpdb6-ubuntu18.04-test-pxf-image-cache
  entrypoint: 'bash'
  args:
  - '-c'
  - |
    mkdir -p /workspace/build
    docker pull gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb6-ubuntu18.04-test-pxf:latest || exit 0
  waitFor: ['-']

- name: 'gcr.io/cloud-builders/docker'
  id: gpdb6-ubuntu18.04-test-pxf-image
  args:
  - 'build'
  - '--build-arg=BASE_IMAGE=${_BASE_IMAGE_REPOSITORY}/gpdb6-ubuntu18.04-test:latest'
  - '--build-arg=GO_VERSION=${_GO_VERSION}'
  - '--build-arg=GINKGO_VERSION=${_GINKGO_VERSION}'
  - '--tag=gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb6-ubuntu18.04-test-pxf:$COMMIT_SHA'
  - '--cache-from'
  - 'gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb6-ubuntu18.04-test-pxf:latest'
  - '-f'
  - 'concourse/docker/pxf-dev-base/gpdb6/ubuntu18.04/Dockerfile'
  - '/workspace/build/'
  waitFor:
    - gpdb6-ubuntu18.04-test-pxf-image-cache

# An image for gpdb6 running on OEL7
- name: 'gcr.io/cloud-builders/docker'
  id: gpdb6-oel7-test-pxf-image-cache
  entrypoint: 'bash'
  args:
  - '-c'
  - |
    mkdir -p /workspace/build
    docker pull gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb6-oel7-test-pxf:latest || exit 0
  waitFor: ['-']

- name: 'gcr.io/cloud-builders/docker'
  id: gpdb6-oel7-test-pxf-image
  args:
  - 'build'
  - '--build-arg=BASE_IMAGE=${_BASE_IMAGE_REPOSITORY}/gpdb6-oel7-test:latest'
  - '--build-arg=GO_VERSION=${_GO_VERSION}'
  - '--build-arg=GINKGO_VERSION=${_GINKGO_VERSION}'
  - '--tag=gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb6-oel7-test-pxf:$COMMIT_SHA'
  - '--cache-from'
  - 'gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb6-oel7-test-pxf:latest'
  - '-f'
  - 'concourse/docker/pxf-dev-base/gpdb6/oel7/Dockerfile'
  - '/workspace/build/'
  waitFor:
    - gpdb6-oel7-test-pxf-image-cache

##############################################################################
# GPDB 7 Images
##############################################################################

# Greenplum 7 Centos 7 Image
- name: 'gcr.io/cloud-builders/docker'
  id: gpdb7-centos7-test-pxf-image-cache
  entrypoint: 'bash'
  args:
    - '-c'
    - |
      mkdir -p /workspace/build
      docker pull gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb7-centos7-test-pxf:latest || exit 0
  waitFor: ['-']

- name: 'gcr.io/cloud-builders/docker'
  id: gpdb7-centos7-test-pxf-image
  args:
    - 'build'
    - '--build-arg=BASE_IMAGE=${_BASE_IMAGE_REPOSITORY}/gpdb7-centos7-test:latest'
    - '--build-arg=GO_VERSION=${_GO_VERSION}'
    - '--build-arg=GINKGO_VERSION=${_GINKGO_VERSION}'
    - '--tag=gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb7-centos7-test-pxf:$COMMIT_SHA'
    - '--cache-from'
    - 'gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb7-centos7-test-pxf:latest'
    - '-f'
    - 'concourse/docker/pxf-dev-base/gpdb7/centos7/Dockerfile'
    - '/workspace/build/'
  waitFor:
    - gpdb7-centos7-test-pxf-image-cache

# Greenplum 7 Rhel 8 Image
- name: 'gcr.io/cloud-builders/docker'
  id: gpdb7-rhel8-test-pxf-image-cache
  entrypoint: 'bash'
  args:
    - '-c'
    - |
      mkdir -p /workspace/build
      docker pull gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb7-rhel8-test-pxf:latest || exit 0
  waitFor: ['-']

- name: 'gcr.io/cloud-builders/docker'
  id: gpdb7-rhel8-test-pxf-image
  args:
    - 'build'
    - '--build-arg=BASE_IMAGE=${_PRIVATE_BASE_IMAGE_REPOSITORY}/gpdb7-rhel8-test:latest'
    - '--build-arg=GINKGO_VERSION=${_GINKGO_VERSION}'
    - '--tag=gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb7-rhel8-test-pxf:$COMMIT_SHA'
    - '--cache-from'
    - 'gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb7-rhel8-test-pxf:latest'
    - '-f'
    - 'concourse/docker/pxf-dev-base/gpdb7/rhel8/Dockerfile'
    - '/workspace/build/'
  waitFor:
    - gpdb7-rhel8-test-pxf-image-cache

# Greenplum 7 Ubuntu 18.04 Image
- name: 'gcr.io/cloud-builders/docker'
  id: gpdb7-ubuntu18.04-test-pxf-image-cache
  entrypoint: 'bash'
  args:
    - '-c'
    - |
      mkdir -p /workspace/build
      docker pull gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb7-ubuntu18.04-test-pxf:latest || exit 0
  waitFor: ['-']

- name: 'gcr.io/cloud-builders/docker'
  id: gpdb7-ubuntu18.04-test-pxf-image
  args:
    - 'build'
    - '--build-arg=BASE_IMAGE=${_BASE_IMAGE_REPOSITORY}/gpdb7-ubuntu18.04-test:latest'
    - '--build-arg=GO_VERSION=${_GO_VERSION}'
    - '--build-arg=GINKGO_VERSION=${_GINKGO_VERSION}'
    - '--tag=gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb7-ubuntu18.04-test-pxf:$COMMIT_SHA'
    - '--cache-from'
    - 'gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb7-ubuntu18.04-test-pxf:latest'
    - '-f'
    - 'concourse/docker/pxf-dev-base/gpdb7/ubuntu18.04/Dockerfile'
    - '/workspace/build/'
  waitFor:
    - gpdb7-ubuntu18.04-test-pxf-image-cache

substitutions:
  _GO_VERSION: 1.17.6 # default values
  _GINKGO_VERSION: 1.16.5 # default values

# Push images to Cloud Build to Container Registry
images:
- 'gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb5-centos7-test-pxf:$COMMIT_SHA'
- 'gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb6-centos7-test-pxf:$COMMIT_SHA'
- 'gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb6-rhel8-test-pxf:$COMMIT_SHA'
- 'gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb6-ubuntu18.04-test-pxf:$COMMIT_SHA'
- 'gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb6-oel7-test-pxf:$COMMIT_SHA'
- 'gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb7-centos7-test-pxf:$COMMIT_SHA'
- 'gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb7-rhel8-test-pxf:$COMMIT_SHA'
- 'gcr.io/$PROJECT_ID/gpdb-pxf-dev/gpdb7-ubuntu18.04-test-pxf:$COMMIT_SHA'
