Merge pull request #88 from Trycatch-tv/dev #4
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 # Cambia esto a la rama que desees | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Build Docker image | |
run: docker build -t my-app:latest . | |
- name: Save Docker image to file | |
run: docker save -o my-app.tar my-app:latest | |
- name: Upload Docker image as artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: docker-image | |
path: my-app.tar | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v2 | |
with: | |
name: docker-image | |
path: . | |
- name: SSH and deploy | |
uses: appleboy/ssh-action@v0.1.6 | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USER }} | |
key: ${{ secrets.EC2_KEY }} | |
script: | | |
docker load -i my-app.tar | |
docker stop my-app || true | |
docker rm my-app || true | |
docker run -d --name my-app -p 80:3000 my-app:latest |