Skip to content

Instantly share code, notes, and snippets.

@nullx5
Last active March 15, 2025 17:58
Show Gist options
  • Save nullx5/838ad8a7311b94c803d2d41a45051839 to your computer and use it in GitHub Desktop.
Save nullx5/838ad8a7311b94c803d2d41a45051839 to your computer and use it in GitHub Desktop.

Github actions deploy a server ubuntu cuando se haga push a rama main

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"
@nullx5
Copy link
Author

nullx5 commented Feb 22, 2025

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.

image

@nullx5
Copy link
Author

nullx5 commented Mar 15, 2025

image

@nullx5
Copy link
Author

nullx5 commented Mar 15, 2025

image

@nullx5
Copy link
Author

nullx5 commented Mar 15, 2025

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment