# 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: mvn-install
    dir: app
    volumes:
      - name: 'm2'
        path: /root/.m2
    name: 'maven'
    entrypoint: 'mvn'
    args: ['install']

  - id: build-and-push-event-generator-docker-image
    dir: app/eventgenerator
    volumes:
      - name: 'm2'
        path: /root/.m2
    name: 'maven'
    entrypoint: 'mvn'
    env: ['PUB_IMAGE_NAME=gcr.io/${PROJECT_ID}/${_EVENT_GENERATOR_IMAGE_REPO_NAME}:${_IMAGE_TAG}']
    args: ['compile', 'com.google.cloud.tools:jib-maven-plugin:3.3.1:build']

  - id: build-and-push-metrics-ack-docker-image
    dir: app/metrics
    volumes:
      - name: 'm2'
        path: /root/.m2
    name: 'maven'
    entrypoint: 'mvn'
    env: ['SUB_IMAGE_NAME=gcr.io/${PROJECT_ID}/${_METRICS_ACK_IMAGE_REPO_NAME}:${_IMAGE_TAG}']
    args: ['compile', 'com.google.cloud.tools:jib-maven-plugin:3.3.1:build', '-P', 'ack']

  - id: build-and-push-metrics-nack-docker-image
    dir: app/metrics
    volumes:
      - name: 'm2'
        path: /root/.m2
    name: 'maven'
    entrypoint: 'mvn'
    env: ['SUB_IMAGE_NAME=gcr.io/${PROJECT_ID}/${_METRICS_NACK_IMAGE_REPO_NAME}:${_IMAGE_TAG}']
    args: ['compile', 'com.google.cloud.tools:jib-maven-plugin:3.3.1:build', '-P', 'nack']

  - id: build-and-push-metrics-complete-docker-image
    dir: app/metrics
    volumes:
      - name: 'm2'
        path: /root/.m2
    name: 'maven'
    entrypoint: 'mvn'
    env: ['SUB_IMAGE_NAME=gcr.io/${PROJECT_ID}/${_METRICS_COMPLETE_IMAGE_REPO_NAME}:${_IMAGE_TAG}']
    args: ['compile', 'com.google.cloud.tools:jib-maven-plugin:3.3.1:build', '-P', 'complete']

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

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