Clean conflicting containers during core deploy

This commit is contained in:
2026-05-28 14:08:32 +02:00
parent 6fab554657
commit 6ac7fe1005
+18 -1
View File
@@ -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'