-
Notifications
You must be signed in to change notification settings - Fork 1
176 lines (154 loc) · 5.06 KB
/
FIle.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
name: Deploy App Auditoria
# Trigger.
on:
push:
branches:
- auditoria_qa_am
jobs:
deploy:
runs-on: ubuntu-latest
env:
#Conexion ssh
SSH_PRIVATE_KEY: ${{ secrets.PEM_AUDITORIA_QA }}
REMOTE_USER: ec2-user
REMOTE_HOST: ${{ vars.IP_AUDITORIA_QA }}
GITHUB_TOKEN: ${{ secrets.TOKEN_GH_AM }}
APP_NAME: app.js
#Conexion dockerhub
DOCKERHUB_USERNAME: ${{ vars.DOCKERHUB_USERNAME_AM }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD_AM }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN_AM }}
steps:
# Install packages Nodejs Npm Git
- name: Install Packages
uses: appleboy/ssh-action@master
with:
host: ${{ env.REMOTE_HOST }}
username: ${{ env.REMOTE_USER }}
key: ${{ env.SSH_PRIVATE_KEY }}
script: |
sudo yum update -y
sudo yum install nodejs npm git -y
# Create a Directory
- name: Create a Directory
uses: appleboy/ssh-action@master
with:
host: ${{ env.REMOTE_HOST }}
username: ${{ env.REMOTE_USER }}
key: ${{ env.SSH_PRIVATE_KEY }}
script: |
sudo rm -rf /opt/auditoria || true
cd /opt
sudo mkdir -p auditoria
# Execute git clone.
- name: Clone repository
uses: appleboy/ssh-action@master
with:
host: ${{ env.REMOTE_HOST }}
username: ${{ env.REMOTE_USER }}
key: ${{ env.SSH_PRIVATE_KEY }}
script: |
cd /opt/auditoria
sudo git clone -b auditoria_qa_am https://github.com/alkemyTech/UMSA-DevOps-T1.git /opt/auditoria
# Install npm packages express pm2.
- name: Install npm packages
uses: appleboy/ssh-action@master
with:
host: ${{ env.REMOTE_HOST }}
username: ${{ env.REMOTE_USER }}
key: ${{ env.SSH_PRIVATE_KEY }}
script: |
cd /opt/auditoria
sudo npm install -g express pm2
# Start service
- name: Start Service
uses: appleboy/ssh-action@master
with:
host: ${{ env.REMOTE_HOST }}
username: ${{ env.REMOTE_USER }}
key: ${{ env.SSH_PRIVATE_KEY }}
script: |
cd /opt/auditoria
sudo pm2 delete app.js || true
sudo pm2 start app.js --name 'app.js'
# Check if app is running
- name: Check if app is running
uses: appleboy/ssh-action@master
with:
host: ${{ env.REMOTE_HOST }}
username: ${{ env.REMOTE_USER }}
key: ${{ env.SSH_PRIVATE_KEY }}
script: |
if sudo pm2 ls | grep -q 'app.js'; then
echo "El servicio app.js está en ejecución."
else
echo "El servicio app.js no está en ejecución."
exit 1
fi
- name: checkout
uses: actions/checkout@v4
- name: Generar Imagen Docker
uses: docker/[email protected]
with:
context: .
file: Dockerfile
push: false
tags: ${{ env.DOCKERHUB_USERNAME }}/auditoria_qa:latest
- name: Iniciar sesion en docker hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_PASSWORD }}
- name: Subir a DockerHub
uses: docker/[email protected]
with:
context: .
file: Dockerfile
push: true
tags: ${{ env.DOCKERHUB_USERNAME }}/auditoria_qa:latest
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_TOKEN }}
- name: Actualizar el sistema e instalar Docker
uses: appleboy/ssh-action@master
with:
host: ${{ env.REMOTE_HOST }}
username: ${{ env.REMOTE_USER }}
key: ${{ env.SSH_PRIVATE_KEY }}
script: |
sudo yum update -y
sudo yum install docker -y
sudo service docker start
sudo usermod -aG docker ec2-user
- name: Detener y eliminar aplicación existente
uses: appleboy/ssh-action@master
with:
host: ${{ env.REMOTE_HOST }}
username: ${{ env.REMOTE_USER }}
key: ${{ env.SSH_PRIVATE_KEY }}
script: |
sudo pm2 delete app.js || true
- name: Detener y eliminar contenedor existente
uses: appleboy/ssh-action@master
with:
host: ${{ env.REMOTE_HOST }}
username: ${{ env.REMOTE_USER }}
key: ${{ env.SSH_PRIVATE_KEY }}
script: |
sudo docker stop auditoria_qa || true
sudo docker rm auditoria_qa || true
- name: Ejecutar nuevo contenedor Docker
uses: appleboy/ssh-action@master
with:
host: ${{ env.REMOTE_HOST }}
username: ${{ env.REMOTE_USER }}
key: ${{ env.SSH_PRIVATE_KEY }}
script: |
sudo docker run -d -p 8080:8080 --name auditoria_qa ${{ env.DOCKERHUB_USERNAME }}/auditoria_qa:latest
- name: Mostrar información de la página
uses: appleboy/ssh-action@master
with:
host: ${{ env.REMOTE_HOST }}
username: ${{ env.REMOTE_USER }}
key: ${{ env.SSH_PRIVATE_KEY }}
script: |
sudo curl localhost:8080