Skip to content

Deploy test

Deploy test #10

Workflow file for this run

name: Node.js CD
# Controls when the action will run.
on:
push:
branches: [ main ]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14' # O la versión que uses
- name: Install dependencies for frontend
run: |
cd frontend
npm install
- name: Build frontend
run: |
cd frontend
npm run build
- name: Install dependencies for backend
run: |
cd backend
npm install
- name: Deploy using ssh
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.VPS_SSH_HOST }}
username: ${{ secrets.VPS_SSH_USERNAME }}
password: ${{ secrets.VPS_SSH_PASSWORD }}
port: 22
script: |
# Crear directorios en el VPS
ssh ${{ secrets.VPS_SSH_USERNAME }}@${{ secrets.VPS_SSH_HOST }} "mkdir -p /var/www/html/virtual-dojo/frontend /var/www/html/virtual-dojo/backend"
# Copiar el build del frontend al VPS
rsync -avz --delete -e "ssh -o StrictHostKeyChecking=no" ./frontend/dist/ ${{ secrets.VPS_SSH_USERNAME }}@${{ secrets.VPS_SSH_HOST }}:/var/www/html/virtual-dojo/frontend
# Copiar el backend al VPS
rsync -avz --delete -e "ssh -o StrictHostKeyChecking=no" ./backend/ ${{ secrets.VPS_SSH_USERNAME }}@${{ secrets.VPS_SSH_HOST }}:/var/www/html/virtual-dojo/backend
# Conectar al VPS y reiniciar el backend
ssh ${{ secrets.VPS_SSH_USERNAME }}@${{ secrets.VPS_SSH_HOST }} << 'EOF'
cd /var/www/html/virtual-dojo/backend
npm install --only=prod
pm2 restart all || pm2 start server.js --name virtual-dojo
exit
EOF