Job-Specification

---
key: deploy-to-zhdk-leihs-test
name: Deploy to zhdk-leihs-test.ruby.zhdk.ch
context:
  tasks:
    deploy:
      key: deploy
      name: deploy
      traits:
        g2016: true
      scripts:
        deploy:
          body: |
            set -eux
            cd deploy
            export ANSIBLE_HOST_KEY_CHECKING=False
            ansible-playbook deploy_play.yml \
              --ssh-common-args '-i ~/.ssh/zhdk_ci_executor_rsa' \
              -i ../zhdk-inventory/${DEPLOY_TARGET_INVENTORY}
          timeout: 20 minutes
          start_when:
            data from prod was synced:
              states:
              - passed
              script_key: restore-dump
        fetch-dump:
          body: |
            set -euxo
            cd deploy
            export ANSIBLE_HOST_KEY_CHECKING=False
            ansible-playbook fetch-latest-dump_play.yml \
              --ssh-common-args '-i ~/.ssh/zhdk_ci_executor_rsa' \
              -i ../zhdk-inventory/prod-hosts
        restore-dump:
          body: |
            set -eux
            cd deploy
            export ANSIBLE_HOST_KEY_CHECKING=False
            ansible-playbook db-restore-only_play.yml \
              --ssh-common-args '-i ~/.ssh/zhdk_ci_executor_rsa' \
              -i ../zhdk-inventory/${DEPLOY_TARGET_INVENTORY}
          timeout: 10 Minutes
          start_when:
            fetch passed:
              states:
              - passed
              script_key: fetch-dump
        attach-server-log:
          body: |
            set -eux
            cd deploy
            export ANSIBLE_HOST_KEY_CHECKING=False
            ansible-playbook get-server-log_play.yml \
              --ssh-common-args '-i ~/.ssh/zhdk_ci_executor_rsa' \
              -i ../zhdk-inventory/${DEPLOY_TARGET_INVENTORY}

            echo ''; echo ''; echo '';
            echo '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
            echo 'Last 100 lines of server log can be found in Trial Attachments!'
            echo '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
          start_when:
            after deploy:
              states:
              - passed
              - aborted
              - defective
              - failed
              script_key: deploy
          ignore_abort: true
          ignore_state: true
      git_options:
        submodules:
          include_match: "^.*$"
      trial_attachments:
        server_log:
          content_type: text/plain
          include_match: ".*server_log.*"
  task_defaults:
    traits: {}
    environment_variables:
      DEPLOY_TARGET_INVENTORY: test-hosts
    exclusive_global_resources:
      zhdk-leihs-test.ruby.zhdk.ch: true
priority: 2