prueba6 #7
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: App ventas ec2 | |
on: | |
push: | |
branches: | |
- ventas_qa_sc | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
env: | |
#Conexion ssh | |
SSH_PRIVATE_KEY: ${{ secrets.PEM_FILE_VENTAS_QA }} | |
REMOTE_USER: ec2-user | |
REMOTE_HOST: ${{ vars.IP_EC2_VENTAS_QA }} | |
#Conexion dockerhub | |
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME_SANTIAGO }} | |
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD_SANTIAGO }} | |
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN_SANTIAGO }} | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
- name: Generar Imagen Docker | |
uses: docker/[email protected] | |
with: | |
context: . | |
file: Dockerfile | |
push: false | |
tags: ${{ env.DOCKERHUB_USERNAME }}/ventas_qa:latest | |
- name: Iniciar sesion en docker hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ env.DOCKERHUB_USERNAME }} | |
password: ${{ env.DOCKERHUB_PASSWORD }} | |
- name: Subir a DockerHub | |
uses: docker/[email protected] | |
with: | |
context: . | |
file: Dockerfile | |
push: true | |
tags: ${{ env.DOCKERHUB_USERNAME }}/ventas_qa:latest | |
- name: Actualizar el sistema e instalar Docker | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ env.REMOTE_HOST }} | |
username: ${{ env.REMOTE_USER }} | |
key: ${{ env.SSH_PRIVATE_KEY }} | |
script: | | |
sudo yum update -y | |
sudo yum install docker -y | |
sudo service docker start | |
sudo usermod -aG docker ec2-user | |
- name: Eliminar contenedor | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ env.REMOTE_HOST }} | |
username: ${{ env.REMOTE_USER }} | |
key: ${{ env.SSH_PRIVATE_KEY }} | |
script: | | |
docker stop ventas_qa_sc || true | |
docker rm ventas_qa_sc || true | |
- name: Ejecutar contenedor en EC2 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ env.REMOTE_HOST }} | |
username: ${{ env.REMOTE_USER }} | |
key: ${{ env.SSH_PRIVATE_KEY }} | |
script: | | |
docker run -d -p 3000:3000 --name ventas_qa_sc ${{ env.DOCKERHUB_USERNAME }}/ventas_qa:latest | |
- name: Mostrar informacion de la pagina | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ env.REMOTE_HOST }} | |
username: ${{ env.REMOTE_USER }} | |
key: ${{ env.SSH_PRIVATE_KEY }} | |
script: | | |
sudo curl localhost:3000 |