Merge pull request #118 from Trycatch-tv/dev #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: 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 | |
# Crear un archivo .env con las variables de entorno necesarias | |
echo "DATABASE_HOST=${{secrets.DATABASE_NAME}}" > .env | |
echo "DATABASE_PORT=${{secrets.DATABASE_PORT}}" >> .env | |
echo "DATABASE_USER=${{secrets.DATABASE_USER}}" >> .env | |
echo "DATABASE_PASSWORD=${{secrets.DATABASE_PASSWORD}}" >> .env | |
echo "DATABASE_NAME=${{secrets.DATABASE_NAME}}" >> .env | |
echo "FILE_SERVICE_URL=${{secrets.FILE_SERVICE_URL}}" >> .env | |
echo "REVIEW_SERVICE_URL=${{secrets.REVIEW_SERVICE_URL}}" >> .env | |
echo "NODE_ENV=${{secrets.NODE_ENV}}" >> .env | |
echo "POSTGRES_USER=${{secrets.POSTGRES_USER}}" >> .env | |
echo "POSTGRES_PASSWORD=${{secrets.POSTGRES_PASSWORD}}" >> .env | |
echo "POSTGRES_DB=${{secrets.POSTGRES_DB}}" >> .env | |
# Actualizar la imagen del servicio backend y reiniciarlo sin afectar db | |
docker-compose down | |
docker-compose up -d --no-deps --build | |
echo "Finalizado!" | |
EOF |