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
+4 -4
View File
@@ -6,13 +6,13 @@ services:
- ./backend/.env
environment:
DATABASE_URL: postgresql+psycopg://genexamenes:genexamenes@db:5432/genexamenes
# Sobrescribe backend/.env con el puerto actual del frontend.
ALLOWED_ORIGINS: http://sinbad2.ujaen.es,http://sinbad2.ujaen.es:8075
# Sobrescribe backend/.env con el origen público del frontend en despliegue.
ALLOWED_ORIGINS: ${ALLOWED_ORIGINS:-http://sinbad2.ujaen.es,http://sinbad2.ujaen.es:8075}
LLM_BASE_URL:
LLM_MODEL: qwen3.5:35b
LLM_TIMEOUT_SECONDS: "180"
ports:
- "8074:8074"
- "${BACKEND_PORT:-8074}:8074"
depends_on:
db:
condition: service_healthy
@@ -27,7 +27,7 @@ services:
VITE_API_URL: ${VITE_API_URL:-http://sinbad2.ujaen.es:8074}
VITE_GOOGLE_CLIENT_ID: ${VITE_GOOGLE_CLIENT_ID:-}
ports:
- "8075:80"
- "${FRONTEND_PORT:-8075}:80"
depends_on:
- backend
restart: unless-stopped