From 427c728900238d12ced8bab709f91eb8ca688e48 Mon Sep 17 00:00:00 2001 From: default Date: Fri, 5 Jun 2026 23:55:30 +0000 Subject: [PATCH] fix(deploy): free port 3001 before bringing up the stack MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On hosts with leftover dev processes or stuck containers from prior attempts, docker compose fails with 'address already in use' when trying to bind PostgREST to 127.0.0.1:3001. The previous deploy attempt actually got as far as starting Postgres and MinIO, then PostgREST failed at port binding — leaving the Postgres container running, which would persist for the next attempt and keep re-occupying 3001 indirectly. Add a defensive pre-check: if 3001 is bound, kill the holder (fuser -k) and remove any docker container publishing 3001, then docker compose down --remove-orphans to clear stuck state. Sleep 3 to let the kernel release the port. --- .gitea/workflows/deploy.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 48af1c7..5aee9ad 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -28,6 +28,14 @@ jobs: run: | APP_DIR=/home/tyler/route-commerce mkdir -p $APP_DIR + # Free port 3001 if anything is still on it (stale container, leftover dev process) + if ss -tln 2>/dev/null | grep -q ':3001 '; then + echo "Port 3001 in use, attempting to free it..." + fuser -k 3001/tcp 2>/dev/null || true + docker ps -aq --filter "publish=3001" 2>/dev/null | xargs -r docker rm -f 2>/dev/null || true + docker compose -f $APP_DIR/docker-compose.yml down --remove-orphans 2>/dev/null || true + sleep 3 + fi # Seed config files into APP_DIR if missing (they live in the repo, not in APP_DIR) [ -f $APP_DIR/.env.example ] || cp .env.example $APP_DIR/.env.example [ -f $APP_DIR/docker-compose.yml ] || cp docker-compose.yml $APP_DIR/docker-compose.yml