Create manual-workflow.yml #47
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
name: CIPagosqa | |
env: | |
SSH_PRIVATE_KEY: ${{ secrets.PEM_ORG_PAGOS_DEV }} | |
REMOTE_USER: ec2-user | |
REMOTE_HOST: ${{ secrets.IP_PAGOS_QA }} | |
APP_NAME: app.js | |
on: | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: 'Seleccione el entorno de destino' | |
required: true | |
default: 'QA' | |
options: | |
- 'QA: Entorno de Pruebas (QA)' | |
- 'PROD: Entorno de Producción (PROD)' | |
push: | |
branches: | |
- franco-pagos-qa | |
jobs: | |
ci-pagos-qa: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Crear directorio de trabajo en la máquina EC2 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ env.REMOTE_HOST }} | |
username: ${{ env.REMOTE_USER }} | |
key: ${{ env.SSH_PRIVATE_KEY }} | |
script: | | |
sudo rm -rf /opt/ms-pagos-qa-app || true | |
sudo mkdir -p /opt/ms-pagos-qa-app | |
sudo usermod -aG docker $USER | |
- name: Clonar repositorio de GitHub | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ env.REMOTE_HOST }} | |
username: ${{ env.REMOTE_USER }} | |
key: ${{ env.SSH_PRIVATE_KEY }} | |
script: | | |
cd /opt/ms-pagos-qa-app | |
sudo git clone -b franco-pagos-qa https://${{ secrets.TOKEN_PAGOS }}@github.com/alkemyTech/UMSA-DevOps-T3 . | |
# Instalar Docker | |
- name: Install 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 | |
echo "Docker is not installed. Installing Docker..." | |
sudo yum update -y | |
sudo yum install -y docker | |
else | |
echo "Docker is already installed." | |
fi | |
if ! systemctl is-active --quiet docker | |
then | |
echo "Docker is not running. Starting Docker..." | |
sudo systemctl start docker | |
else | |
echo "Docker is already running." | |
fi | |
# Construir la imagen Docker | |
- name: Build Docker image | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ env.REMOTE_HOST }} | |
username: ${{ env.REMOTE_USER }} | |
key: ${{ env.SSH_PRIVATE_KEY }} | |
script: | | |
cd /opt/ms-pagos-qa-app | |
docker rmi pagosimagen || true | |
docker build -t pagosimagen . | |
# Autenticación en DockerHub | |
- name: Login to DockerHub | |
run: echo "${{ secrets.DOCKERPAGO_TOKEN }}" | docker login -u "${{ secrets.dockerUserpago }}" --password-stdin | |
# Subir imagen a DockerHub | |
#- name: Push image to DockerHub | |
# run: docker push "${{secrets.dockerUserpago}}"/pagosimagen:latest | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: ${{ secrets.dockerUserpago }}/pagosimagen:latest | |
username: ${{ secrets.dockerUserpago }} | |
password: ${{ secrets.DOCKERPAGO_TOKEN }} | |
# Despliegue al entorno de QA (manual) | |
- name: Desplegar al entorno de QA | |
run: echo "Presiona un botón para desplegar en QA" |