feat: Update Docker configuration and README.md #3
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-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build Docker image | |
run: docker build -t gatos-sin-hogar-backend . | |
- name: Save Docker image to a tar file | |
run: docker save gatos-sin-hogar-backend > gatos-sin-hogar-backend.tar | |
- name: Copy Docker image to EC2 | |
uses: appleboy/scp-action@v0.1.7 | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USER }} | |
key: ${{ secrets.EC2_KEY }} | |
source: 'gatos-sin-hogar-backend.tar' | |
target: '~/gatos-sin-hogar-backend.tar' | |
- name: SSH into EC2 and load the Docker image | |
uses: appleboy/ssh-action@v0.1.7 | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USER }} | |
key: ${{ secrets.EC2_KEY }} | |
script: | | |
docker load < ~/gatos-sin-hogar-backend.tar | |
docker stop gatos-sin-hogar-backend || true | |
docker rm gatos-sin-hogar-backend || true | |
docker run -d --name gatos-sin-hogar-backend -p 80:7000 gatos-sin-hogar-backend |