steps:
  # Build
  - name: 'gcr.io/cloud-builders/docker'
    args: [ 'build', '--build-arg', 'COMPOSER_FLAGS=--dev', '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA', '.' ]
    id: Build-container

    #  - name: 'gcr.io/cloud-builders/docker'
    #  args: [ 'push', 'gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA' ]
    #waitFor: [ 'Build-container' ]
    #id: Pubish-container

  # Test
  #- name: 'gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA'
  #  entrypoint: 'bash'
  #  args: ['-c','composer install --dev;  /workspace/vendor/bin/phpunit' ]
  #  env:
  #    - 'APP_ENV=test'
  #   waitFor: [ 'Pubish-container' ]
  #  id: Run-test
  # Prepare App.yaml
  - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
    entrypoint: 'bash'
    args: [
      '-c','sed -i "s|_GTC_DB_PANEL_HOST|${_GTC_DB_PANEL_HOST}|g" app.yaml && sed -i "s|_GTC_DB_PANEL_NAME|${_GTC_DB_PANEL_NAME}|g" app.yaml && sed -i "s|_GTC_DB_PANEL_USER|${_GTC_DB_PANEL_USER}|g" app.yaml && sed -i "s|_GTC_DB_PANEL_PASS|${_GTC_DB_PANEL_PASS}|g" app.yaml && sed -i "s|_GTC_DB_PANEL_PORT|${_GTC_DB_PANEL_PORT}|g" app.yaml && sed -i "s|_GTC_JWT_SECRET_KEY|${_GTC_JWT_SECRET_KEY}|g" app.yaml && sed -i "s|_GTC_DB_PANEL_SOCKET|${_GTC_DB_PANEL_SOCKET}|g" app.yaml && sed -i "s|_GTC_SMTP_DEFAULT_HOST|${_GTC_SMTP_DEFAULT_HOST}|g" app.yaml && sed -i "s|_GTC_SMTP_DEFAULT_PORT|${_GTC_SMTP_DEFAULT_PORT}|g" app.yaml && sed -i "s|_GTC_SMTP_DEFAULT_USERNAME|${_GTC_SMTP_DEFAULT_USERNAME}|g" app.yaml && sed -i "s|_GTC_SMTP_DEFAULT_PASSWORD|${_GTC_SMTP_DEFAULT_PASSWORD}|g" app.yaml ']
    waitFor: [ 'Build-container' ]
    id: Prepare-appYaml

  # Deploy    
  - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
    entrypoint: 'bash'
    args: [ '-c', 'gcloud config set project ${_TARGET_PROJECT_ID} && gcloud config set app/cloud_build_timeout 1600 && gcloud app deploy' ]
    waitFor: ['Prepare-appYaml']
    id: Deploy-APP
timeout: '3200s'
#test