Files
GenExam-IA/.gitlab-ci.yml
T
Mireya Cueto Garrido eec534922a 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.
2026-06-02 10:40:13 +02:00

61 lines
1.8 KiB
YAML

stages:
- deploy
variables:
APP_NAME: "generadorexamenesllms"
BACKEND_PORT: "8074"
FRONTEND_PORT: "8075"
deploy_to_sinbad2:
stage: deploy
before_script:
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $SSH_HOST >> ~/.ssh/known_hosts
script:
- echo "Enviando código a Sinbad2..."
- ssh $REMOTE_USER@$SSH_HOST "mkdir -p ~/deploy_$APP_NAME"
- scp -r ./* $REMOTE_USER@$SSH_HOST:~/deploy_$APP_NAME/
- echo "Levantando contenedores con Docker Compose..."
- |
ssh "$REMOTE_USER@$SSH_HOST" <<EOF
set -e
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 [ -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"
- echo "Frontend -> http://sinbad2.ujaen.es:$FRONTEND_PORT"
only:
- branches