Files
quickcart/.gitea/workflows/build-and-deploy.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

74 lines
3.0 KiB
YAML

name: Build and Deploy QuickCart
on:
push:
branches: [main]
jobs:
build-and-deploy:
runs-on: self-hosted
steps:
- name: Checkout
run: |
rm -rf $GITHUB_WORKSPACE/*
cd $GITHUB_WORKSPACE
git clone $GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git .
git checkout $GITHUB_SHA
- name: Build and import images
run: |
cd $GITHUB_WORKSPACE
for svc in frontend order-service payment-service inventory-service notification-service; do
if [ -d "services/$svc" ]; then
echo "==> Building workshop/$svc:local"
docker build -t "workshop/$svc:local" "services/$svc/"
echo "==> Importing into k3s containerd"
k3s ctr images rm "docker.io/workshop/$svc:local" 2>/dev/null || true
docker save "workshop/$svc:local" | k3s ctr images import -
fi
done
- name: Restart deployments
run: |
for svc in frontend order-service payment-service inventory-service notification-service; do
if k3s kubectl -n workshop get deploy "$svc" >/dev/null 2>&1; then
echo "==> Restarting $svc"
k3s kubectl -n workshop rollout restart "deploy/$svc"
fi
done
for svc in frontend order-service payment-service inventory-service notification-service; do
if k3s kubectl -n workshop get deploy "$svc" >/dev/null 2>&1; then
echo "==> Waiting for $svc..."
k3s kubectl -n workshop rollout status "deploy/$svc" --timeout=120s || true
fi
done
echo "==> All services redeployed."
- name: Send Dynatrace deployment events
if: always()
env:
DT_ENV_URL: ${{ secrets.DT_ENV_URL }}
DT_API_TOKEN: ${{ secrets.DT_API_TOKEN }}
K8_CLUSTER: ${{ secrets.K8_CLUSTER }}
run: |
for svc in frontend order-service payment-service inventory-service notification-service; do
echo "==> Sending Dynatrace deployment event for $svc"
curl -X POST \
-H "Authorization: Api-Token ${DT_API_TOKEN}" \
-H "Content-Type: application/json" \
"${DT_ENV_URL}/api/v2/events/ingest" \
-d @- <<EOF
{
"eventType": "CUSTOM_DEPLOYMENT",
"title": "QuickCart deploy: ${svc}",
"description": "Build and deploy from commit ${{ github.sha }}",
"entitySelector": "type(SERVICE),entityName.startsWith(\"${svc}\"),toRelationships.isClusterOfService(type(KUBERNETES_CLUSTER),entityName(${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
done