From 6ac7fe1005a206576fa6d5b45ed023d4f8fc51b7 Mon Sep 17 00:00:00 2001 From: Jiri Uhlir Date: Thu, 28 May 2026 14:08:32 +0200 Subject: [PATCH] Clean conflicting containers during core deploy --- scripts/deploy-core-service.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/deploy-core-service.sh b/scripts/deploy-core-service.sh index d1b2ce3..3b0bb9a 100755 --- a/scripts/deploy-core-service.sh +++ b/scripts/deploy-core-service.sh @@ -15,7 +15,6 @@ export DOCKER_CONFIG="/tmp/.docker" mkdir -p "$DOCKER_CONFIG" DB_FILE="/opt/appfactory/data/appfactory/appfactory.db" - SERVICE_DIR="$WORKSPACE_DIR/$SERVICE_NAME" DEPLOY_DIR="$APPFACTORY_DIR/deploy" @@ -144,6 +143,19 @@ run_step() { } >>"$STDOUT_FILE" 2>>"$STDERR_FILE" } +cleanup_conflicting_containers() { + local service="$1" + + docker ps -a --format "{{.ID}} {{.Names}}" \ + | awk -v svc="$service" '$2 == svc || $2 ~ ("_" svc "$") { print $1 }' \ + | while read -r container_id; do + if [ -n "$container_id" ]; then + echo "Removing conflicting container: $container_id" + docker rm -f "$container_id" || true + fi + done +} + set +e run_step "Updating source" bash -c " @@ -165,6 +177,11 @@ if [ "$RESULT" -eq 0 ]; then RESULT=$? fi +if [ "$RESULT" -eq 0 ]; then + run_step "Cleaning conflicting containers" cleanup_conflicting_containers "$SERVICE_NAME" + RESULT=$? +fi + if [ "$RESULT" -eq 0 ]; then run_step "Recreating container" bash -c " cd '$DEPLOY_DIR'