repositorio en GitHub Settings > Secrets and variables > Actions.
Agrega los siguientes secretos:
SSH_HOST: 192.168.100.1
SSH_USER: root
SSH_KEY: (Contenido de tu clave privada SSH)
name: Deploy to Ubuntu Server
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Deploy code to server
run: |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "cd /ruta/del/proyecto && git pull origin main && systemctl restart gunicorn && systemctl restart nginx"
Se puede usar un script en el servidor o directamente en el workflow. https://www.youtube.com/watch?v=ztgyGnWwMzY
Si el despliegue es sencillo y el repositorio está bien protegido, el workflow actual es aceptable. Pero si buscas mayor seguridad y flexibilidad, es mejor usar un script en el servidor.