Deploy: retry "docker compose up -d" instead of guessing at a stale container
The previous fix (kill anything on port 8420 before up) didn't help -- confirmed nothing was actually squatting on the port. The real cause, per the maintainer: "up -d" run manually a few seconds after "down" always succeeds, but scripted straight through (down && pull && up, pull sometimes a no-op if the image is already cached) fails every time. That's "down" returning before the OS/docker-proxy has actually released port 8420 yet, not an orphaned container -- a timing race, not a stuck process. Retrying "up -d" a few times with a short pause rides out that race without needing to guess a fixed sleep long enough to always cover it.
This commit is contained in:
@@ -68,10 +68,25 @@ jobs:
|
|||||||
chmod 600 ~/.ssh/deploy_key
|
chmod 600 ~/.ssh/deploy_key
|
||||||
ssh-keyscan -p "$DEPLOY_PORT" "$DEPLOY_HOST" >> ~/.ssh/known_hosts 2>/dev/null
|
ssh-keyscan -p "$DEPLOY_PORT" "$DEPLOY_HOST" >> ~/.ssh/known_hosts 2>/dev/null
|
||||||
ssh -i ~/.ssh/deploy_key -p "$DEPLOY_PORT" -o StrictHostKeyChecking=yes \
|
ssh -i ~/.ssh/deploy_key -p "$DEPLOY_PORT" -o StrictHostKeyChecking=yes \
|
||||||
espressoframe_deployer@"$DEPLOY_HOST" \
|
espressoframe_deployer@"$DEPLOY_HOST" bash -s <<'REMOTE'
|
||||||
'cd ~/espresso-frame && \
|
set -e
|
||||||
docker compose down --remove-orphans && \
|
cd ~/espresso-frame
|
||||||
docker ps -q --filter publish=8420 | xargs -r docker stop && \
|
docker compose down --remove-orphans
|
||||||
docker ps -aq --filter publish=8420 | xargs -r docker rm && \
|
docker compose pull
|
||||||
docker compose pull && \
|
# "down" returning doesn't guarantee the OS/docker-proxy has
|
||||||
docker compose up -d'
|
# actually released port 8420 yet -- an immediate "up -d" right
|
||||||
|
# after (especially with "pull" a no-op because the image was
|
||||||
|
# already cached) can lose that race and fail with "port is
|
||||||
|
# already allocated", even though the exact same "up -d" run a
|
||||||
|
# few seconds later succeeds every time. Retry instead of
|
||||||
|
# guessing at a fixed sleep long enough to always cover it.
|
||||||
|
for i in $(seq 1 10); do
|
||||||
|
if docker compose up -d; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
echo "docker compose up -d failed (attempt $i/10) -- retrying in 3s"
|
||||||
|
sleep 3
|
||||||
|
done
|
||||||
|
echo "docker compose up -d did not succeed after 10 attempts"
|
||||||
|
exit 1
|
||||||
|
REMOTE
|
||||||
|
|||||||
Reference in New Issue
Block a user