From 80a20abc4f65f936f7df6ab53a039c8a4fd26560 Mon Sep 17 00:00:00 2001 From: gitea-admin Date: Sat, 25 Jul 2026 13:41:51 +0330 Subject: [PATCH] Update .gitea/workflows/deploy-asp-net-core.yml --- .gitea/workflows/deploy-asp-net-core.yml | 59 +++++++++++++++++++----- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/.gitea/workflows/deploy-asp-net-core.yml b/.gitea/workflows/deploy-asp-net-core.yml index 9661e5b..bf26dad 100644 --- a/.gitea/workflows/deploy-asp-net-core.yml +++ b/.gitea/workflows/deploy-asp-net-core.yml @@ -7,13 +7,14 @@ on: required: true type: string - container_name: + service_name: required: true type: string - port: - required: true + timeout: + required: false type: string + default: '120' secrets: SSH_HOST: @@ -37,15 +38,51 @@ jobs: host: ${{ secrets.SSH_HOST }} username: ${{ secrets.SSH_USER }} key: ${{ secrets.SSH_PRIVATE_KEY }} + command_timeout: ${{ inputs.timeout }}m script: | - docker pull ${{ inputs.image_ref }} + echo "🚀 Updating service ${{ inputs.service_name }} with image ${{ inputs.image_ref }}..." - docker stop ${{ inputs.container_name }} || true - docker rm ${{ inputs.container_name }} || true + docker service update \ + --image ${{ inputs.image_ref }} \ + --with-registry-auth \ + ${{ inputs.service_name }} - docker run -d \ - --name ${{ inputs.container_name }} \ - --restart unless-stopped \ - -p ${{ inputs.port }} \ - ${{ inputs.image_ref }} \ No newline at end of file + 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 + exit 1 + fi + + echo "🎉 Deployment successful!" \ No newline at end of file