# Copyright 2025 Google LLC. All Rights Reserved.
#
# 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.

# gcloud builds submit --config deployment/cd/dev.yaml --substitutions _PROJECT_ID=<project_id>,_ARTIFACT_REGISTRY_REPO_NAME=<af_name> .

steps:
  # Build and Push
  - name: 'gcr.io/cloud-builders/docker'
    args:
      - 'build'
      - '-t'
      - '$_REGION-docker.pkg.dev/$_PROJECT_ID/$_ARTIFACT_REGISTRY_REPO_NAME/$_CONTAINER_NAME:latest'
      - '.'

  - name: 'gcr.io/cloud-builders/docker'
    args:
      - 'push'
      - '$_REGION-docker.pkg.dev/$_PROJECT_ID/$_ARTIFACT_REGISTRY_REPO_NAME/$_CONTAINER_NAME:latest'

  # Deploy
  - name: 'gcr.io/cloud-builders/gcloud'
    entrypoint: gcloud
    args:
      - 'run'
      - 'deploy'
      - '${_SERVICE_NAME}'
      - '--image'
      - '$_REGION-docker.pkg.dev/$PROJECT_ID/$_ARTIFACT_REGISTRY_REPO_NAME/$_CONTAINER_NAME:latest'
      - '--allow-unauthenticated'
      - '--platform'
      - 'managed'
      - '--region'
      - '${_REGION}'
      - "--project"
      - "${_PROJECT_ID}"
      - "--min-instances"
      - "1"
      - "--no-cpu-throttling"
      - "--cpu"
      - "2"
      - "--memory"
      - "4Gi"
      - "--concurrency"
      - "40"
      - '--env-vars-file'
      - 'deployment/config/dev.yaml'

options:
  substitution_option: 'ALLOW_LOOSE'

substitutions:
  _CONTAINER_NAME: agent_runtime
  _PROJECT_ID: ""
  _ARTIFACT_REGISTRY_REPO_NAME: ""
  _SERVICE_NAME: agent-runtime-service
  _REGION: us-central1
