From eec534922a9032a572b7f45e897c72a12cf30981 Mon Sep 17 00:00:00 2001 From: Mireya Cueto Garrido Date: Tue, 2 Jun 2026 10:40:13 +0200 Subject: [PATCH] Fix GitLab CI YAML parsing for remote deploy block. Replace the inline SSH command with a YAML-safe block scalar and heredoc so the pipeline parser accepts the script while keeping the same port-conflict handling logic. --- .gitlab-ci.yml | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1b106c3..484d76a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,27 +23,35 @@ deploy_to_sinbad2: - scp -r ./* $REMOTE_USER@$SSH_HOST:~/deploy_$APP_NAME/ - 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 - " + - | + ssh "$REMOTE_USER@$SSH_HOST" <|0.0.0.0:$BACKEND_PORT->" || true + + CONFLICT_FRONT=\$(docker ps -q --filter publish=$FRONTEND_PORT) + if [ -n "\$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 [ -n "\$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 + export FRONTEND_PORT=$FRONTEND_PORT + export 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 + EOF - echo "Despliegue completado." - echo "Backend -> http://sinbad2.ujaen.es:$BACKEND_PORT"