Merge pull request #117 from Trycatch-tv/dev #46
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: Deploy to EC2 | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx (optional for caching) | |
uses: docker/setup-buildx-action@v1 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build-and-push | |
steps: | |
- name: Install SSH client | |
run: sudo apt-get install -y sshpass | |
- name: SSH and deploy | |
env: | |
SSHPASS: ${{ secrets.EC2_KEY }} | |
run: | | |
sshpass -e ssh -o StrictHostKeyChecking=no ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF' | |
# Clonar el repositorio en una ruta específica | |
git clone https://github.com/Trycatch-tv/ValidadorBootcamp-backend /home/${{ secrets.EC2_USER }}/app | |
cd /home/${{ secrets.EC2_USER }}/app | |
# Actualizar la imagen del servicio backend y reiniciarlo sin afectar db | |
docker-compose down | |
docker-compose up -d --no-deps --build | |
echo "Finalizado!" | |
EOF |