Files
quickcart/.github/workflows/workshop-deploy-bad-release.yaml
AIOps Lab d4206b7091
All checks were successful
Build and Deploy QuickCart / build-and-deploy (push) Successful in 51s
Initial workshop snapshot
2026-06-18 13:37:34 +00:00

83 lines
2.8 KiB
YAML

name: Deploy Bad Release
on:
workflow_dispatch:
inputs:
action:
description: "Action to perform"
required: true
type: choice
options:
- deploy-bad-release
- rollback
failure_rate:
description: "Failure rate (0.0-1.0), only used for deploy-bad-release"
required: false
default: "0.7"
repository_dispatch:
types: [auto-remediate]
env:
DT_ENV_URL: ${{ secrets.DT_ENV_URL }}
DT_API_TOKEN: ${{ secrets.DT_API_TOKEN }}
WORKSHOP_IP: ${{ secrets.WORKSHOP_IP }}
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Resolve action
id: resolve
run: |
if [ "${{ github.event_name }}" = "repository_dispatch" ]; then
echo "action=rollback" >> "$GITHUB_OUTPUT"
echo "failure_rate=0" >> "$GITHUB_OUTPUT"
else
echo "action=${{ inputs.action }}" >> "$GITHUB_OUTPUT"
echo "failure_rate=${{ inputs.failure_rate }}" >> "$GITHUB_OUTPUT"
fi
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy bad release via HTTP
if: steps.resolve.outputs.action == 'deploy-bad-release'
run: |
curl -X POST \
-H "Content-Type: application/json" \
-d '{"rate":${{ steps.resolve.outputs.failure_rate }}}' \
"https://workshop.${{ env.WORKSHOP_IP }}.nip.io/admin/failure-rate"
- name: Rollback via HTTP
if: steps.resolve.outputs.action == 'rollback'
run: |
curl -X POST \
-H "Content-Type: application/json" \
-d '{"rate":0}' \
"https://workshop.${{ env.WORKSHOP_IP }}.nip.io/admin/failure-rate"
- name: Send Dynatrace deployment event
if: always()
env:
K8_CLUSTER: ${{ secrets.K8_CLUSTER }}
run: |
curl -X POST \
-H "Authorization: Api-Token ${{ env.DT_API_TOKEN }}" \
-H "Content-Type: application/json" \
"${{ env.DT_ENV_URL }}/api/v2/events/ingest" \
-d @- <<EOF
{
"eventType": "CUSTOM_DEPLOYMENT",
"title": "Payment Service ${{ steps.resolve.outputs.action }}",
"description": "Action: ${{ steps.resolve.outputs.action }}, Failure Rate: ${{ steps.resolve.outputs.failure_rate }}",
"entitySelector": "type(\"SERVICE\"),entityName.startsWith(\"payment-service\"),tag(\"environment:${K8_CLUSTER}\")",
"properties": {
"git.repository": "${{ github.repository }}",
"git.commit": "${{ github.sha }}",
"deployment.url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"environment": "${K8_CLUSTER}"
}
}
EOF