Fix GitLab deploy port conflicts on Sinbad2.

Parametrize compose published ports and add CI safeguards to detect and release occupied frontend/backend ports before docker compose up, preventing bind errors on 8075.
This commit is contained in:
Mireya Cueto Garrido
2026-06-02 10:37:13 +02:00
parent 7f32380e0a
commit b08fc94016
2 changed files with 19 additions and 4 deletions
+15
View File
@@ -25,6 +25,21 @@ deploy_to_sinbad2:
- echo "Levantando contenedores con Docker Compose..."
- ssh $REMOTE_USER@$SSH_HOST "
cd ~/deploy_$APP_NAME &&
echo 'Comprobando puertos en uso...' &&
docker ps --format '{{.ID}} {{.Ports}}' | grep -E '0.0.0.0:$FRONTEND_PORT->|0.0.0.0:$BACKEND_PORT->' || true &&
CONFLICT_FRONT=\$(docker ps -q --filter publish=$FRONTEND_PORT) &&
if [ ! -z \"\$CONFLICT_FRONT\" ]; then
echo \"Liberando puerto frontend $FRONTEND_PORT (contenedores: \$CONFLICT_FRONT)\" &&
docker stop \$CONFLICT_FRONT &&
docker rm \$CONFLICT_FRONT;
fi &&
CONFLICT_BACK=\$(docker ps -q --filter publish=$BACKEND_PORT) &&
if [ ! -z \"\$CONFLICT_BACK\" ]; then
echo \"Liberando puerto backend $BACKEND_PORT (contenedores: \$CONFLICT_BACK)\" &&
docker stop \$CONFLICT_BACK &&
docker rm \$CONFLICT_BACK;
fi &&
export BACKEND_PORT=$BACKEND_PORT FRONTEND_PORT=$FRONTEND_PORT ALLOWED_ORIGINS=\"http://sinbad2.ujaen.es,http://sinbad2.ujaen.es:$FRONTEND_PORT\" &&
docker compose down --remove-orphans &&
docker compose build --no-cache frontend backend &&
docker compose up -d