# 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
#
#     http://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:
  - name: "gcr.io/cloud-builders/docker"
    args: ["build", "-t", "${_IMAGE_MAIN}", "./recursive"]
    id: BUILD_MAIN_CONTAINER
    waitFor: ["-"]

  - name: "gcr.io/cloud-builders/docker"
    args: ["build", "-t", "${_IMAGE_OTEL}", "./otelcol"]
    id: BUILD_OTEL_CONTAINER
    waitFor: ["-"]

  - name: "gcr.io/cloud-builders/docker"
    args: ["push", "${_IMAGE_MAIN}"]
    id: PUSH_MAIN_CONTAINER
    waitFor:
      - BUILD_MAIN_CONTAINER

  - name: "gcr.io/cloud-builders/docker"
    args: ["push", "${_IMAGE_OTEL}"]
    id: PUSH_OTEL_CONTAINER
    waitFor:
      - BUILD_OTEL_CONTAINER

  - name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
    entrypoint: gcloud
    args:
      [
        "run",
        "services",
        "replace",
        "multicontainers.yaml",
        "--region",
        "asia-east1",
      ]
    id: DEPLOY_MULTICONTAINER
    waitFor:
      - PUSH_MAIN_CONTAINER
      - PUSH_OTEL_CONTAINER

substitutions:
  _REGISTRY: asia-east1-docker.pkg.dev/${PROJECT_ID}/my-container
  _IMAGE_MAIN: ${_REGISTRY}/recursive:latest
  _IMAGE_OTEL: ${_REGISTRY}/otelsidecar:latest

images:
  - ${_IMAGE_MAIN}
  - ${_IMAGE_OTEL}

options:
  dynamic_substitutions: true
