Initial workshop snapshot
All checks were successful
Build and Deploy QuickCart / build-and-deploy (push) Successful in 1m2s
All checks were successful
Build and Deploy QuickCart / build-and-deploy (push) Successful in 1m2s
This commit is contained in:
46
.github/workflows/workshop-build-and-push.yaml
vendored
Normal file
46
.github/workflows/workshop-build-and-push.yaml
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
name: Build and Push Images
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- "services/**"
|
||||
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
IMAGE_PREFIX: ${{ github.repository }}
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
service:
|
||||
- frontend
|
||||
- order-service
|
||||
- payment-service
|
||||
- inventory-service
|
||||
- notification-service
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Log in to GHCR
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build and push ${{ matrix.service }}
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: services/${{ matrix.service }}
|
||||
push: true
|
||||
tags: |
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/${{ matrix.service }}:latest
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/${{ matrix.service }}:${{ github.sha }}
|
||||
82
.github/workflows/workshop-deploy-bad-release.yaml
vendored
Normal file
82
.github/workflows/workshop-deploy-bad-release.yaml
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
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
|
||||
108
.github/workflows/workshop-release.yaml
vendored
Normal file
108
.github/workflows/workshop-release.yaml
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
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
|
||||
Reference in New Issue
Block a user