---
stages:
- name: Build Stage
  inputs:
  - type: git
    branch: master
  triggers:
  - type: commit
  jobs:
  - name: Build
    type: builder
    artifact_dir: ''
- name: Deploy Stage
  inputs:
  - type: job
    stage: Build Stage
    job: Build
  triggers:
  - type: stage
  jobs:
  - name: Dev Deploy Stage
    type: deployer
    target:
      url: ${CF_TARGET_URL}
      organization: ${CF_ORGANIZATION}
      space: ${CF_SPACE}
      application: ${CF_APP}
    script: |-
      #!/bin/bash
      # Publish catalogAPI
      if ! cf service catalogAPI > /dev/null; then
        cf cups catalogAPI
      fi

      # Push app
      export CF_APP_NAME="$CF_APP"
      cf push "${CF_APP_NAME}"

      # Update catalogAPI
      HOST=http://$(cf app $CF_APP_NAME | grep urls: | awk '{print $2}')
      cf uups catalogAPI -p '{"host":"'$HOST'"}'
- name: Prod Deploy Stage
  inputs:
  - type: job
    stage: Build Stage
    job: Build
  jobs:
  - name: Deploy Stage
    type: deployer
    target:
      url: ${CF_TARGET_URL}
      organization: ${CF_ORGANIZATION}
      space: prod
      application: ${CF_APP}
    script: |-
      #!/bin/bash
      # Publish catalogAPI
      if ! cf service catalogAPI > /dev/null; then
        cf cups catalogAPI
      fi

      # Push app
      export CF_APP_NAME="$CF_APP"
      cf push "${CF_APP_NAME}"

      # Update catalogAPI
      HOST=http://$(cf app $CF_APP_NAME | grep urls: | awk '{print $2}')-prod
      cf uups catalogAPI -p '{"host":"'$HOST'"}'


---
stages:
- name: Build Stage
  inputs:
  - type: git
    branch: master
  triggers:
  - type: commit
  jobs:
  - name: Build
    type: builder
    artifact_dir: ''
- name: Deploy Stage
  inputs:
  - type: job
    stage: Build Stage
    job: Build
  triggers:
  - type: stage
  jobs:
  - name: Deploy Stage
    type: deployer
    target:
      url: ${CF_TARGET_URL}
      organization: ${CF_ORGANIZATION}
      space: ${CF_SPACE}
      application: ${CF_APP}
    script: |-
      #!/bin/bash
      # Publish catalogAPI
      if ! cf service catalogAPI > /dev/null; then
        cf cups catalogAPI
      fi

      # Push app
      export CF_APP_NAME="$CF_APP"
      cf push "${CF_APP_NAME}"

      # Update catalogAPI
      HOST=http://$(cf app $CF_APP_NAME | grep urls: | awk '{print $2}')
      cf uups catalogAPI -p '{"host":"'$HOST'"}'

Revert "testing the addition of a prod stage"
Revert "testing the addition of a prod stage"

This reverts commit 4af3dc8633fa878e51a9d737346a83841a6fe30e.
