-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (82 loc) · 2.81 KB
/
cobranzas_dev ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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
sudo rm -rf /opt/ms-cobranzas-dev-app # Eliminar el directorio existente
sudo git clone -b maicol_cobranzas https://${{ secrets.TOKEN_GH_AUDITORIA }}@github.com/alkemyTech/UMSA-DevOps-T3 /opt/ms-cobranzas-dev-app
- 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 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