Skip to content

Commit faf21f4

Browse files
authored
Fix #421: Improve prod-deploy error handling so exact error is printed in case of rollback
1 parent 46666f1 commit faf21f4

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 1.1.1 under development
44

5+
- New #421: Improve `prod-deploy` error handling so exact error is printed in case of rollback (@samdark)
56
- Enh #424: Refactor `Makefile` default command help logic (@samdark)
67
- Enh #435: Set locale `C.UTF-8` in `Dockerfile` (@vjik)
78

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,19 @@ endif
121121

122122
ifeq ($(PRIMARY_GOAL),prod-deploy)
123123
prod-deploy: ## PROD | Deploy to production
124-
docker -H ${PROD_SSH} stack deploy --prune --detach=false --with-registry-auth -c docker/compose.yml -c docker/prod/compose.yml ${STACK_NAME}
124+
set -euo pipefail \
125+
docker -H ${PROD_SSH} stack deploy --prune --detach=false --with-registry-auth -c docker/compose.yml -c docker/prod/compose.yml ${STACK_NAME} 2>&1 | tee deploy.log \
126+
if grep -qiE 'rollback:|update rolled back' deploy.log then \
127+
FAILED_TASK_ID="$(grep -oiE 'task[[:space:]]+[a-z0-9]+' deploy.log | head -n 1 | awk '{print $2}')" \
128+
if [ -n "${FAILED_TASK_ID}" ]; then \
129+
echo "Docker Swarm update rolled back; failing job. Failed task ID: ${FAILED_TASK_ID}" \
130+
echo "--- docker service logs (${FAILED_TASK_ID}) ---" \
131+
docker -H ${PROD_SSH} service logs --timestamps --tail 500 "${FAILED_TASK_ID}" || true \
132+
else \
133+
echo 'Docker Swarm update rolled back; failing job. Failed task ID: not found in deploy output.' \
134+
fi \
135+
exit 1 \
136+
fi
125137
endif
126138

127139
#

0 commit comments

Comments
 (0)