From 81f1e42da33e35b6f9a4606f28ac0f3029d760a5 Mon Sep 17 00:00:00 2001 From: gitea-admin Date: Fri, 23 Oct 2026 02:18:52 +0330 Subject: [PATCH] Update .gitea/workflows/deploy-asp-net-core.yml --- .gitea/workflows/deploy-asp-net-core.yml | 78 ++++++++++++------------ 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/.gitea/workflows/deploy-asp-net-core.yml b/.gitea/workflows/deploy-asp-net-core.yml index 055307a..d168b15 100644 --- a/.gitea/workflows/deploy-asp-net-core.yml +++ b/.gitea/workflows/deploy-asp-net-core.yml @@ -11,6 +11,11 @@ on: required: true type: string + port: + required: false + type: string + default: '' + timeout: required: false type: string @@ -41,48 +46,43 @@ jobs: command_timeout: ${{ inputs.timeout }}m script: | - echo "🚀 Updating service ${{ inputs.service_name }} with image ${{ inputs.image_ref }}..." + set -u + SERVICE="${{ inputs.service_name }}" + IMAGE="${{ inputs.image_ref }}" - docker service update \ - --force \ - --image ${{ inputs.image_ref }} \ - ${{ inputs.service_name }} + echo "🚀 Updating service $SERVICE with image $IMAGE..." - echo "⏳ Waiting for service to converge..." - timeout ${{ inputs.timeout }} docker service ls --filter "name=${{ inputs.service_name }}" > /dev/null - - # Wait for rollout to complete - ELAPSED=0 - INTERVAL=5 - while true; do - REPLICAS=$(docker service ls --filter "name=${{ inputs.service_name }}" --format "{{.Replicas}}") - RUNNING=$(echo "$REPLICAS" | cut -d'/' -f1) - DESIRED=$(echo "$REPLICAS" | cut -d'/' -f2) - - echo " Replicas: $REPLICAS" - - if [ "$RUNNING" = "$DESIRED" ] && [ "$DESIRED" != "0" ]; then - echo "✅ Service ${{ inputs.service_name }} is running ($REPLICAS)" - break - fi - - ELAPSED=$((ELAPSED + INTERVAL)) - if [ "$ELAPSED" -ge "${{ inputs.timeout }}" ]; then - echo "❌ Timeout: service did not converge in ${{ inputs.timeout }}s" - echo "--- Service status ---" - docker service ps ${{ inputs.service_name }} --no-trunc - exit 1 - fi - - sleep $INTERVAL - done - - # Final check: make sure no tasks are in failed state - FAILED=$(docker service ps ${{ inputs.service_name }} --filter "desired-state=shutdown" --format "{{.CurrentState}}" | grep -c "Failed" || true) - if [ "$FAILED" -gt "0" ]; then - echo "❌ Service has $FAILED failed task(s):" - docker service ps ${{ inputs.service_name }} --no-trunc + # Blocks until converged; auto-rolls back if the new tasks fail + if ! timeout "${{ inputs.timeout }}" docker service update \ + --force \ + --with-registry-auth \ + --update-failure-action rollback \ + --update-monitor 15s \ + --image "$IMAGE" \ + "$SERVICE"; then + echo "❌ docker service update failed or timed out after ${{ inputs.timeout }}s" + docker service ps "$SERVICE" --no-trunc + docker service logs --tail 50 "$SERVICE" || true exit 1 fi + # Did THIS rollout succeed? (ignores old failed tasks in history) + STATE=$(docker service inspect "$SERVICE" \ + --format '{{if .UpdateStatus}}{{.UpdateStatus.State}}{{end}}') + echo " Update state: ${STATE:-none}" + + NEW_FAILED=$(docker service ps "$SERVICE" \ + --format '{{.Image}} {{.CurrentState}}' \ + | grep "^$IMAGE" | grep -c "Failed" || true) + + if [ "$STATE" = "rollback_completed" ] || [ "$STATE" = "rollback_started" ] \ + || [ "$STATE" = "paused" ] || [ "$NEW_FAILED" -gt 0 ]; then + echo "❌ Rollout failed (state=$STATE, failed tasks on new image=$NEW_FAILED)" + docker service ps "$SERVICE" --no-trunc + docker service logs --tail 50 "$SERVICE" || true + exit 1 + fi + + REPLICAS=$(docker service ls --filter "name=$SERVICE" --format '{{.Replicas}}') + echo "✅ $SERVICE running ($REPLICAS) on $IMAGE" echo "🎉 Deployment successful!" \ No newline at end of file