Skip to content

Commit

Permalink
ci cobranzas-qa.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Nhay2008 authored Apr 16, 2024
1 parent 22a77ef commit 37d58e7
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions .github/workflows/cobranzas-qa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Cd-cobranzas-qa

on:
workflow_dispatch:
inputs:
app_container_name:
description: 'Nombre del contenedor'
required: true
default: 'maicol-cobranzas-qa'

env:
SSH_PRIVATE_KEY: ${{ secrets.PEM_MICROSERVICIOS }}
REMOTE_USER: ${{ secrets.USERS_COBRANZAS }}
REMOTE_HOST: ${{ secrets.IP_COBRANZAS_QA }}
APP_NAME: ${{ github.event.inputs.app_container_name }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKER }}
DOCKERHUB_USERNAME: ${{ secrets.USERS_DOCKER }}

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

0 comments on commit 37d58e7

Please sign in to comment.