diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index f32ff2f..4b11a68 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -13,6 +13,7 @@ jobs: - name: Run Entire CI/CD Process on Host via SSH run: | set -e + # 1. Preparar el cliente SSH apt-get update > /dev/null && apt-get install -y openssh-client git > /dev/null mkdir -p ~/.ssh @@ -21,37 +22,35 @@ jobs: ssh-keyscan -H ${{ secrets.PROD_SERVER_HOST }} >> ~/.ssh/known_hosts # 2. Conectarse al HOST y ejecutar todo el proceso allí - # ¡¡CAMBIO CLAVE!! Usamos << EOF para que las variables de Gitea se expandan - ssh ${{ secrets.PROD_SERVER_USER }}@${{ secrets.PROD_SERVER_HOST }} << EOF + ssh ${{ secrets.PROD_SERVER_USER }}@${{ secrets.PROD_SERVER_HOST }} << 'EOF' set -e # --- PARTE 1: PREPARACIÓN (EN EL HOST) --- echo "--- (HOST) Preparing temporary workspace ---" - # Usamos las variables que el runner de Gitea ya ha puesto en el entorno - REPO_NAME_LOWER=\$(echo "\$GITEA_REPOSITORY" | tr '[:upper:]' '[:lower:]') - TEMP_DIR="/tmp/gitea-build/\$GITEA_RUN_ID" - GITEA_REPO_PATH="/var/lib/docker/volumes/gitea-stack_gitea-data/_data/git/repositories/\${REPO_NAME_LOWER}.git" + # Usamos las variables que el runner sí pasa a la sesión remota + TEMP_DIR="/tmp/gitea-build/${GITEA_RUN_ID}" + REPO_NAME=$(echo "$GITEA_REPOSITORY" | tr '[:upper:]' '[:lower:]') + GITEA_REPO_PATH="/var/lib/docker/volumes/gitea-stack_gitea-data/_data/git/repositories/${REPO_NAME}.git" - echo "Adding git repository to safe directories..." - git config --global --add safe.directory "\$GITEA_REPO_PATH" - - echo "Cloning repository from local path: \$GITEA_REPO_PATH" - rm -rf \$TEMP_DIR - git clone "\$GITEA_REPO_PATH" \$TEMP_DIR - cd \$TEMP_DIR - git checkout "\$GITEA_SHA" + git config --global --add safe.directory "$GITEA_REPO_PATH" + + echo "Cloning repository from local path: $GITEA_REPO_PATH" + rm -rf $TEMP_DIR + git clone $GITEA_REPO_PATH $TEMP_DIR + cd $TEMP_DIR + git checkout "$GITEA_SHA" # --- PARTE 2: CONSTRUIR IMÁGENES CON KANIKO (EN EL HOST) --- echo "--- (HOST) Building images... ---" - docker run --rm -v "\$(pwd)":/workspace gcr.io/kaniko-project/executor:v1.9.0 \ + docker run --rm -v "$(pwd)":/workspace gcr.io/kaniko-project/executor:v1.9.0 \ --context=/workspace --dockerfile=/workspace/Backend/GestionIntegral.Api/Dockerfile --no-push \ - --destination=\${REPO_NAME_LOWER}-backend:latest --tarPath=/workspace/backend.tar + --destination=${REPO_NAME}-backend:latest --tarPath=/workspace/backend.tar - docker run --rm -v "\$(pwd)":/workspace gcr.io/kaniko-project/executor:v1.9.0 \ + docker run --rm -v "$(pwd)":/workspace gcr.io/kaniko-project/executor:v1.9.0 \ --context=/workspace --dockerfile=/workspace/Frontend/Dockerfile --no-push \ - --destination=\${REPO_NAME_LOWER}-frontend:latest --tarPath=/workspace/frontend.tar + --destination=${REPO_NAME}-frontend:latest --tarPath=/workspace/frontend.tar # --- PARTE 3: DESPLEGAR (EN EL HOST) --- echo "--- (HOST) Loading images and deploying... ---" @@ -60,18 +59,26 @@ jobs: docker load < frontend.tar cd /opt/gestion-integral - # Creamos el archivo .env con los secretos - echo "Creating .env file..." - echo "DB_SA_PASSWORD=${{ secrets.DB_SA_PASSWORD_SECRET }}" > .env - echo "JWT_KEY=${{ secrets.JWT_KEY_SECRET }}" >> .env - + + # --- ¡¡LA CORRECCIÓN DEFINITIVA ESTÁ AQUÍ!! --- + # 1. Creamos un archivo .env al vuelo con los secretos. + echo "Creating .env file with secrets..." + cat > .env <