[verified] fix Stage helper lock under daemon userns remapping
Deploy Canina / deploy (push) Failing after 7m24s
Deploy Canina / deploy (push) Failing after 7m24s
This commit is contained in:
1 parent
2a32f31097
commit
0fa6abc53d
2 files changed
+61
-9
No files matched your search
@@ -46,6 +46,21 @@ cleanup_stage_lock() {
|
||||
wait "$release_pid" 2>/dev/null || :
|
||||
fi
|
||||
if [[ -n $lock_container_id ]]; then
|
||||
if [[ $status != 0 ]]; then
|
||||
# Never emit raw helper/daemon output (image entrypoints may contain
|
||||
# secrets). Classify only a bounded tail before deleting the owned ID.
|
||||
local helper_log diagnostic=unavailable
|
||||
helper_log=$(timeout --foreground --kill-after=2s 10 docker logs --tail 10 "$lock_container_id" 2>&1 | head -c 4096) || :
|
||||
case "$helper_log" in
|
||||
*'Permission denied'*) diagnostic=permission-denied ;;
|
||||
*'No such file or directory'*) diagnostic=missing-host-lock ;;
|
||||
*'Read-only file system'*) diagnostic=read-only-filesystem ;;
|
||||
*'flock: not found'*) diagnostic=flock-unavailable ;;
|
||||
*CANINA_STAGE_DEPLOY_LOCK_ACQUIRED*) diagnostic=previously-acquired ;;
|
||||
?*) diagnostic=unclassified-output ;;
|
||||
esac
|
||||
printf 'Stage lock helper diagnostic: %s\n' "$diagnostic" >&2
|
||||
fi
|
||||
timeout --kill-after=2s 15 docker rm -f "$lock_container_id" >/dev/null || {
|
||||
printf 'Stage lock helper cleanup failed; manual inspection required\n' >&2
|
||||
[[ $status != 0 ]] || status=1
|
||||
@@ -59,10 +74,12 @@ trap 'exit 143' TERM
|
||||
runner_image=$(timeout --foreground --kill-after=2s 10 docker inspect -f '{{.Config.Image}}' gitea_runner)
|
||||
[[ -n $runner_image ]] || exit 1
|
||||
lock_container_id=$(timeout --kill-after=2s 15 docker create --name canina-stage-deploy-lock \
|
||||
--pull=never --network none \
|
||||
--mount type=bind,src=/opt/services/canina,dst=/host-canina \
|
||||
--pull=never --network none --cap-drop=ALL --security-opt=no-new-privileges \
|
||||
--mount type=bind,src=/opt/services/canina,dst=/host-canina,readonly \
|
||||
--entrypoint /bin/sh "$runner_image" -c '
|
||||
exec 9>/host-canina/stage-backend-deploy.lock
|
||||
# Linux flock permits an exclusive lock on a read-only descriptor. Preserve
|
||||
# daemon userns remapping; require the existing host inode, never create it.
|
||||
exec 9</host-canina/stage-backend-deploy.lock
|
||||
flock -n 9 || exit 1
|
||||
printf "CANINA_STAGE_DEPLOY_LOCK_ACQUIRED\n"
|
||||
while :; do sleep 60; done
|
||||
@@ -72,7 +89,7 @@ timeout --foreground --kill-after=2s 10 docker start "$lock_container_id" >/dev/
|
||||
lock_acquired=false
|
||||
for lock_attempt in {1..10}; do
|
||||
[[ $(timeout --foreground --kill-after=2s 10 docker inspect -f '{{.State.Running}}' "$lock_container_id") == true ]] || break
|
||||
if [[ $(timeout --foreground --kill-after=2s 10 docker logs "$lock_container_id") == CANINA_STAGE_DEPLOY_LOCK_ACQUIRED ]]; then
|
||||
if [[ $(timeout --foreground --kill-after=2s 10 docker logs --tail 1 "$lock_container_id" 2>/dev/null) == CANINA_STAGE_DEPLOY_LOCK_ACQUIRED ]]; then
|
||||
lock_acquired=true
|
||||
break
|
||||
fi
|
||||
|
||||
Reference in new issue
Block a user