Skip to content

cobranzas_dev ci.yml #34

cobranzas_dev ci.yml

cobranzas_dev ci.yml #34

on:
push:
branches:
- maicol_cobranzas
jobs:
deploy:
runs-on: ubuntu-latest
env:
EC2_HOST: ${{ secrets.IP_COBRANZAS_DEV }}
EC2_USERNAME: ${{ secrets.USERS_COBRANZAS }}
EC2_SSH_KEY: ${{ secrets.PEM_ORG_COBRANZAS_DEV }}
GH_TOKEN: ${{ secrets.TOKEN_COBRANZAS }}
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Check if directory exists
uses: appleboy/ssh-action@master
with:
host: ${{ env.EC2_HOST }}
username: ${{ env.EC2_USERNAME }}
key: ${{ env.EC2_SSH_KEY }}
script: |
if [ -d "/opt/ms-cobranzas-dev-app" ]; then
echo "Directory already exists."
else
echo "Directory does not exist. Creating directory..."
sudo mkdir -p /opt/ms-cobranzas-dev-app
fi
- name: Install Git
uses: appleboy/ssh-action@master
with:
host: ${{ env.EC2_HOST }}
username: ${{ env.EC2_USERNAME }}
key: ${{ env.EC2_SSH_KEY }}
script: |
sudo yum update -y && sudo yum install -y git
- name: Clone repository
uses: appleboy/ssh-action@master
with:
host: ${{ env.EC2_HOST }}
username: ${{ env.EC2_USERNAME }}
key: ${{ env.EC2_SSH_KEY }}
script: |
cd /opt/ms-cobranzas-dev-app
sudo git clone -b maicol_cobranzas https://${{ secrets.TOKEN_GH_AUDITORIA }}@github.com/alkemyTech/UMSA-DevOps-T3 .
- name: Install npm if not installed
uses: appleboy/ssh-action@master
with:
host: ${{ env.EC2_HOST }}
username: ${{ env.EC2_USERNAME }}
key: ${{ env.EC2_SSH_KEY }}
script: |
if ! command -v npm &> /dev/null; then
sudo yum install -y npm
fi
- name: Install npm packages
uses: appleboy/ssh-action@master
with:
host: ${{ env.EC2_HOST }}
username: ${{ env.EC2_USERNAME }}
key: ${{ env.EC2_SSH_KEY }}
script: |
cd /opt/ms-cobranzas-dev-app
sudo npm install express -g pm2
- name: Restart or Start app.js
uses: appleboy/ssh-action@master
with:
host: ${{ env.EC2_HOST }}
username: ${{ env.EC2_USERNAME }}
key: ${{ env.EC2_SSH_KEY }}
script: |
cd /opt/ms-cobranzas-dev-app
sudo pm2 restart app.js || sudo pm2 start -f app.js
- name: Check service status
uses: appleboy/ssh-action@master
with:
host: ${{ env.EC2_HOST }}
username: ${{ env.EC2_USERNAME }}
key: ${{ env.EC2_SSH_KEY }}
script: |
sudo pm2 status