# PREREQUISITES:
#   1. you have to provide the following env vars in the cloud build trigger:
#      - $_APP - name of your app. This name is used for all kube resources (deployment, service, etc.)
#      - $_ZONE - zone where your cluster is located. By default 'us-east1-d' is used (New York).
#   2. You have to have a kube cluster with the same name as the google project your are in,
#      OR provide the cluster name explicitly by specifying the $_CLUSTER_NAME env var.
#   3. ConfigMap in the cluster named $_APP with the required private
#      environment variables from './config.json' specified.
#      You have to at least have the following vars specified there:
#      - MONGO_URL
#      - REDIS_URL
#      - STAGE ('dev', 'qa', 'production', etc.)
#   4. Ingress configuration which proxies port 80 to the serviceName $_APP

substitutions:
  _VERSION: '0'

timeout: 2000s
steps:

- name: 'startupjs/deploy:$_VERSION'
  args: [init]
  env:
  # pipe all user defined substitutions
  - _APP=$_APP
  - _ZONE=$_ZONE
  - _PATH=$_PATH
  - _CLUSTER_NAME=$_CLUSTER_NAME
  # pipe all default substitutions
  # https://cloud.google.com/cloud-build/docs/configuring-builds/substitute-variable-values#using_default_substitutions
  - PROJECT_ID=$PROJECT_ID
  - BUILD_ID=$BUILD_ID
  - COMMIT_SHA=$COMMIT_SHA
  - SHORT_SHA=$SHORT_SHA
  - REPO_NAME=$REPO_NAME
  - BRANCH_NAME=$BRANCH_NAME
  - TAG_NAME=$TAG_NAME
  - REVISION_ID=$REVISION_ID

- name: 'startupjs/deploy:$_VERSION'
  args: [build]

- name: 'startupjs/deploy:$_VERSION'
  args: [push]

- name: 'startupjs/deploy:$_VERSION'
  args: [pushLatest]

- name: 'startupjs/deploy:$_VERSION'
  args: [compile]

- name: 'startupjs/deploy:$_VERSION'
  # For new cluster which has embedded helm: [applyVersion] and remove the previous [compile] step completely.
  # For cron pass additional '--cron' at the end
  args: [apply]
