# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

steps:
  - id: configure-docker-authentication
    name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
    entrypoint: 'gcloud'
    args: ['auth', 'configure-docker', '-q']

  - id: build-event-generator-docker-image
    dir: app
    waitFor: ['configure-docker-authentication']
    name: 'gcr.io/cloud-builders/docker'
    args: ['build', '-f', 'DockerfileEventGenerator', '-t', 'gcr.io/${PROJECT_ID}/${_EVENT_GENERATOR_IMAGE_REPO_NAME}:${_IMAGE_TAG}', '../']

  - id: push-event-generator-docker-image
    dir: app
    waitFor: ['build-event-generator-docker-image']
    name: 'gcr.io/cloud-builders/docker'
    args: ['push', 'gcr.io/${PROJECT_ID}/${_EVENT_GENERATOR_IMAGE_REPO_NAME}:${_IMAGE_TAG}']

  - id: build-metrics-ack-docker-image
    dir: app
    waitFor: ['configure-docker-authentication']
    name: 'gcr.io/cloud-builders/docker'
    args: ['build', '-f', 'DockerfileMetricsAck', '-t', 'gcr.io/${PROJECT_ID}/${_METRICS_ACK_IMAGE_REPO_NAME}:${_IMAGE_TAG}', '../']

  - id: push-metrics-ack-docker-image
    dir: app
    waitFor: ['build-metrics-ack-docker-image']
    name: 'gcr.io/cloud-builders/docker'
    args: ['push', 'gcr.io/${PROJECT_ID}/${_METRICS_ACK_IMAGE_REPO_NAME}:${_IMAGE_TAG}']

  - id: build-metrics-nack-docker-image
    dir: app
    waitFor: ['configure-docker-authentication']
    name: 'gcr.io/cloud-builders/docker'
    args: ['build', '-f', 'DockerfileMetricsNack', '-t', 'gcr.io/${PROJECT_ID}/${_METRICS_NACK_IMAGE_REPO_NAME}:${_IMAGE_TAG}', '../']

  - id: push-metrics-nack-docker-image
    dir: app
    waitFor: ['build-metrics-nack-docker-image']
    name: 'gcr.io/cloud-builders/docker'
    args: ['push', 'gcr.io/${PROJECT_ID}/${_METRICS_NACK_IMAGE_REPO_NAME}:${_IMAGE_TAG}']

  - id: build-metrics-complete-docker-image
    dir: app
    waitFor: ['configure-docker-authentication']
    name: 'gcr.io/cloud-builders/docker'
    args: ['build', '-f', 'DockerfileMetricsComplete', '-t', 'gcr.io/${PROJECT_ID}/${_METRICS_COMPLETE_IMAGE_REPO_NAME}:${_IMAGE_TAG}', '../']

  - id: push-metrics-complete-docker-image
    dir: app
    waitFor: ['build-metrics-complete-docker-image']
    name: 'gcr.io/cloud-builders/docker'
    args: ['push', 'gcr.io/${PROJECT_ID}/${_METRICS_COMPLETE_IMAGE_REPO_NAME}:${_IMAGE_TAG}']

substitutions:
  _EVENT_GENERATOR_IMAGE_REPO_NAME: 'jss-psi-golang-event-generator'
  _METRICS_ACK_IMAGE_REPO_NAME: 'jss-psi-golang-metrics-ack'
  _METRICS_NACK_IMAGE_REPO_NAME: 'jss-psi-golang-metrics-nack'
  _METRICS_COMPLETE_IMAGE_REPO_NAME: 'jss-psi-golang-metrics-complete'
  _IMAGE_TAG: 'latest'

options:
  machineType: 'E2_HIGHCPU_8'
  logging: 'CLOUD_LOGGING_ONLY'
