Update .gitea/workflows/deploy-asp-net-core.yml

This commit is contained in:
2026-07-25 13:41:51 +03:30
parent c19af8a8b7
commit 80a20abc4f
+48 -11
View File
@@ -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 }}
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!"