65 lines
1.5 KiB
YAML
65 lines
1.5 KiB
YAML
|
|
name: Despliegue SSH
|
||
|
|
description: Ejecuta un script de despliegue remoto por SSH
|
||
|
|
|
||
|
|
inputs:
|
||
|
|
ssh-private-key:
|
||
|
|
description: Llave privada SSH
|
||
|
|
required: true
|
||
|
|
|
||
|
|
known-hosts:
|
||
|
|
description: Contenido del archivo known_hosts
|
||
|
|
required: true
|
||
|
|
|
||
|
|
host:
|
||
|
|
description: Dirección IP o hostname del servidor
|
||
|
|
required: true
|
||
|
|
|
||
|
|
user:
|
||
|
|
description: Usuario SSH
|
||
|
|
required: false
|
||
|
|
default: deploy
|
||
|
|
|
||
|
|
deploy-script:
|
||
|
|
description: Ruta absoluta del script remoto
|
||
|
|
required: true
|
||
|
|
|
||
|
|
commit-sha:
|
||
|
|
description: Commit validado que será desplegado
|
||
|
|
required: true
|
||
|
|
|
||
|
|
runs:
|
||
|
|
using: composite
|
||
|
|
|
||
|
|
steps:
|
||
|
|
- name: Preparar SSH
|
||
|
|
shell: bash
|
||
|
|
env:
|
||
|
|
SSH_PRIVATE_KEY: ${{ inputs.ssh-private-key }}
|
||
|
|
SSH_KNOWN_HOSTS: ${{ inputs.known-hosts }}
|
||
|
|
run: |
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
install -d -m 700 "$HOME/.ssh"
|
||
|
|
|
||
|
|
printf '%s\n' "$SSH_PRIVATE_KEY" > "$HOME/.ssh/id_ed25519"
|
||
|
|
chmod 600 "$HOME/.ssh/id_ed25519"
|
||
|
|
|
||
|
|
printf '%s\n' "$SSH_KNOWN_HOSTS" > "$HOME/.ssh/known_hosts"
|
||
|
|
chmod 600 "$HOME/.ssh/known_hosts"
|
||
|
|
|
||
|
|
- name: Ejecutar despliegue remoto
|
||
|
|
shell: bash
|
||
|
|
env:
|
||
|
|
DEPLOY_HOST: ${{ inputs.host }}
|
||
|
|
DEPLOY_USER: ${{ inputs.user }}
|
||
|
|
DEPLOY_SCRIPT: ${{ inputs.deploy-script }}
|
||
|
|
COMMIT_SHA: ${{ inputs.commit-sha }}
|
||
|
|
run: |
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
ssh \
|
||
|
|
-i "$HOME/.ssh/id_ed25519" \
|
||
|
|
-o IdentitiesOnly=yes \
|
||
|
|
"${DEPLOY_USER}@${DEPLOY_HOST}" \
|
||
|
|
"${DEPLOY_SCRIPT} '${COMMIT_SHA}'"
|