Files
quickcart/.github/workflows/workshop-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

109 lines
3.8 KiB
YAML

name: Release (GitOps)
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-release]
env:
DT_ENV_URL: ${{ secrets.DT_ENV_URL }}
DT_API_TOKEN: ${{ secrets.DT_API_TOKEN }}
jobs:
release:
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: Resolve version
id: version
run: |
if [ "${{ steps.resolve.outputs.action }}" = "deploy-bad-release" ]; then
echo "version=bad-release-${{ github.run_number }}" >> "$GITHUB_OUTPUT"
else
echo "version=rollback-${{ github.run_number }}" >> "$GITHUB_OUTPUT"
fi
- name: Checkout code
uses: actions/checkout@v4
- name: Install yq
uses: mikefarah/yq@master
- name: Update payment-service manifest
run: |
VERSION="${{ steps.version.outputs.version }}"
FAILURE_RATE="${{ steps.resolve.outputs.failure_rate }}"
# Update pod template labels
yq -i '
.spec.template.metadata.labels."app.kubernetes.io/version" = "'"$VERSION"'"
' k8s/payment-service.yaml
# Update DT_RELEASE_VERSION env var
yq -i '
(.spec.template.spec.containers[0].env[] | select(.name == "DT_RELEASE_VERSION")).value = "'"$VERSION"'"
' k8s/payment-service.yaml
# Update FAILURE_RATE env var
yq -i '
(.spec.template.spec.containers[0].env[] | select(.name == "FAILURE_RATE")).value = "'"$FAILURE_RATE"'"
' k8s/payment-service.yaml
- name: Commit and push
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add k8s/payment-service.yaml
git commit -m "release: payment-service ${{ steps.version.outputs.version }} (failure_rate=${{ steps.resolve.outputs.failure_rate }})"
git push
- 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": "Version: ${{ steps.version.outputs.version }}, Failure Rate: ${{ steps.resolve.outputs.failure_rate }}",
"entitySelector": "type(\"SERVICE\"),entityName.startsWith(\"payment-service\"),tag(\"environment:${K8_CLUSTER}\")",
"properties": {
"dt.release.version": "${{ steps.version.outputs.version }}",
"dt.release.product": "workshop",
"dt.release.stage": "production",
"git.repository": "${{ github.repository }}",
"git.commit": "${{ github.sha }}",
"deployment.url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"environment": "${K8_CLUSTER}"
}
}
EOF