Update .gitea/workflows/deploy-asp-net-core.yml
This commit is contained in:
@@ -7,13 +7,14 @@ on:
|
|||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
|
|
||||||
container_name:
|
service_name:
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
|
|
||||||
port:
|
timeout:
|
||||||
required: true
|
required: false
|
||||||
type: string
|
type: string
|
||||||
|
default: '120'
|
||||||
|
|
||||||
secrets:
|
secrets:
|
||||||
SSH_HOST:
|
SSH_HOST:
|
||||||
@@ -37,15 +38,51 @@ jobs:
|
|||||||
host: ${{ secrets.SSH_HOST }}
|
host: ${{ secrets.SSH_HOST }}
|
||||||
username: ${{ secrets.SSH_USER }}
|
username: ${{ secrets.SSH_USER }}
|
||||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
|
command_timeout: ${{ inputs.timeout }}m
|
||||||
|
|
||||||
script: |
|
script: |
|
||||||
docker pull ${{ inputs.image_ref }}
|
echo "🚀 Updating service ${{ inputs.service_name }} with image ${{ inputs.image_ref }}..."
|
||||||
|
|
||||||
docker stop ${{ inputs.container_name }} || true
|
docker service update \
|
||||||
docker rm ${{ inputs.container_name }} || true
|
--image ${{ inputs.image_ref }} \
|
||||||
|
--with-registry-auth \
|
||||||
|
${{ inputs.service_name }}
|
||||||
|
|
||||||
docker run -d \
|
echo "⏳ Waiting for service to converge..."
|
||||||
--name ${{ inputs.container_name }} \
|
timeout ${{ inputs.timeout }} docker service ls --filter "name=${{ inputs.service_name }}" > /dev/null
|
||||||
--restart unless-stopped \
|
|
||||||
-p ${{ inputs.port }} \
|
# Wait for rollout to complete
|
||||||
${{ inputs.image_ref }}
|
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!"
|
||||||
Reference in New Issue
Block a user