Skip to content

CD-AUDITORIA-QA

CD-AUDITORIA-QA #9

Workflow file for this run

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