-
Notifications
You must be signed in to change notification settings - Fork 0
98 lines (86 loc) · 3.13 KB
/
auditoria-qa.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
name: AUDITORIA-QA
on:
workflow_dispatch:
inputs:
app_container_name:
description: 'Nombre del contenedor'
required: true
default: 'auditoria-app-qa'
env:
SSH_PRIVATE_KEY: ${{ secrets.PEM_AUDITORIA_QA }}
REMOTE_USER: ec2-user
REMOTE_HOST: ${{ secrets.IP_AUDITORIA_QA }}
APP_NAME: ${{ github.event.inputs.app_container_name }}
DOCKERHUB_TOKEN: ${{ secrets.DH_TOKEN_CLIENTES }}
DOCKERHUB_USERNAME: romicalani
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Iniciar sesion en Docker Hub
uses: docker/[email protected]
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_TOKEN }}
- name: Generar imagen Docker
run: |
docker build . -t ${{env.DOCKERHUB_USERNAME }}/${{env.APP_NAME}}:latest
- name: Subir imagen Docker
run: |
docker push ${{env.DOCKERHUB_USERNAME }}/${{env.APP_NAME}}:latest
- name: Instalar docker
uses: appleboy/ssh-action@master
with:
host: ${{ env.REMOTE_HOST }}
username: ${{ env.REMOTE_USER }}
key: ${{ env.SSH_PRIVATE_KEY }}
script: |
if ! command -v docker > /dev/null; then
sudo yum install docker -y
else
echo "docker is installed."
fi
if systemctl is-active --quiet docker; then
echo "Docker service is already running."
else
sudo systemctl start docker
fi
sudo usermod -aG docker ${{ env.REMOTE_USER }}
- name: Detener y eliminar si esta en ejecucion
uses: appleboy/ssh-action@master
with:
host: ${{ env.REMOTE_HOST }}
username: ${{ env.REMOTE_USER }}
key: ${{ env.SSH_PRIVATE_KEY }}
script: |
if sudo docker ps -a --format '{{.Names}}' | grep -q ${{env.APP_NAME}}; then
echo "Eliminando contenedor con nombre: ${{env.APP_NAME}}"
sudo docker stop $(sudo docker ps -q) || true
sudo docker rm -f ${{env.APP_NAME}} || true
echo "Contenedor eliminado exitosamente."
fi
- name: Descargar imagen docker
uses: appleboy/ssh-action@master
with:
host: ${{ env.REMOTE_HOST }}
username: ${{ env.REMOTE_USER }}
key: ${{ env.SSH_PRIVATE_KEY }}
script: |
if ! sudo docker image ${{ env.DOCKERHUB_USERNAME }}/${{env.APP_NAME}}:latest &> /dev/null; then
sudo docker pull ${{ env.DOCKERHUB_USERNAME }}/${{env.APP_NAME}}:latest
fi
sudo docker run -dp 3000:3000 --name ${{env.APP_NAME}} ${{ env.DOCKERHUB_USERNAME }}/${{env.APP_NAME}}:latest
- name: Verificar servicio en ejecucion
uses: appleboy/ssh-action@master
with:
host: ${{ env.REMOTE_HOST }}
username: ${{ env.REMOTE_USER }}
key: ${{ env.SSH_PRIVATE_KEY }}
script: |
if netstat -an | grep :3000; then
echo "${{env.APP_NAME}} is running"
else
echo "${{env.APP_NAME}} is not running"
fi