Estandarizar censo y automatizar despliegue
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
name: Validar censo
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- develop
|
||||
pull_request:
|
||||
branches:
|
||||
- develop
|
||||
|
||||
jobs:
|
||||
validate:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Obtener código
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
|
||||
- name: Configurar Node.js
|
||||
uses: https://github.com/actions/setup-node@v4
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
cache: npm
|
||||
|
||||
- name: Mostrar versiones
|
||||
run: |
|
||||
node --version
|
||||
npm --version
|
||||
|
||||
- name: Instalar dependencias
|
||||
run: npm ci
|
||||
|
||||
- name: Build obligatorio
|
||||
run: npm run build
|
||||
|
||||
deploy-dev:
|
||||
needs: validate
|
||||
if: github.event_name == 'push' && github.ref_name == 'develop'
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Desplegar censo en pruebas
|
||||
uses: CIDWA/infra-actions/deploy-ssh@main
|
||||
with:
|
||||
ssh-private-key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
|
||||
known-hosts: ${{ secrets.DEPLOY_KNOWN_HOSTS }}
|
||||
host: 10.10.10.11
|
||||
user: deploy
|
||||
deploy-script: /var/deploy/scripts/deploy-node-app.sh censo-dev
|
||||
commit-sha: ${{ github.sha }}
|
||||
@@ -1,85 +0,0 @@
|
||||
name: Despliegue Automatizado Universal
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- develop
|
||||
- master
|
||||
|
||||
jobs:
|
||||
get-context:
|
||||
runs-on: host
|
||||
outputs:
|
||||
node_version: ${{ steps.setup.outputs.version }}
|
||||
target_app: ${{ steps.setup.outputs.app }}
|
||||
steps:
|
||||
- name: Resolver Aplicación desde apps.conf
|
||||
id: setup
|
||||
run: |
|
||||
# 1. Obtener el nombre del repositorio actual en Gitea (ej: front-Censo)
|
||||
REPO_NAME="${{ github.event.repository.name }}"
|
||||
|
||||
# 2. Determinar si buscamos un entorno -dev (develop) o producción (master)
|
||||
if [ "${{ github.ref_name }}" = "develop" ]; then
|
||||
SUFFIX="-dev"
|
||||
else
|
||||
SUFFIX=""
|
||||
fi
|
||||
|
||||
echo "Buscando qué sección de apps.conf tiene REPO=$REPO_NAME y termina en '$SUFFIX'..."
|
||||
|
||||
# 3. Buscar en /etc/apps.conf el bloque que contenga REPO=nombre_del_repo
|
||||
TARGET_APP=$(awk -v repo="REPO=$REPO_NAME" -v suf="$SUFFIX" '
|
||||
/^\[/ { gsub(/[\[\]]/, "", $0); current_box=$0; next }
|
||||
$0 == repo {
|
||||
if ((suf == "-dev" && current_box ~ /-dev$/) || (suf == "" && current_box !~ /-dev$/)) {
|
||||
print current_box;
|
||||
exit
|
||||
}
|
||||
}
|
||||
' /etc/apps.conf)
|
||||
|
||||
if [ -z "$TARGET_APP" ]; then
|
||||
echo "ERROR: No se encontró ninguna sección en /etc/apps.conf para el repositorio $REPO_NAME con el sufijo correcto."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 4. Leer la versión de Node del bloque encontrado
|
||||
VERSION=$(awk -v app="$TARGET_APP" '
|
||||
$0=="["app"]" { found=1; next }
|
||||
/^\[/ && found { exit }
|
||||
found && /^NODE=/ { split($0, a, "="); print a[2]; exit }
|
||||
' /etc/apps.conf)
|
||||
|
||||
MAJOR_VERSION=$(echo "$VERSION" | tr -d '[:space:]' | grep -oE '[0-9]+' | head -n1)
|
||||
|
||||
echo "-> ID de Aplicación encontrado: $TARGET_APP"
|
||||
echo "-> Versión Mayor de Node resuelta: $MAJOR_VERSION"
|
||||
|
||||
echo "app=${TARGET_APP}" >> $GITHUB_OUTPUT
|
||||
echo "version=${MAJOR_VERSION}" >> $GITHUB_OUTPUT
|
||||
|
||||
build:
|
||||
needs: get-context
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Configurar Node.js dinámicamente
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ needs.get-context.outputs.node_version }}
|
||||
|
||||
- run: npm ci
|
||||
- run: npm run build
|
||||
|
||||
deploy:
|
||||
needs: [get-context, build]
|
||||
runs-on: host
|
||||
steps:
|
||||
- name: Ejecutar Despliegue en Servidor Físico
|
||||
run: |
|
||||
TARGET_APP="${{ needs.get-context.outputs.target_app }}"
|
||||
BRANCH_NAME="${{ github.ref_name }}"
|
||||
|
||||
sudo -u deploy /home/deploy/scripts/deploy-front.sh "$TARGET_APP" "$BRANCH_NAME"
|
||||
@@ -0,0 +1,25 @@
|
||||
module.exports = {
|
||||
apps: [
|
||||
{
|
||||
name: "censo-dev",
|
||||
cwd: "/var/www/html/front/pruebas/censo",
|
||||
script: "node_modules/next/dist/bin/next",
|
||||
args: "start",
|
||||
|
||||
interpreter: "/home/deploy/.nvm/versions/node/v22.21.1/bin/node",
|
||||
|
||||
env: {
|
||||
NODE_ENV: "production",
|
||||
PORT: 3366,
|
||||
HOSTNAME: "0.0.0.0",
|
||||
},
|
||||
|
||||
autorestart: true,
|
||||
watch: false,
|
||||
min_uptime: "10s",
|
||||
max_restarts: 10,
|
||||
restart_delay: 3000,
|
||||
time: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
Generated
+28
-8
@@ -37,6 +37,10 @@
|
||||
"eslint-config-next": "16.0.2",
|
||||
"sass": "^1.94.0",
|
||||
"typescript": "^5"
|
||||
},
|
||||
"engines": {
|
||||
"node": "22.21.1",
|
||||
"npm": "10.9.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/code-frame": {
|
||||
@@ -1394,6 +1398,7 @@
|
||||
"version": "2.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@parcel/watcher/-/watcher-2.5.1.tgz",
|
||||
"integrity": "sha512-dfUnCxiN9H4ap84DvD2ubjw+3vUNpstxa0TneY/Paat8a3R4uQZDLSvWjmznAY/DoahqTHl9V46HF/Zs3F29pg==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
@@ -1433,6 +1438,7 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1453,6 +1459,7 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1473,6 +1480,7 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1493,6 +1501,7 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1513,6 +1522,7 @@
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1533,6 +1543,7 @@
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1553,6 +1564,7 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1573,6 +1585,7 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1593,6 +1606,7 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1613,6 +1627,7 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1633,6 +1648,7 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1653,6 +1669,7 @@
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1673,6 +1690,7 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -2886,7 +2904,7 @@
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
|
||||
"integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
|
||||
"devOptional": true,
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"fill-range": "^7.1.1"
|
||||
@@ -3411,6 +3429,7 @@
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz",
|
||||
"integrity": "sha512-pGjwhsmsp4kL2RTz08wcOlGN83otlqHeD/Z5T8GXZB+/YcpQ/dgo+lbU8ZsGxV0HIvqqxo9l7mqYwyYMD9bKDg==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"optional": true,
|
||||
"bin": {
|
||||
@@ -4193,7 +4212,7 @@
|
||||
"version": "7.1.1",
|
||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
|
||||
"integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
|
||||
"devOptional": true,
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"to-regex-range": "^5.0.1"
|
||||
@@ -4878,7 +4897,7 @@
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
|
||||
"integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==",
|
||||
"devOptional": true,
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
@@ -4924,7 +4943,7 @@
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz",
|
||||
"integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==",
|
||||
"devOptional": true,
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"is-extglob": "^2.1.1"
|
||||
@@ -4963,7 +4982,7 @@
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
|
||||
"integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
|
||||
"devOptional": true,
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.12.0"
|
||||
@@ -5403,7 +5422,7 @@
|
||||
"version": "4.0.8",
|
||||
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz",
|
||||
"integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==",
|
||||
"devOptional": true,
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"braces": "^3.0.3",
|
||||
@@ -5561,6 +5580,7 @@
|
||||
"version": "7.1.1",
|
||||
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.1.1.tgz",
|
||||
"integrity": "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true
|
||||
},
|
||||
@@ -5836,7 +5856,7 @@
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
|
||||
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
|
||||
"devOptional": true,
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=8.6"
|
||||
@@ -6837,7 +6857,7 @@
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
|
||||
"integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
|
||||
"devOptional": true,
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"is-number": "^7.0.0"
|
||||
|
||||
+6
-1
@@ -38,5 +38,10 @@
|
||||
"eslint-config-next": "16.0.2",
|
||||
"sass": "^1.94.0",
|
||||
"typescript": "^5"
|
||||
}
|
||||
},
|
||||
"engines": {
|
||||
"node": "22.21.1",
|
||||
"npm": "10.9.4"
|
||||
},
|
||||
"packageManager": "npm@10.9.4"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user