Update .gitea/workflows/deploy-asp-net-core.yml
This commit is contained in:
@@ -11,6 +11,11 @@ on:
|
|||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
|
|
||||||
|
port:
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: ''
|
||||||
|
|
||||||
timeout:
|
timeout:
|
||||||
required: false
|
required: false
|
||||||
type: string
|
type: string
|
||||||
@@ -41,48 +46,43 @@ jobs:
|
|||||||
command_timeout: ${{ inputs.timeout }}m
|
command_timeout: ${{ inputs.timeout }}m
|
||||||
|
|
||||||
script: |
|
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 \
|
echo "🚀 Updating service $SERVICE with image $IMAGE..."
|
||||||
|
|
||||||
|
# Blocks until converged; auto-rolls back if the new tasks fail
|
||||||
|
if ! timeout "${{ inputs.timeout }}" docker service update \
|
||||||
--force \
|
--force \
|
||||||
--image ${{ inputs.image_ref }} \
|
--with-registry-auth \
|
||||||
${{ inputs.service_name }}
|
--update-failure-action rollback \
|
||||||
|
--update-monitor 15s \
|
||||||
echo "⏳ Waiting for service to converge..."
|
--image "$IMAGE" \
|
||||||
timeout ${{ inputs.timeout }} docker service ls --filter "name=${{ inputs.service_name }}" > /dev/null
|
"$SERVICE"; then
|
||||||
|
echo "❌ docker service update failed or timed out after ${{ inputs.timeout }}s"
|
||||||
# Wait for rollout to complete
|
docker service ps "$SERVICE" --no-trunc
|
||||||
ELAPSED=0
|
docker service logs --tail 50 "$SERVICE" || true
|
||||||
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sleep $INTERVAL
|
# Did THIS rollout succeed? (ignores old failed tasks in history)
|
||||||
done
|
STATE=$(docker service inspect "$SERVICE" \
|
||||||
|
--format '{{if .UpdateStatus}}{{.UpdateStatus.State}}{{end}}')
|
||||||
|
echo " Update state: ${STATE:-none}"
|
||||||
|
|
||||||
# Final check: make sure no tasks are in failed state
|
NEW_FAILED=$(docker service ps "$SERVICE" \
|
||||||
FAILED=$(docker service ps ${{ inputs.service_name }} --filter "desired-state=shutdown" --format "{{.CurrentState}}" | grep -c "Failed" || true)
|
--format '{{.Image}} {{.CurrentState}}' \
|
||||||
if [ "$FAILED" -gt "0" ]; then
|
| grep "^$IMAGE" | grep -c "Failed" || true)
|
||||||
echo "❌ Service has $FAILED failed task(s):"
|
|
||||||
docker service ps ${{ inputs.service_name }} --no-trunc
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
REPLICAS=$(docker service ls --filter "name=$SERVICE" --format '{{.Replicas}}')
|
||||||
|
echo "✅ $SERVICE running ($REPLICAS) on $IMAGE"
|
||||||
echo "🎉 Deployment successful!"
|
echo "🎉 Deployment successful!"
|
||||||
Reference in New Issue
Block a user