-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |