Testeo de Key directa en json.
Some checks failed
Build and Deploy / remote-build-and-deploy (push) Failing after 15s
Some checks failed
Build and Deploy / remote-build-and-deploy (push) Failing after 15s
This commit is contained in:
@@ -14,62 +14,48 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# 1. Preparar el cliente SSH (sin cambios)
|
# 1. Preparar el cliente SSH
|
||||||
apt-get update > /dev/null && apt-get install -y openssh-client git > /dev/null
|
apt-get update > /dev/null && apt-get install -y openssh-client git > /dev/null
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.PROD_SERVER_SSH_KEY }}" > ~/.ssh/id_rsa
|
echo "${{ secrets.PROD_SERVER_SSH_KEY }}" > ~/.ssh/id_rsa
|
||||||
chmod 600 ~/.ssh/id_rsa
|
chmod 600 ~/.ssh/id_rsa
|
||||||
ssh-keyscan -H ${{ secrets.PROD_SERVER_HOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan -H ${{ secrets.PROD_SERVER_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
# 2. Conectarse al HOST y ejecutar el script.
|
# 2. Conectarse al HOST y ejecutar todo el proceso allí
|
||||||
# ¡¡LA CLAVE ESTÁ AQUÍ!! << EOF sin comillas, y variables remotas escapadas.
|
ssh ${{ secrets.PROD_SERVER_USER }}@${{ secrets.PROD_SERVER_HOST }} << 'EOF'
|
||||||
ssh ${{ secrets.PROD_SERVER_USER }}@${{ secrets.PROD_SERVER_HOST }} << EOF
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# --- PARTE 1: PREPARACIÓN (EN EL HOST) ---
|
# --- PARTE 1: PREPARACIÓN Y BUILD ---
|
||||||
echo "--- (HOST) Preparing temporary workspace ---"
|
echo "--- (HOST) Preparing & Building ---"
|
||||||
|
|
||||||
# Gitea reemplazará estas variables ANTES de enviar el script.
|
|
||||||
TEMP_DIR="/tmp/gitea-build/${{ gitea.run_id }}"
|
TEMP_DIR="/tmp/gitea-build/${{ gitea.run_id }}"
|
||||||
REPO_NAME_RAW="${{ gitea.repository }}"
|
REPO_NAME_RAW="${{ gitea.repository }}"
|
||||||
# El shell remoto ejecutará estos comandos. Escapamos los '$'.
|
|
||||||
REPO_NAME=\$(echo "\$REPO_NAME_RAW" | tr '[:upper:]' '[:lower:]')
|
REPO_NAME=\$(echo "\$REPO_NAME_RAW" | tr '[:upper:]' '[:lower:]')
|
||||||
GITEA_REPO_PATH="/var/lib/docker/volumes/gitea-stack_gitea-data/_data/git/repositories/\${REPO_NAME}.git"
|
GITEA_REPO_PATH="/var/lib/docker/volumes/gitea-stack_gitea-data/_data/git/repositories/\${REPO_NAME}.git"
|
||||||
|
|
||||||
git config --global --add safe.directory "\$GITEA_REPO_PATH"
|
git config --global --add safe.directory "\$GITEA_REPO_PATH"
|
||||||
|
|
||||||
echo "Cloning repository from local path: \$GITEA_REPO_PATH"
|
|
||||||
rm -rf \$TEMP_DIR
|
rm -rf \$TEMP_DIR
|
||||||
git clone \$GITEA_REPO_PATH \$TEMP_DIR
|
git clone \$GITEA_REPO_PATH \$TEMP_DIR
|
||||||
cd \$TEMP_DIR
|
cd \$TEMP_DIR
|
||||||
git checkout "${{ gitea.sha }}"
|
git checkout "${{ gitea.sha }}"
|
||||||
|
|
||||||
# --- PARTE 2: CONSTRUIR IMÁGENES CON KANIKO (EN EL HOST) ---
|
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}-backend:latest --tarPath=/workspace/backend.tar
|
||||||
echo "--- (HOST) Building images... ---"
|
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}-frontend:latest --tarPath=/workspace/frontend.tar
|
||||||
|
|
||||||
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}-backend:latest --tarPath=/workspace/backend.tar
|
|
||||||
|
|
||||||
docker run --rm -v "\$(pwd)":/workspace gcr.io/kaniko-project/executor:v1.9.0 \
|
# --- PARTE 2: DESPLEGAR ---
|
||||||
--context=/workspace --dockerfile=/workspace/Frontend/Dockerfile --no-push \
|
|
||||||
--destination=\${REPO_NAME}-frontend:latest --tarPath=/workspace/frontend.tar
|
|
||||||
|
|
||||||
# --- PARTE 3: DESPLEGAR (EN EL HOST) ---
|
|
||||||
echo "--- (HOST) Loading images and deploying... ---"
|
echo "--- (HOST) Loading images and deploying... ---"
|
||||||
|
|
||||||
docker load < backend.tar
|
docker load < backend.tar
|
||||||
docker load < frontend.tar
|
docker load < frontend.tar
|
||||||
|
|
||||||
cd /opt/gestion-integral
|
cd /opt/gestion-integral
|
||||||
# Gitea reemplaza los secretos aquí. Es seguro.
|
|
||||||
|
# Exportamos el secreto de la BD.
|
||||||
export DB_SA_PASSWORD='${{ secrets.DB_SA_PASSWORD_SECRET }}'
|
export DB_SA_PASSWORD='${{ secrets.DB_SA_PASSWORD_SECRET }}'
|
||||||
export JWT_KEY='${{ secrets.JWT_KEY_SECRET }}'
|
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
|
|
||||||
# --- PARTE 4: LIMPIEZA (EN EL HOST) ---
|
# --- PARTE 3: LIMPIEZA ---
|
||||||
echo "--- (HOST) Cleaning up... ---"
|
echo "--- (HOST) Cleaning up... ---"
|
||||||
# Escapamos la variable para que la evalúe el host remoto
|
|
||||||
rm -rf \$TEMP_DIR
|
rm -rf \$TEMP_DIR
|
||||||
docker image prune -af
|
docker image prune -af
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,8 @@ var jwtSettings = builder.Configuration.GetSection("Jwt");
|
|||||||
|
|
||||||
// Le decimos que busque la clave JWT en la raíz de la configuración (donde están las variables de entorno).
|
// Le decimos que busque la clave JWT en la raíz de la configuración (donde están las variables de entorno).
|
||||||
// Si no la encuentra, como respaldo, busca en la sección "Jwt" del appsettings.
|
// Si no la encuentra, como respaldo, busca en la sección "Jwt" del appsettings.
|
||||||
var jwtKey = builder.Configuration["JWT_KEY"] ?? jwtSettings["Key"] ?? throw new ArgumentNullException("JWT_KEY or Jwt:Key not configured");
|
//var jwtKey = builder.Configuration["JWT_KEY"] ?? jwtSettings["Key"] ?? throw new ArgumentNullException("JWT_KEY or Jwt:Key not configured");
|
||||||
|
var jwtKey = jwtSettings["Key"] ?? throw new ArgumentNullException("Jwt:Key", "JWT Key not configured in appsettings.json");
|
||||||
|
|
||||||
var keyBytes = Encoding.ASCII.GetBytes(jwtKey);
|
var keyBytes = Encoding.ASCII.GetBytes(jwtKey);
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Jwt": {
|
"Jwt": {
|
||||||
"Key": "",
|
"Key": "badb1a38d221c9e23bcf70958840ca7f5a5dc54f2047dadf7ce45b578b5bc3e2",
|
||||||
"Issuer": "GestionIntegralApi",
|
"Issuer": "GestionIntegralApi",
|
||||||
"Audience": "GestionIntegralClient",
|
"Audience": "GestionIntegralClient",
|
||||||
"DurationInHours": 8
|
"DurationInHours": 8
|
||||||
|
|||||||
Reference in New Issue
Block a user